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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 19, 2015, 2:41 p.m.
Message ID <c193872b3f0e3a38c151.1426776070@juju>
Download mbox | patch
Permalink /patch/8159/
State Accepted
Commit c0096a2bd3ff5b4318907401d8e7da740649a020
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 c193872b3f0e3a38c15195039fd6675e55643c3b
# Parent  00524ae3512103c33f6365a90ef91d6604d09920
bookmarks: add outgoing() to replace diff() for outgoing bookmarks

This replacement makes enhancement of "show outgoing 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
@@ -470,6 +470,34 @@  def incoming(ui, repo, other):
 
     return 0
 
+def outgoing(ui, repo, other):
+    '''Show bookmarks outgoing from repo to other
+    '''
+    ui.status(_("searching for changed bookmarks\n"))
+
+    r = compare(repo, repo._bookmarks, other.listkeys('bookmarks'),
+                srchex=hex)
+    addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
+
+    outgoings = []
+    if ui.debugflag:
+        getid = lambda id: id
+    else:
+        getid = lambda id: id[:12]
+    def add(b, id):
+        outgoings.append("   %-25s %s\n" % (b, getid(id)))
+    for b, scid, dcid in addsrc:
+        add(b, scid)
+
+    if not outgoings:
+        ui.status(_("no changed bookmarks found\n"))
+        return 1
+
+    for s in sorted(outgoings):
+        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
@@ -4757,7 +4757,7 @@  def outgoing(ui, repo, dest=None, **opts
             ui.warn(_("remote doesn't support bookmarks\n"))
             return 0
         ui.status(_('comparing with %s\n') % util.hidepassword(dest))
-        return bookmarks.diff(ui, other, repo)
+        return bookmarks.outgoing(ui, repo, other)
 
     repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default')
     try: