[PATCH 1 of 3] Add 'goutgoing' command to graphlog extension

Alpar Juttner alpar at cs.elte.hu
Fri Nov 21 03:57:25 CST 2008


# HG changeset patch
# User Alpar Juttner <alpar at cs.elte.hu>
# Date 1227216645 0
# Node ID a19defd9b33a9016be2e95159881ce6b8381fed0
# Parent  92c952c4470c41647a30184b21466554021d580e
Add 'goutgoing' command to graphlog extension

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

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -9,10 +9,11 @@
 import os
 import sys
 from mercurial.cmdutil import revrange, show_changeset
-from mercurial.commands import templateopts
+from mercurial.commands import templateopts, logopts, remoteopts
 from mercurial.i18n import _
 from mercurial.node import nullrev
 from mercurial.util import Abort, canonpath
+from mercurial import hg, ui, cmdutil, url
 
 def revisions(repo, start, stop):
     """cset DAG generator yielding (rev, node, [parents]) tuples
@@ -293,6 +294,63 @@
 
     ascii(ui, grapher(graphabledag()))
 
+def outgoing_revs(ui, repo, dest, opts):
+    """cset DAG generator yielding (node, [parents]) tuples
+
+    This generator function walks through the revisions not found
+    in the destination
+    """
+    limit = cmdutil.loglimit(opts)
+    dest, revs, checkout = hg.parseurl(
+        ui.expandpath(dest or 'default-push', dest or 'default'),
+        opts.get('rev'))
+    cmdutil.setremoteconfig(ui, opts)
+    if revs:
+        revs = [repo.lookup(rev) for rev in revs]
+    other = hg.repository(ui, dest)
+    ui.status(_('comparing with %s\n') % url.hidepassword(dest))
+    o = repo.findoutgoing(other, force=opts.get('force'))
+    if not o:
+        ui.status(_("no changes found\n"))
+        return
+    o = repo.changelog.nodesbetween(o, revs)[0]
+    o.reverse()
+    revdict = {}
+    for n in o:
+        revdict[repo.changectx(n).rev()]=True
+    count = 0
+    for n in o:
+        if count >= limit:
+            break
+        ctx = repo.changectx(n)
+        parents = [p.rev() for p in ctx.parents() if p.rev() in revdict]
+        parents.sort()
+        yield (ctx, parents)
+        count += 1
+
+def goutgoing(ui, repo, dest=None, **opts):
+    """show the outgoing changesets alongside an ASCII revision graph
+
+    Print the outgoing changesets alongside a revision graph drawn with
+    ASCII characters.
+
+    Nodes printed as an @ character are parents of the working
+    directory.
+    """
+    revdag = outgoing_revs(ui, repo, dest, opts)
+    repo_parents = repo.dirstate.parents()
+    displayer = show_changeset(ui, repo, 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 repo_parents and '@' or 'o'
+            yield (ctx.rev(), parents, char, lines)
+
+    ascii(ui, grapher(graphabledag()))
+
 cmdtable = {
     "glog":
         (graphlog,
@@ -301,4 +359,12 @@
           ('r', 'rev', [], _('show the specified revision or range')),
          ] + templateopts,
          _('hg glog [OPTION]... [FILE]')),
+    "goutgoing|gout":
+        (goutgoing,
+         [('f', 'force', None,
+           _('run even when remote repository is unrelated')),
+          ('r', 'rev', [],
+           _('a specific revision up to which you would like to push')),
+         ] + logopts + remoteopts,
+         _('[-M] [-p] [-f] [-r REV]... [DEST]')),
 }


More information about the Mercurial-devel mailing list