add merge command. means same thing as "update -m".
authorVadim Gelfer <vadim.gelfer@gmail.com>
Wed, 29 Mar 2006 10:27:16 -0800
changeset 2019 ced2d3620f95
parent 2015 1a09814a5b1f
child 2020 00925397236c
add merge command. means same thing as "update -m". repo.addchangegroup method now returns number of heads modified and added, so command line can tell whether update or merge needed. this makes tiny change to ssh wire protocol, but change is backwards compatible. pull command now returns 0 if no changes to pull.
mercurial/commands.py
mercurial/localrepo.py
mercurial/sshrepo.py
tests/test-clone-r.out
tests/test-filebranch.out
tests/test-flags.out
tests/test-help.out
tests/test-merge5.out
tests/test-merge6.out
tests/test-merge7.out
tests/test-pull-pull-corruption.out
tests/test-push-r.out
tests/test-push-warn.out
tests/test-unrelated-pull.out
tests/test-up-local-change.out
--- a/mercurial/commands.py	Wed Mar 29 12:45:33 2006 +0200
+++ b/mercurial/commands.py	Wed Mar 29 10:27:16 2006 -0800
@@ -1998,6 +1998,16 @@
     for f in files:
         ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f))
 
+def merge(ui, repo, node=None, **opts):
+    """Merge working directory with another revision
+
+    Merge the contents of the current working directory and the
+    requested revision. Files that changed between either parent are
+    marked as changed for the next commit and a commit must be
+    performed before any further updates are allowed.
+    """
+    return update(ui, repo, node=node, merge=True, **opts)
+    
 def outgoing(ui, repo, dest="default-push", **opts):
     """show changesets not found in destination
 
@@ -2070,6 +2080,19 @@
         for name, path in ui.configitems("paths"):
             ui.write("%s = %s\n" % (name, path))
 
+def postincoming(ui, repo, modheads, optupdate):
+    if modheads == 0:
+        return
+    if optupdate:
+        if modheads == 1:
+            return update(ui, repo)
+        else:
+            ui.status(_("not updating, since new heads added\n"))
+    if modheads > 1:
+        ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
+    else:
+        ui.status(_("(run 'hg update' to get a working copy)\n"))
+    
 def pull(ui, repo, source="default", **opts):
     """pull changes from the specified source
 
@@ -2114,14 +2137,8 @@
         raise util.Abort(_("pull -r doesn't work for remote repositories yet"))
     elif opts['rev']:
         revs = [other.lookup(rev) for rev in opts['rev']]
-    r = repo.pull(other, heads=revs, force=opts['force'])
-    if not r:
-        if opts['update']:
-            return update(ui, repo)
-        else:
-            ui.status(_("(run 'hg update' to get a working copy)\n"))
-
-    return r
+    modheads = repo.pull(other, heads=revs, force=opts['force'])
+    return postincoming(ui, repo, modheads, opts['update'])
 
 def push(ui, repo, dest="default-push", **opts):
     """push changes to the specified destination
@@ -2158,7 +2175,7 @@
     if opts['rev']:
         revs = [repo.lookup(rev) for rev in opts['rev']]
     r = repo.push(other, opts['force'], revs=revs)
-    return r
+    return r == 0
 
 def rawcommit(ui, repo, *flist, **rc):
     """raw commit interface (DEPRECATED)
@@ -2387,7 +2404,7 @@
                 respond("")
 
                 r = repo.addchangegroup(fin)
-                respond("")
+                respond(str(r))
 
     optlist = "name templates style address port ipv6 accesslog errorlog"
     for o in optlist.split():
@@ -2599,13 +2616,8 @@
         raise util.Abort(_("%s: unknown bundle compression type")
                          % fname)
     gen = generator(util.filechunkiter(f, 4096))
