changeset 3316:39fd6e82ea38

merge: pull user messages out to hg.py - add _update for shadowing in clone - add _showstats helper - remove update parameter defaults - move stats message and merge help messages
author Matt Mackall <mpm@selenic.com>
date Tue, 10 Oct 2006 03:39:44 -0500
parents 38be819a1225
children 34f08b8883cf
files mercurial/hg.py mercurial/merge.py
diffstat 2 files changed, 38 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Tue Oct 10 02:31:02 2006 -0500
+++ b/mercurial/hg.py	Tue Oct 10 03:39:44 2006 -0500
@@ -201,30 +201,55 @@
             dest_lock.release()
 
         if update:
-            _merge.update(dest_repo, dest_repo.changelog.tip())
+            _update(dest_repo, dest_repo.changelog.tip())
     if dir_cleanup:
         dir_cleanup.close()
 
     return src_repo, dest_repo
 
+def _showstats(repo, stats):
+    stats = ((stats[0], _("updated")),
+             (stats[1], _("merged")),
+             (stats[2], _("removed")),
+             (stats[3], _("unresolved")))
+    note = ", ".join([_("%d files %s") % s for s in stats])
+    repo.ui.status("%s\n" % note)
+
+def _update(repo, node): return update(repo, node)
+
 def update(repo, node):
     """update the working directory to node, merging linear changes"""
-    return _merge.update(repo, node)
+    stats = _merge.update(repo, node, False, False, None, None)
+    _showstats(repo, stats)
+    if stats[3]:
+        repo.ui.status(_("There are unresolved merges with"
+                         " locally modified files.\n"))
+    return stats[3]
 
 def clean(repo, node, wlock=None, show_stats=True):
     """forcibly switch the working directory to node, clobbering changes"""
-    return _merge.update(repo, node, force=True, wlock=wlock,
-                         show_stats=show_stats)
+    stats = _merge.update(repo, node, False, True, None, wlock)
+    if show_stats: _showstats(repo, stats)
+    return stats[3]
 
 def merge(repo, node, force=None, remind=True, wlock=None):
     """branch merge with node, resolving changes"""
-    return _merge.update(repo, node, branchmerge=True, force=force,
-                         remind=remind, wlock=wlock)
+    stats = _merge.update(repo, node, True, force, False, wlock)
+    _showstats(repo, stats)
+    if stats[3]:
+        pl = repo.parents()
+        repo.ui.status(_("There are unresolved merges,"
+                         " you can redo the full merge using:\n"
+                         "  hg update -C %s\n"
+                         "  hg merge %s\n"
+                         % (pl[0].rev(), pl[1].rev())))
+    elif remind:
+        repo.ui.status(_("(branch merge, don't forget to commit)\n"))
+    return stats[3]
 
 def revert(repo, node, choose, wlock):
     """revert changes to revision in node without updating dirstate"""
-    return _merge.update(repo, node, force=True, partial=choose,
-                         show_stats=False, wlock=wlock)
+    return _merge.update(repo, node, False, True, choose, wlock)[3]
 
 def verify(repo):
     """verify the consistency of a repository"""
--- a/mercurial/merge.py	Tue Oct 10 02:31:02 2006 -0500
+++ b/mercurial/merge.py	Tue Oct 10 03:39:44 2006 -0500
@@ -291,15 +291,14 @@
             if filemerge(repo, f, f2, wctx, mctx):
                 unresolved += 1
             else:
+                merged += 1
                 if f != fd:
                     repo.ui.debug(_("copying %s to %s\n") % (f, fd))
                     repo.wwrite(fd, repo.wread(f))
                     if move:
                         repo.ui.debug(_("removing %s\n") % f)
                         os.unlink(repo.wjoin(f))
-
             util.set_exec(repo.wjoin(fd), flag)
-            merged += 1
         elif m == "g": # get
             flag = a[2]
             repo.ui.note(_("getting %s\n") % f)
@@ -352,8 +351,7 @@
                 else:
                     repo.dirstate.copy(f2, fd)
 
-def update(repo, node, branchmerge=False, force=False, partial=None,
-           wlock=None, show_stats=True, remind=True):
+def update(repo, node, branchmerge, force, partial, wlock):
     """
     Perform a merge between the working directory and the given node
 
@@ -361,8 +359,6 @@
     force = whether to force branch merging or file overwriting
     partial = a function to filter file lists (dirstate not updated)
     wlock = working dir lock, if already held
-    show_stats = whether to report merge statistics
-    remind = whether to remind about merge
     """
 
     if not wlock:
@@ -404,32 +400,12 @@
     if not partial:
         repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
 
-    updated, merged, removed, unresolved = applyupdates(repo, action, wc, p2)
+    stats = applyupdates(repo, action, wc, p2)
 
-    if show_stats:
-        stats = ((updated, _("updated")),
-                 (merged - unresolved, _("merged")),
-                 (removed, _("removed")),
-                 (unresolved, _("unresolved")))
-        note = ", ".join([_("%d files %s") % s for s in stats])
-        repo.ui.status("%s\n" % note)
     if not partial:
         recordupdates(repo, action, branchmerge, p2)
         repo.dirstate.setparents(fp1, fp2)
-        repo.hook('update', parent1=xp1, parent2=xp2, error=unresolved)
+        repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
 
-        if branchmerge:
-            if unresolved:
-                repo.ui.status(_("There are unresolved merges,"
-                                " you can redo the full merge using:\n"
-                                "  hg update -C %s\n"
-                                "  hg merge %s\n"
-                                % (p1.rev(), p2.rev())))
-            elif remind:
-                repo.ui.status(_("(branch merge, don't forget to commit)\n"))
-        elif unresolved:
-            repo.ui.status(_("There are unresolved merges with"
-                             " locally modified files.\n"))
+    return stats
 
-    return unresolved
-