[PATCH 05 of 15 V5] bookmarks: rewrite comparing bookmarks in "commands.summary()" by "compare()"

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Nov 7 21:54:15 CST 2013


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1383882352 -32400
#      Fri Nov 08 12:45:52 2013 +0900
# Node ID d089a7cf094309bde506b7651f3c8f29343ca02d
# Parent  b15d68e0de47ea0dcc81777de5a5edbc148badf5
bookmarks: rewrite comparing bookmarks in "commands.summary()" by "compare()"

This patch adds "summary()", which uses "compare()" to compare
bookmarks between the local and the remote repositories, to replace
comparing bookmarks in "commands.summary()".

This patch also adds test to check summary output with
incoming/outgoing bookmarks, because "hg summary --remote" is not
tested yet on the repository with incoming/outgoing bookmarks.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -426,6 +426,12 @@
         return 1
     return 0
 
+def summary(repo, other):
+    (addsrc, adddst, advsrc, advdst, diverge, differ, invalid
+     ) = compare(repo, other.listkeys('bookmarks'), repo._bookmarks,
+                 dsthex=hex)
+    return (len(addsrc), len(adddst))
+
 def validdest(repo, old, new):
     """Is the new bookmark destination a valid update from the old one"""
     repo = repo.unfiltered()
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5552,14 +5552,11 @@
         if o:
             t.append(_('%d outgoing') % len(o))
         if 'bookmarks' in other.listkeys('namespaces'):
-            lmarks = repo.listkeys('bookmarks')
-            rmarks = other.listkeys('bookmarks')
-            diff = set(rmarks) - set(lmarks)
-            if len(diff) > 0:
-                t.append(_('%d incoming bookmarks') % len(diff))
-            diff = set(lmarks) - set(rmarks)
-            if len(diff) > 0:
-                t.append(_('%d outgoing bookmarks') % len(diff))
+            counts = bookmarks.summary(repo, other)
+            if counts[0] > 0:
+                t.append(_('%d incoming bookmarks') % counts[0])
+            if counts[1] > 0:
+                t.append(_('%d outgoing bookmarks') % counts[1])
 
         if t:
             # i18n: column positioning for "hg summary"
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -424,4 +424,10 @@
   remote: added 1 changesets with 1 changes to 1 files
   exporting bookmark add-foo
 
+Check summary output for incoming/outgoing bookmarks
+  $ hg bookmarks -d X
+  $ hg bookmarks -d Y
+  $ hg summary --remote | grep '^remote:'
+  remote: *2 incoming bookmarks, 1 outgoing bookmarks (glob)
+
   $ cd ..


More information about the Mercurial-devel mailing list