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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Oct 2 09:38:42 CDT 2013


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1380723659 -32400
#      Wed Oct 02 23:20:59 2013 +0900
# Node ID 0f9bfa66f2ddb9a019619d48bd5237d8c8a9ac0a
# Parent  ba759054d28fe66d42972d373f3fe4e942893309
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
@@ -427,6 +427,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
@@ -5545,14 +5545,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