Patchwork [1,of,4,V6-2] bookmarks: add incoming() to replace diff() for incoming bookmarks

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 19, 2015, 2:41 p.m.
Message ID <00524ae3512103c33f63.1426776069@juju>
Download mbox | patch
Permalink /patch/8160/
State Accepted
Commit d0ea2028e8e668a459bbfdf0a49d68e3f6a20d8e
Headers show

Comments

Katsunori FUJIWARA - March 19, 2015, 2:41 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1426775765 -32400
#      Thu Mar 19 23:36:05 2015 +0900
# Node ID 00524ae3512103c33f6365a90ef91d6604d09920
# Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
bookmarks: add incoming() to replace diff() for incoming bookmarks

This replacement makes enhancement of "show incoming bookmarks" easy,
because "compare()" can detect more detailed difference of bookmarks
between two repositories.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -442,6 +442,34 @@  def updatefromremote(ui, repo, remotemar
             writer(msg)
         localmarks.recordchange(tr)
 
+def incoming(ui, repo, other):
+    '''Show bookmarks incoming from other to repo
+    '''
+    ui.status(_("searching for changed bookmarks\n"))
+
+    r = compare(repo, other.listkeys('bookmarks'), repo._bookmarks,
+                dsthex=hex)
+    addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
+
+    incomings = []
+    if ui.debugflag:
+        getid = lambda id: id
+    else:
+        getid = lambda id: id[:12]
+    def add(b, id):
+        incomings.append("   %-25s %s\n" % (b, getid(id)))
+    for b, scid, dcid in addsrc:
+        add(b, scid)
+
+    if not incomings:
+        ui.status(_("no changed bookmarks found\n"))
+        return 1
+
+    for s in sorted(incomings):
+        ui.write(s)
+
+    return 0
+
 def diff(ui, dst, src):
     ui.status(_("searching for changed bookmarks\n"))
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4302,7 +4302,7 @@  def incoming(ui, repo, source="default",
             ui.warn(_("remote doesn't support bookmarks\n"))
             return 0
         ui.status(_('comparing with %s\n') % util.hidepassword(source))
-        return bookmarks.diff(ui, repo, other)
+        return bookmarks.incoming(ui, repo, other)
 
     repo._subtoppath = ui.expandpath(source)
     try: