[PATCH] bookmarks: Add -B option to incoming/outgoing to compare bookmarks

David Soria Parra dsp at php.net
Sun Jun 20 05:31:31 CDT 2010


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1277029608 -7200
# Node ID 8eac6de572daa918ffd2e196657aa3d3296e5cf6
# Parent  c040847539905c3f9c8b417586128695c72f3dd4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks

We add a -B/--bookmarks option to hg incmoing and hg outgoing. If the option
is passed we compare bookmarks instead of changesets. This can be used
to see which bookmarks do not exists on the remote site.

diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
--- a/hgext/bookmarks.py
+++ b/hgext/bookmarks.py
@@ -29,7 +29,7 @@
 '''
 
 from mercurial.i18n import _
-from mercurial.node import nullid, nullrev, hex, short
+from mercurial.node import nullid, nullrev, hex, short, url
 from mercurial import util, commands, repair, extensions, pushkey, hg
 import os
 
@@ -445,6 +445,37 @@
 
     return result
 
+def diffbookmarks(ui, repo, remote):
+    ui.status(_("searching for changes\n"))
+
+    lmarks = repo.listkeys('bookmarks')
+    rmarks = remote.listkeys('bookmarks')
+
+    diff = set(rmarks) - set(lmarks)
+    for k in diff:
+        ui.write("   %-25s %s\n" % (k, rmarks[k][:12]))
+
+    if len(diff) <= 0:
+        ui.status(_("no changes found\n"))
+
+def incoming(oldincoming, ui, repo, source="default", **opts):
+    if opts.get('bookmarks'):
+        source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
+        other = hg.repository(hg.remoteui(repo, opts), source)
+        ui.status(_('comparing with %s\n') % url.hidepassword(source))
+        diffbookmarks(ui, repo, other)
+    else:
+        oldincoming(ui, repo, source, **opts)
+
+def outgoing(oldoutgoing, ui, repo, source="default", **opts):
+    if opts.get('bookmarks'):
+        source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
+        other = hg.repository(hg.remoteui(repo, opts), source)
+        ui.status(_('comparing with %s\n') % url.hidepassword(source))
+        diffbookmarks(ui, other, repo)
+    else:
+        oldoutgoing(ui, repo, source, **opts)
+
 def uisetup(ui):
     extensions.wrapfunction(repair, "strip", strip)
     if ui.configbool('bookmarks', 'track.current'):
@@ -456,6 +487,12 @@
     entry = extensions.wrapcommand(commands.table, 'push', push)
     entry[1].append(('B', 'bookmark', [],
                      _("bookmark to export")))
+    entry = extensions.wrapcommand(commands.table, 'incoming', incoming)
+    entry[1].append(('B', 'bookmarks', False,
+                     _("compare bookmark")))
+    entry = extensions.wrapcommand(commands.table, 'outgoing', outgoing)
+    entry[1].append(('B', 'bookmarks', False,
+                     _("compare bookmark")))
 
     pushkey.register('bookmarks', pushbookmark, listbookmarks)
 



More information about the Mercurial-devel mailing list