changeset 2019:ced2d3620f95

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.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Wed, 29 Mar 2006 10:27:16 -0800
parents 1a09814a5b1f
children 00925397236c
files 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
diffstat 15 files changed, 63 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1998,6 +1998,16 @@ def manifest(ui, repo, rev=None):
     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 @@ def paths(ui, repo, search=None):
         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 @@ def pull(ui, repo, source="default", **o
         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 @@ def push(ui, repo, dest="default-push", 
     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 @@ def serve(ui, repo, **opts):
                 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 @@ def unbundle(ui, repo, fname, **opts):
         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 @@ table = {
           ('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
+++ b/mercurial/localrepo.py
@@ -964,7 +964,7 @@ class localrepository(object):
 
         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 @@ class localrepository(object):
         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 @@ class localrepository(object):
             return cl.rev(x)
 
         if not source:
-            return
+            return 0
 
         self.hook('prechangegroup', throw=True)
 
@@ -1424,6 +1426,8 @@ class localrepository(object):
             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 @@ class localrepository(object):
                         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
+++ b/mercurial/sshrepo.py
@@ -130,4 +130,7 @@ class sshrepository(remoterepository):
 
         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
+++ b/tests/test-clone-r.out
@@ -118,7 +118,7 @@ adding changesets
 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
+++ b/tests/test-filebranch.out
@@ -13,7 +13,7 @@ adding changesets
 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
+++ b/tests/test-flags.out
@@ -11,7 +11,7 @@ adding changesets
 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
+++ b/tests/test-help.out
@@ -59,6 +59,7 @@ list of commands (use "hg help -v" to sh
  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 @@ list of commands (use "hg help -v" to sh
  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
+++ b/tests/test-merge5.out
@@ -2,4 +2,4 @@ removing b
 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
+++ b/tests/test-merge6.out
@@ -4,7 +4,7 @@ adding changesets
 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 changesets
 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
+++ b/tests/test-merge7.out
@@ -4,7 +4,7 @@ adding changesets
 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 changesets
 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
+++ b/tests/test-pull-pull-corruption.out
@@ -16,7 +16,7 @@ adding changesets
 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
+++ b/tests/test-push-r.out
@@ -127,7 +127,7 @@ adding changesets
 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
+++ b/tests/test-push-warn.out
@@ -8,7 +8,7 @@ adding changesets
 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
+++ b/tests/test-unrelated-pull.out
@@ -8,7 +8,7 @@ adding changesets
 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
+++ b/tests/test-up-local-change.out
@@ -101,7 +101,7 @@ this update spans a branch affecting the
  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