Patchwork [1,of,3] localrepo: refactor commit argument check as checkcommitpatterns

login
register
mail settings
Submitter timeless@mozdev.org
Date April 6, 2016, 6:24 p.m.
Message ID <f51bc5f09b2b5aae476e.1459967071@waste.org>
Download mbox | patch
Permalink /patch/14395/
State Accepted
Headers show

Comments

timeless@mozdev.org - April 6, 2016, 6:24 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1459965137 0
#      Wed Apr 06 17:52:17 2016 +0000
# Node ID f51bc5f09b2b5aae476e31f44755229a591afa80
# Parent  ea86cdcd9b50bf38c6b9dd7bbaa04b9c8cc0aefb
localrepo: refactor commit argument check as checkcommitpatterns

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1477,6 +1477,28 @@ 
 
         return fparent1
 
+    def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
+        """check for commit arguments that aren't commitable"""
+        force = False
+        if not force and (match.isexact() or match.prefix()):
+            matched = set(status.modified + status.added + status.removed)
+
+            for f in match.files():
+                f = self.dirstate.normalize(f)
+                if f == '.' or f in matched or f in wctx.substate:
+                    continue
+                if f in status.deleted:
+                    fail(f, _('file not found!'))
+                if f in vdirs: # visited directory
+                    d = f + '/'
+                    for mf in matched:
+                        if mf.startswith(d):
+                            break
+                    else:
+                        fail(f, _("no match under directory!"))
+                elif f not in self.dirstate:
+                    fail(f, _("file not tracked!"))
+
     @unfilteredmethod
     def commit(self, text="", user=None, date=None, match=None, force=False,
                editor=False, extra=None):
@@ -1571,24 +1593,8 @@ 
                     status.removed.insert(0, '.hgsubstate')
 
             # make sure all explicit patterns are matched
-            if not force and (match.isexact() or match.prefix()):
-                matched = set(status.modified + status.added + status.removed)
-
-                for f in match.files():
-                    f = self.dirstate.normalize(f)
-                    if f == '.' or f in matched or f in wctx.substate:
-                        continue
-                    if f in status.deleted:
-                        fail(f, _('file not found!'))
-                    if f in vdirs: # visited directory
-                        d = f + '/'
-                        for mf in matched:
-                            if mf.startswith(d):
-                                break
-                        else:
-                            fail(f, _("no match under directory!"))
-                    elif f not in self.dirstate:
-                        fail(f, _("file not tracked!"))
+            if not force:
+                self.checkcommitpatterns(wctx, vdirs, match, status, fail)
 
             cctx = context.workingcommitctx(self, status,
                                             text, user, date, extra)