hgext/graphlog.py
changeset 8838 e89b05308d69
parent 8837 d8e3a98018cb
child 8839 bbfa21b6f18a
equal deleted inserted replaced
8837:d8e3a98018cb 8838:e89b05308d69
    17 from mercurial.commands import templateopts
    17 from mercurial.commands import templateopts
    18 from mercurial.i18n import _
    18 from mercurial.i18n import _
    19 from mercurial.node import nullrev
    19 from mercurial.node import nullrev
    20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
    20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
    21 from mercurial import hg, url, util, graphmod
    21 from mercurial import hg, url, util, graphmod
       
    22 
       
    23 def asciiformat(ui, repo, revdag, opts):
       
    24     """formats a changelog DAG walk for ASCII output"""
       
    25     showparents = [ctx.node() for ctx in repo[None].parents()]
       
    26     displayer = show_changeset(ui, repo, opts, buffered=True)
       
    27     for (ctx, parents) in revdag:
       
    28         displayer.show(ctx)
       
    29         lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1]
       
    30         char = ctx.node() in showparents and '@' or 'o'
       
    31         yield (ctx.rev(), parents, char, lines)
    22 
    32 
    23 def grapher(nodes):
    33 def grapher(nodes):
    24     """grapher for asciigraph on a list of nodes and their parents
    34     """grapher for asciigraph on a list of nodes and their parents
    25 
    35 
    26     nodes must generate tuples (node, parents, char, lines) where
    36     nodes must generate tuples (node, parents, char, lines) where
   246     if path: # could be reset in canonpath
   256     if path: # could be reset in canonpath
   247         revdag = graphmod.filerevs(repo, path, start, stop)
   257         revdag = graphmod.filerevs(repo, path, start, stop)
   248     else:
   258     else:
   249         revdag = graphmod.revisions(repo, start, stop)
   259         revdag = graphmod.revisions(repo, start, stop)
   250 
   260 
   251     graphdag = graphabledag(ui, repo, revdag, opts)
   261     graphdag = asciiformat(ui, repo, revdag, opts)
   252     ascii(ui, grapher(graphdag))
   262     ascii(ui, grapher(graphdag))
   253 
   263 
   254 def graphrevs(repo, nodes, opts):
   264 def graphrevs(repo, nodes, opts):
   255     limit = cmdutil.loglimit(opts)
   265     limit = cmdutil.loglimit(opts)
   256     nodes.reverse()
   266     nodes.reverse()
   257     if limit < sys.maxint:
   267     if limit < sys.maxint:
   258         nodes = nodes[:limit]
   268         nodes = nodes[:limit]
   259     return graphmod.nodes(repo, nodes)
   269     return graphmod.nodes(repo, nodes)
   260 
       
   261 def graphabledag(ui, repo, revdag, opts):
       
   262     showparents = [ctx.node() for ctx in repo[None].parents()]
       
   263     displayer = show_changeset(ui, repo, opts, buffered=True)
       
   264     for (ctx, parents) in revdag:
       
   265         displayer.show(ctx)
       
   266         lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1]
       
   267         char = ctx.node() in showparents and '@' or 'o'
       
   268         yield (ctx.rev(), parents, char, lines)
       
   269 
   270 
   270 def goutgoing(ui, repo, dest=None, **opts):
   271 def goutgoing(ui, repo, dest=None, **opts):
   271     """show the outgoing changesets alongside an ASCII revision graph
   272     """show the outgoing changesets alongside an ASCII revision graph
   272 
   273 
   273     Print the outgoing changesets alongside a revision graph drawn with
   274     Print the outgoing changesets alongside a revision graph drawn with
   290         ui.status(_("no changes found\n"))
   291         ui.status(_("no changes found\n"))
   291         return
   292         return
   292 
   293 
   293     o = repo.changelog.nodesbetween(o, revs)[0]
   294     o = repo.changelog.nodesbetween(o, revs)[0]
   294     revdag = graphrevs(repo, o, opts)
   295     revdag = graphrevs(repo, o, opts)
   295     graphdag = graphabledag(ui, repo, revdag, opts)
   296     graphdag = asciiformat(ui, repo, revdag, opts)
   296     ascii(ui, grapher(graphdag))
   297     ascii(ui, grapher(graphdag))
   297 
   298 
   298 def gincoming(ui, repo, source="default", **opts):
   299 def gincoming(ui, repo, source="default", **opts):
   299     """show the incoming changesets alongside an ASCII revision graph
   300     """show the incoming changesets alongside an ASCII revision graph
   300 
   301 
   339                 # use the created uncompressed bundlerepo
   340                 # use the created uncompressed bundlerepo
   340                 other = bundlerepo.bundlerepository(ui, repo.root, fname)
   341                 other = bundlerepo.bundlerepository(ui, repo.root, fname)
   341 
   342 
   342         chlist = other.changelog.nodesbetween(incoming, revs)[0]
   343         chlist = other.changelog.nodesbetween(incoming, revs)[0]
   343         revdag = graphrevs(other, chlist, opts)
   344         revdag = graphrevs(other, chlist, opts)
   344         graphdag = graphabledag(ui, repo, revdag, opts)
   345         graphdag = asciiformat(ui, repo, revdag, opts)
   345         ascii(ui, grapher(graphdag))
   346         ascii(ui, grapher(graphdag))
   346 
   347 
   347     finally:
   348     finally:
   348         if hasattr(other, 'close'):
   349         if hasattr(other, 'close'):
   349             other.close()
   350             other.close()