-    if repo.addchangegroup(util.chunkbuffer(gen)):
-        return 1
-
-    if opts['update']:
-        return update(ui, repo)
-    else:
-        ui.status(_("(run 'hg update' to get a working copy)\n"))
+    modheads = repo.addchangegroup(util.chunkbuffer(gen))
+    return postincoming(ui, repo, modheads, opts['update'])
 
 def undo(ui, repo):
     """undo the last commit or pull
@@ -2849,6 +2861,13 @@
           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
          _('hg log [OPTION]... [FILE]')),
     "manifest": (manifest, [], _('hg manifest [REV]')),
+    "merge":
+    (merge,
+     [('b', 'branch', '', _('merge with head of a specific branch')),
+      ('', 'style', '', _('display using template map file')),
+      ('f', 'force', None, _('force a merge with outstanding changes')),
+      ('', 'template', '', _('display with template'))],
+     _('hg merge [-b TAG] [-f] [REV]')),
     "outgoing|out": (outgoing,
          [('M', 'no-merges', None, _('do not show merges')),
           ('f', 'force', None,
--- a/mercurial/localrepo.py	Wed Mar 29 12:45:33 2006 +0200
+++ b/mercurial/localrepo.py	Wed Mar 29 10:27:16 2006 -0800
@@ -964,7 +964,7 @@
 
         if not fetch:
             self.ui.status(_("no changes found\n"))
-            return 1
+            return 0
 
         if heads is None:
             cg = remote.changegroup(fetch, 'pull')
@@ -1340,6 +1340,8 @@
         return util.chunkbuffer(gengroup())
 
     def addchangegroup(self, source):
+        """add changegroup to repo.
+        returns number of heads modified or added + 1."""
 
         def csmap(x):
             self.ui.debug(_("add changeset %s\n") % short(x))
@@ -1349,7 +1351,7 @@
             return cl.rev(x)
 
         if not source:
-            return
+            return 0
 
         self.hook('prechangegroup', throw=True)
 
@@ -1424,6 +1426,8 @@
             for i in range(cor + 1, cnr + 1):
                 self.hook("incoming", node=hex(self.changelog.node(i)))
 
+        return newheads - oldheads + 1
+
     def update(self, node, allow=False, force=False, choose=None,
                moddirstate=True, forcemerge=False, wlock=None):
         pl = self.dirstate.parents()
@@ -1624,8 +1628,8 @@
                         cf = _(" (resolve)")
                     self.ui.status(" %s%s\n" % (f, cf))
                 self.ui.warn(_("aborting update spanning branches!\n"))
-                self.ui.status(_("(use update -m to merge across branches"
-                                 " or -C to lose changes)\n"))
+                self.ui.status(_("(use 'hg merge' to merge across branches"
+                                 " or '-C' to lose changes)\n"))
                 return 1
             branch_merge = True
 
--- a/mercurial/sshrepo.py	Wed Mar 29 12:45:33 2006 +0200
+++ b/mercurial/sshrepo.py	Wed Mar 29 10:27:16 2006 -0800
@@ -130,4 +130,7 @@
 
         self.readerr()
         l = int(self.pipei.readline())
-        return self.pipei.read(l) != ""
+        r = self.pipei.read(l)
+        if not r:
+            return 1
+        return int(r)
--- a/tests/test-clone-r.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-clone-r.out	Wed Mar 29 10:27:16 2006 -0800
@@ -118,7 +118,7 @@
 adding manifests
 adding file changes
 added 4 changesets with 2 changes to 3 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 checking changesets
 checking manifests
 crosschecking files in changesets and manifests
--- a/tests/test-filebranch.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-filebranch.out	Wed Mar 29 10:27:16 2006 -0800
@@ -13,7 +13,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 2 changes to 2 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 merging for foo
 resolving manifests
 getting bar
--- a/tests/test-flags.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-flags.out	Wed Mar 29 10:27:16 2006 -0800
@@ -11,7 +11,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 changeset:   2:b833d578451e
 tag:         tip
 parent:      0:4536b1c2ca69
--- a/tests/test-help.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-help.out	Wed Mar 29 10:27:16 2006 -0800
@@ -59,6 +59,7 @@
  locate      locate files matching specific patterns
  log         show revision history of entire repository or files
  manifest    output the latest or given revision of the project manifest
+ merge       Merge working directory with another revision
  outgoing    show changesets not found in destination
  parents     show the parents of the working dir or revision
  paths       show definition of symbolic path names
@@ -100,6 +101,7 @@
  locate      locate files matching specific patterns
  log         show revision history of entire repository or files
  manifest    output the latest or given revision of the project manifest
+ merge       Merge working directory with another revision
  outgoing    show changesets not found in destination
  parents     show the parents of the working dir or revision
  paths       show definition of symbolic path names
--- a/tests/test-merge5.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-merge5.out	Wed Mar 29 10:27:16 2006 -0800
@@ -2,4 +2,4 @@
 this update spans a branch affecting the following files:
  b
 aborting update spanning branches!
-(use update -m to merge across branches or -C to lose changes)
+(use 'hg merge' to merge across branches or '-C' to lose changes)
--- a/tests/test-merge6.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-merge6.out	Wed Mar 29 10:27:16 2006 -0800
@@ -4,7 +4,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 bar should remain deleted.
 f9b0e817f6a48de3564c6b2957687c5e7297c5a0 644 foo
 pulling from ../A2
@@ -13,6 +13,6 @@
 adding manifests
 adding file changes
 added 1 changesets with 0 changes to 0 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 bar should remain deleted.
 f9b0e817f6a48de3564c6b2957687c5e7297c5a0 644 foo
--- a/tests/test-merge7.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-merge7.out	Wed Mar 29 10:27:16 2006 -0800
@@ -4,7 +4,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 merge: warning: conflicts during merge
 merging test.txt
 merging test.txt failed!
@@ -14,7 +14,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 merge: warning: conflicts during merge
 resolving manifests
  force None allow 1 moddirstate True linear False
--- a/tests/test-pull-pull-corruption.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-pull-pull-corruption.out	Wed Mar 29 10:27:16 2006 -0800
@@ -16,7 +16,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 checking changesets
 checking manifests
 crosschecking files in changesets and manifests
--- a/tests/test-push-r.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-push-r.out	Wed Mar 29 10:27:16 2006 -0800
@@ -127,7 +127,7 @@
 adding manifests
 adding file changes
 added 4 changesets with 2 changes to 3 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 checking changesets
 checking manifests
 crosschecking files in changesets and manifests
--- a/tests/test-push-warn.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-push-warn.out	Wed Mar 29 10:27:16 2006 -0800
@@ -8,7 +8,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 pushing to ../a
 searching for changes
 abort: push creates new remote branches!
--- a/tests/test-unrelated-pull.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-unrelated-pull.out	Wed Mar 29 10:27:16 2006 -0800
@@ -8,7 +8,7 @@
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files (+1 heads)
-(run 'hg update' to get a working copy)
+(run 'hg heads' to see heads, 'hg merge' to merge)
 changeset:   1:bdcee5d51fa6
 tag:         tip
 user:        a
--- a/tests/test-up-local-change.out	Wed Mar 29 12:45:33 2006 +0200
+++ b/tests/test-up-local-change.out	Wed Mar 29 10:27:16 2006 -0800
@@ -101,7 +101,7 @@
  a (resolve)
  b (resolve)
 aborting update spanning branches!
-(use update -m to merge across branches or -C to lose changes)
+(use 'hg merge' to merge across branches or '-C' to lose changes)
 failed
 abort: outstanding uncommitted changes
 failed