Patchwork [4,of,4,V6-2] bookmarks: rewrite comparing bookmarks in commands.summary() by compare()

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 19, 2015, 2:41 p.m.
Message ID <66448f60e4207f79e33c.1426776072@juju>
Download mbox | patch
Permalink /patch/8162/
State Accepted
Commit 03c84c966ef5940e7b1b27d40ec2805b55f0a13e
Headers show

Comments

Katsunori FUJIWARA - March 19, 2015, 2:41 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1426775766 -32400
#      Thu Mar 19 23:36:06 2015 +0900
# Node ID 66448f60e4207f79e33c6ee09c54fef719708a8c
# Parent  c714fc4a9c335fc03752771fa2a8586ebbcd9f58
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()

This patch adds utility function "summary()", to replace comparing
bookmarks in "commands.summary()". This replacement finishes
centralizing the logic to compare bookmarks into "bookmarks.compare()".

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.

This test uses "(glob)" to ignore summary about incoming/outgoing
changesets.
Matt Mackall - March 19, 2015, 9:44 p.m.
On Thu, 2015-03-19 at 23:41 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1426775766 -32400
> #      Thu Mar 19 23:36:06 2015 +0900
> # Node ID 66448f60e4207f79e33c6ee09c54fef719708a8c
> # Parent  c714fc4a9c335fc03752771fa2a8586ebbcd9f58
> bookmarks: rewrite comparing bookmarks in commands.summary() by compare()

These are queued for default, thanks. Though we probably want similar
info for branches.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -498,6 +498,16 @@  def outgoing(ui, repo, other):
 
     return 0
 
+def summary(repo, other):
+    '''Compare bookmarks between repo and other for "hg summary" output
+
+    This returns "(# of incoming, # of outgoing)" tuple.
+    '''
+    r = compare(repo, other.listkeys('bookmarks'), repo._bookmarks,
+                dsthex=hex)
+    addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
+    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
@@ -5982,14 +5982,11 @@  def summary(ui, repo, **opts):
             t.append(_('%d outgoing') % len(o))
         other = dother or sother
         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
@@ -494,6 +494,13 @@  pushing a new bookmark on a new head doe
   $ hg -R ../b id -r W
   cc978a373a53 tip W
 
+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 ..
 
 pushing an unchanged bookmark should result in no changes