Patchwork [05,of,15,V4] bookmarks: rewrite comparing bookmarks in "commands.summary()" by "compare()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 15, 2013, 3:25 p.m.
Message ID <f7d7c8c9614afbd13d75.1381850727@juju>
Download mbox | patch
Permalink /patch/2776/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Oct. 15, 2013, 3:25 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1381849966 -32400
#      Wed Oct 16 00:12:46 2013 +0900
# Node ID f7d7c8c9614afbd13d750e3021e6140078bdf58a
# Parent  ebefd33e7ca3eb68211c63daefec42f76fc9ee72
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.

Patch

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
@@ -5546,14 +5546,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 ..