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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Sep 22 09:05:31 CDT 2013


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1379858556 -32400
#      Sun Sep 22 23:02:36 2013 +0900
# Node ID 343b503c285bcd8963180f2acfa1dfe75f4b6ca5
# Parent  ca756257986f99543b997976f096e8f9cd50ba4c
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
@@ -433,6 +433,17 @@
         return 1
     return 0
 
+def summary(repo, other):
+    results = compare(repo, other.listkeys('bookmarks'), repo._bookmarks,
+                      dsthex=hex)
+    addsrc, adddst = 0, 0
+    for k, b, s, d in results:
+        if k == 'addsrc':
+            addsrc += 1
+        elif k == 'adddst':
+            adddst += 1
+    return (addsrc, 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
@@ -5543,14 +5543,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