merge: add -S/--show option to review revisions without merging
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Thu, 14 May 2009 16:03:17 +0200
changeset 8387 50b6af595e0c
parent 8386 4aad982111b6
child 8388 dbc28d362e79
merge: add -S/--show option to review revisions without merging
mercurial/commands.py
tests/test-double-merge
tests/test-double-merge.out
tests/test-merge-default
tests/test-merge-default.out
tests/test-merge1
tests/test-merge1.out
--- a/mercurial/commands.py	Thu May 14 15:48:47 2009 +0200
+++ b/mercurial/commands.py	Thu May 14 16:03:17 2009 +0200
@@ -2025,7 +2025,7 @@
             ui.write(decor[ctx.flags(f)])
         ui.write("%s\n" % f)
 
-def merge(ui, repo, node=None, force=None, rev=None):
+def merge(ui, repo, node=None, **opts):
     """merge working directory with another revision
 
     The contents of the current working directory is updated with all
@@ -2042,10 +2042,10 @@
     explicit revision to merge with must be provided.
     """
 
-    if rev and node:
+    if opts.get('rev') and node:
         raise util.Abort(_("please specify just one revision"))
     if not node:
-        node = rev
+        node = opts.get('rev')
 
     if not node:
         branch = repo.changectx(None).branch()
@@ -2070,7 +2070,18 @@
             raise util.Abort(_('working dir not at a head rev - '
                                'use "hg update" or merge with an explicit rev'))
         node = parent == bheads[0] and bheads[-1] or bheads[0]
-    return hg.merge(repo, node, force=force)
+
+    if opts.get('show'):
+        p1 = repo['.']
+        p2 = repo[node]
+        common = p1.ancestor(p2)
+        roots, heads = [common.node()], [p2.node()]
+        displayer = cmdutil.show_changeset(ui, repo, opts)
+        for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]:
+        	displayer.show(repo[node])
+        return 0
+
+    return hg.merge(repo, node, force=opts.get('force'))
 
 def outgoing(ui, repo, dest=None, **opts):
     """show changesets not found in destination
@@ -3324,7 +3335,8 @@
         (merge,
          [('f', 'force', None, _('force a merge with outstanding changes')),
           ('r', 'rev', '', _('revision to merge')),
-             ],
+          ('S', 'show', None,
+           _('review revisions to merge (no merge is performed)'))],
          _('[-f] [[-r] REV]')),
     "outgoing|out":
         (outgoing,
--- a/tests/test-double-merge	Thu May 14 15:48:47 2009 +0200
+++ b/tests/test-double-merge	Thu May 14 16:03:17 2009 +0200
@@ -20,6 +20,7 @@
 hg ci -m 'change foo' -d "1000000 0"
 
 # we get conflicts that shouldn't be there
+hg merge -S
 hg merge --debug
 
 echo "-- foo --"
--- a/tests/test-double-merge.out	Thu May 14 15:48:47 2009 +0200
+++ b/tests/test-double-merge.out	Thu May 14 16:03:17 2009 +0200
@@ -1,4 +1,14 @@
 created new head
+changeset:   0:310fd17130da
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     add foo
+
+changeset:   1:7731dad1c2b9
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     cp foo bar; change both
+
 resolving manifests
  overwrite None partial False
  ancestor 310fd17130da local 2092631ce82b+ remote 7731dad1c2b9
--- a/tests/test-merge-default	Thu May 14 15:48:47 2009 +0200
+++ b/tests/test-merge-default	Thu May 14 16:03:17 2009 +0200
@@ -31,6 +31,7 @@
 hg commit -mm1
 
 echo % should succeed - 2 heads
+hg merge -S
 hg merge
 hg commit -mm2
 
--- a/tests/test-merge-default.out	Thu May 14 15:48:47 2009 +0200
+++ b/tests/test-merge-default.out	Thu May 14 16:03:17 2009 +0200
@@ -13,6 +13,17 @@
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
 % should succeed - 2 heads
+changeset:   1:ba677d0156c1
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+changeset:   3:903c264cdf57
+parent:      1:ba677d0156c1
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     d
+
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
 % should fail because at tip
--- a/tests/test-merge1	Thu May 14 15:48:47 2009 +0200
+++ b/tests/test-merge1	Thu May 14 16:03:17 2009 +0200
@@ -30,6 +30,7 @@
 hg commit -m "commit #2" -d "1000000 0"
 echo This is file b1 > b
 echo %% no merges expected
+hg merge -S 1
 hg merge 1
 hg diff --nodates
 hg status
--- a/tests/test-merge1.out	Thu May 14 15:48:47 2009 +0200
+++ b/tests/test-merge1.out	Thu May 14 16:03:17 2009 +0200
@@ -1,6 +1,16 @@
 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
 created new head
 %% no merges expected
+changeset:   0:98e00378acd0
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     commit #0
+
+changeset:   1:4ee19afe4659
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     commit #1
+
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
 diff -r d9e5953b9dec b