[PATCH 2 of 2] Add 'gincoming' command to graphlog extension

Alpar Juttner alpar at cs.elte.hu
Thu Nov 20 15:54:09 CST 2008


# HG changeset patch
# User Alpar Juttner <alpar at cs.elte.hu>
# Date 1227216646 0
# Node ID 909b90610219116e2b682d00db3392d8ef8867e9
# Parent  a19defd9b33a9016be2e95159881ce6b8381fed0
Add 'gincoming' command to graphlog extension.

It accects the same options as the 'incoming' command, except for
--newest-first.

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -13,7 +13,7 @@
 from mercurial.i18n import _
 from mercurial.node import nullrev
 from mercurial.util import Abort, canonpath
-from mercurial import hg, ui, cmdutil, url
+from mercurial import hg, ui, cmdutil, url, changegroup, bundlerepo
 
 def revisions(repo, start, stop):
     """cset DAG generator yielding (rev, node, [parents]) tuples
@@ -351,6 +351,91 @@
 
     ascii(ui, grapher(graphabledag()))
 
+def incoming_revs(other, chlist, opts):
+    """cset DAG generator yielding (node, [parents]) tuples
+
+    This generator function walks through the revisions of the destination
+    not found in repo
+    """
+    limit = cmdutil.loglimit(opts)
+    chlist.reverse()
+    revdict = {}
+    for n in chlist:
+        revdict[other.changectx(n).rev()]=True
+    count = 0
+    for n in chlist:
+        if count >= limit:
+            break
+        ctx = other.changectx(n)
+        parents = [p.rev() for p in ctx.parents() if p.rev() in revdict]
+        parents.sort()
+        yield (ctx, parents)
+        count += 1
+
+def gincoming(ui, repo, source="default", **opts):
+    """show the incoming changesets alongside an ASCII revision graph
+
+    Print the incoming changesets alongside a revision graph drawn with
+    ASCII characters.
+
+    Nodes printed as an @ character are parents of the working
+    directory.
+    """
+
+    source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
+    cmdutil.setremoteconfig(ui, opts)
+
+    other = hg.repository(ui, source)
+    ui.status(_('comparing with %s\n') % url.hidepassword(source))
+    if revs:
+        revs = [other.lookup(rev) for rev in revs]
+    incoming = repo.findincoming(other, heads=revs, force=opts["force"])
+    if not incoming:
+        try:
+            os.unlink(opts["bundle"])
+        except:
+            pass
+        ui.status(_("no changes found\n"))
+        return
+
+    cleanup = None
+    try:
+        fname = opts["bundle"]
+        if fname or not other.local():
+            # create a bundle (uncompressed if other repo is not local)
+            if revs is None:
+                cg = other.changegroup(incoming, "incoming")
+            else:
+                cg = other.changegroupsubset(incoming, revs, 'incoming')
+            bundletype = other.local() and "HG10BZ" or "HG10UN"
+            fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
+            # keep written bundle?
+            if opts["bundle"]:
+                cleanup = None
+            if not other.local():
+                # use the created uncompressed bundlerepo
+                other = bundlerepo.bundlerepository(ui, repo.root, fname)
+
+        chlist = other.changelog.nodesbetween(incoming, revs)[0]
+        revdag = incoming_revs(other, chlist, opts)
+        other_parents = other.dirstate.parents()
+        displayer = show_changeset(ui, other, opts, buffered=True)
+        def graphabledag():
+            for (ctx, parents) in revdag:
+                # log_strings is the list of all log strings to draw alongside
+                # the graph.
+                displayer.show(ctx)
+                lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
+                char = ctx.node() in other_parents and '@' or 'o'
+                yield (ctx.rev(), parents, char, lines)
+
+        ascii(ui, grapher(graphabledag()))
+    finally:
+        if hasattr(other, 'close'):
+            other.close()
+        if cleanup:
+            os.unlink(cleanup)
+
 cmdtable = {
     "glog":
         (graphlog,
@@ -359,6 +444,16 @@
           ('r', 'rev', [], _('show the specified revision or range')),
          ] + templateopts,
          _('hg glog [OPTION]... [FILE]')),
+    "gincoming|gin":
+        (gincoming,
+         [('f', 'force', None,
+           _('run even when remote repository is unrelated')),
+          ('', 'bundle', '', _('file to store the bundles into')),
+          ('r', 'rev', [],
+           _('a specific revision up to which you would like to pull')),
+         ] + logopts + remoteopts,
+         _('[-p] [-M] [-f] [-r REV]...'
+           ' [--bundle FILENAME] [SOURCE]')),
     "goutgoing|gout":
         (goutgoing,
          [('f', 'force', None,


More information about the Mercurial-devel mailing list