[PATCH 1 of 5] import: simplify status reporting logic (and make it more I18N-friendly)

Greg Ward greg-hg at gerg.ca
Sun Oct 2 13:37:30 CDT 2011


# HG changeset patch
# User Greg Ward <greg at gerg.ca>
# Date 1317519049 14400
# Node ID df74de0bb682c020b7dd42ee54ceb6fc978e58bb
# Parent  6dc67dced8c122f6139ae20ccdc03a6b11e8b765
import: simplify status reporting logic (and make it more I18N-friendly)

The old code printed (with ui.status()) the changeset ID created by
patch N after committing patch N+1, e.g.

  applying patch1
  applying patch2
  applied 1d4bd90af0e4

where 1d4bd90af0e4 is the changeset ID resulting from patch1. That's
just weird. It's also inconsistent: we only reported the changeset ID
when applying >1 patches. And it's inconsistent with 'commit', which
only tells you the new changeset ID in verbose mode. Finally, the
existing code was I18N-hostile, since it concatenated translated
strings.

The new way is to print the just-created changeset ID with ui.note()
immediately after committing it. It also clarifies what the user
message is for easier I18N.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3275,8 +3275,8 @@
             patch.extract(ui, hunk)
 
         if not tmpname:
-            return None
-        commitid = _('to working directory')
+            return (None, None)
+        msg = _('applied to working directory')
 
         try:
             cmdline_message = cmdutil.logmessage(ui, opts)
@@ -3361,8 +3361,8 @@
                 finally:
                     store.close()
             if n:
-                commitid = short(n)
-            return commitid
+                msg = _('created %s') % short(n)
+            return (msg, n)
         finally:
             os.unlink(tmpname)
 
@@ -3370,7 +3370,6 @@
         wlock = repo.wlock()
         lock = repo.lock()
         parents = repo.parents()
-        lastcommit = None
         for p in patches:
             pf = os.path.join(d, p)
 
@@ -3383,16 +3382,14 @@
 
             haspatch = False
             for hunk in patch.split(pf):
-                commitid = tryone(ui, hunk, parents)
-                if commitid:
+                (msg, node) = tryone(ui, hunk, parents)
+                if msg:
                     haspatch = True
-                    if lastcommit:
-                        ui.status(_('applied %s\n') % lastcommit)
-                    lastcommit = commitid
+                    ui.note(msg + '\n')
                 if update or opts.get('exact'):
                     parents = repo.parents()
                 else:
-                    parents = [repo[commitid]]
+                    parents = [repo[node]]
 
             if not haspatch:
                 raise util.Abort(_('no diffs found'))
diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
--- a/tests/test-import-bypass.t
+++ b/tests/test-import-bypass.t
@@ -171,7 +171,6 @@
   $ hg import --bypass ../patch1.diff ../patch2.diff
   applying ../patch1.diff
   applying ../patch2.diff
-  applied 16581080145e
   $ shortlog
   o  3:bc8ca3f8a7c4 test 0 0 - default - addf
   |
@@ -196,7 +195,6 @@
   $ hg import --bypass --exact ../patch1.diff ../patch2.diff
   applying ../patch1.diff
   applying ../patch2.diff
-  applied 16581080145e
   $ shortlog
   o  3:d60cb8989666 test 0 0 - foo - addf
   |
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -199,7 +199,6 @@
   $ hg init b
   $ hg --cwd a export 0:tip | hg --cwd b import -
   applying patch from stdin
-  applied 80971e65b431
   $ hg --cwd a id
   1d4bd90af0e4 tip
   $ hg --cwd b id
@@ -356,10 +355,15 @@
   $ hg clone -qr0 a b
   $ hg --cwd b parents --template 'parent: {rev}\n'
   parent: 0
-  $ hg --cwd b import ../patch1 ../patch2
+  $ hg --cwd b import -v ../patch1 ../patch2
   applying ../patch1
+  patching file a
+  a
+  created 1d4bd90af0e4
   applying ../patch2
-  applied 1d4bd90af0e4
+  patching file a
+  a
+  created 6d019af21222
   $ hg --cwd b rollback
   repository tip rolled back to revision 1 (undo commit)
   working directory now based on revision 1
@@ -433,6 +437,7 @@
   applying fuzzy-tip.patch
   patching file a
   Hunk #1 succeeded at 1 with fuzz 2 (offset -2 lines).
+  applied to working directory
   $ hg revert -a
   reverting a
 
@@ -449,6 +454,7 @@
   applying fuzzy-tip.patch
   patching file a
   Hunk #1 succeeded at 1 with fuzz 2 (offset -2 lines).
+  applied to working directory
   $ cd ..
 
 
@@ -651,6 +657,7 @@
   removing a
   adding b
   recording removal of a as rename to b (88% similar)
+  applied to working directory
   $ hg st -C
   A b
     a
@@ -665,6 +672,7 @@
   patching file b
   removing a
   adding b
+  applied to working directory
   $ hg st -C
   A b
   R a
diff --git a/tests/test-patch-offset.t b/tests/test-patch-offset.t
--- a/tests/test-patch-offset.t
+++ b/tests/test-patch-offset.t
@@ -69,6 +69,7 @@
   Hunk #2 succeeded at 87 (offset 34 lines).
   Hunk #3 succeeded at 109 (offset 34 lines).
   a
+  created 189885cecb41
 
 compare imported changes against reference file
 
diff --git a/tests/test-patch.t b/tests/test-patch.t
--- a/tests/test-patch.t
+++ b/tests/test-patch.t
@@ -37,7 +37,7 @@
   $ hg --cwd b import -v ../a.diff
   applying ../a.diff
   Using custom patch
-
+  applied to working directory
 
 Issue2417: hg import with # comments in description
 


More information about the Mercurial-devel mailing list