[PATCH 1/5] cleanup adding/removing files in commit and import

Chris Mason mason at suse.com
Wed Jun 15 16:52:52 UTC 2005


Change hg addremove so that it can take a list of files to process instead
of searching the entire tree for candidates.  

Add hg commit -A that calls hg addremove before trying to run the commit

Change hg import to call hg addremove with the file list to make sure files
added/deleted by the patch are properly accounted for.  Instead of using
lsdiff, the output of patch is parsed directly to find the file list.

Index: mercurial-snapshot/mercurial/commands.py
===================================================================
--- mercurial-snapshot.orig/mercurial/commands.py	2005-06-15 12:33:12.000000000 -0400
+++ mercurial-snapshot/mercurial/commands.py	2005-06-15 12:33:54.000000000 -0400
@@ -171,9 +171,22 @@ def add(ui, repo, file, *files):
     '''add the specified files on the next commit'''
     repo.add(relpath(repo, (file,) + files))
 
-def addremove(ui, repo):
+def addremove(ui, repo, *files):
     """add all new files, delete all missing files"""
-    (c, a, d, u) = repo.diffdir(repo.root)
+    if files:
+        files = relpath(repo, files)
+        d = []
+        u = []
+        for f in files:
+            p = repo.wjoin(f)
+            s = repo.dirstate.state(f)
+            isfile = os.path.isfile(p)
+            if s != 'r' and not isfile:
+                d.append(f)
+            elif s not in 'nmai' and isfile:
+                u.append(f)
+    else:
+        (c, a, d, u) = repo.diffdir(repo.root)
     repo.add(u)
     repo.remove(d)
 
@@ -233,6 +246,8 @@ def commit(ui, repo, *files, **opts):
         try: text = open(opts['logfile']).read()
         except IOError: pass
 
+    if opts['addremove']:
+        addremove(ui, repo, *files)
     repo.commit(relpath(repo, files), text, opts['user'], opts['date'])
 
 def debugaddchangegroup(ui, repo):
@@ -425,13 +440,18 @@ def patch(ui, repo, patch1, *patches, **
         # make sure text isn't empty
         if not text: text = "imported patch %s\n" % patch
 
-        f = os.popen("lsdiff --strip %d %s" % (strip, pf))
-        files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines()))
+        f = os.popen("patch -p%d < %s" % (strip, pf))
+        files = []
+        for l in f.read().splitlines():
+            l.rstrip('\r\n');
+            if not quiet:
+                print l
+            if l[:14] == 'patching file ':
+                files.append(l[14:])
         f.close()
 
-        if files:
-            if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
-                raise "patch failed!"
+        if len(files) > 0:
+            addremove(ui, repo, *files)
         repo.commit(files, text)
 
 def pull(ui, repo, source="default"):
@@ -573,7 +593,7 @@ def verify(ui, repo):
 
 table = {
     "add": (add, [], "hg add [files]"),
-    "addremove": (addremove, [], "hg addremove"),
+    "addremove": (addremove, [], "hg addremove [files]"),
     "ann|annotate": (annotate,
                      [('r', 'revision', '', 'revision'),
                       ('u', 'user', None, 'show user'),
@@ -583,6 +603,7 @@ table = {
     "cat|dump": (cat, [], 'hg cat <file> [rev]'),
     "commit|ci": (commit,
                   [('t', 'text', "", 'commit text'),
+                   ('A', 'addremove', None, 'run add/remove during commit'),
                    ('l', 'logfile', "", 'commit text file'),
                    ('d', 'date', "", 'data'),
                    ('u', 'user', "", 'user')],



More information about the Mercurial mailing list