mercurial/debugcommands.py
changeset 30514 625ccc95fa96
parent 30505 158b41842fd2
child 30515 cdd1885d0f2f
equal deleted inserted replaced
30513:ff7df4bb75de 30514:625ccc95fa96
   355 
   355 
   356     cmdlist, unused_allcmds = cmdutil.findpossible(cmd, commands.table)
   356     cmdlist, unused_allcmds = cmdutil.findpossible(cmd, commands.table)
   357     if ui.verbose:
   357     if ui.verbose:
   358         cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
   358         cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
   359     ui.write("%s\n" % "\n".join(sorted(cmdlist)))
   359     ui.write("%s\n" % "\n".join(sorted(cmdlist)))
       
   360 
       
   361 @command('debugdag',
       
   362     [('t', 'tags', None, _('use tags as labels')),
       
   363     ('b', 'branches', None, _('annotate with branch names')),
       
   364     ('', 'dots', None, _('use dots for runs')),
       
   365     ('s', 'spaces', None, _('separate elements by spaces'))],
       
   366     _('[OPTION]... [FILE [REV]...]'),
       
   367     optionalrepo=True)
       
   368 def debugdag(ui, repo, file_=None, *revs, **opts):
       
   369     """format the changelog or an index DAG as a concise textual description
       
   370 
       
   371     If you pass a revlog index, the revlog's DAG is emitted. If you list
       
   372     revision numbers, they get labeled in the output as rN.
       
   373 
       
   374     Otherwise, the changelog DAG of the current repo is emitted.
       
   375     """
       
   376     spaces = opts.get('spaces')
       
   377     dots = opts.get('dots')
       
   378     if file_:
       
   379         rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
       
   380         revs = set((int(r) for r in revs))
       
   381         def events():
       
   382             for r in rlog:
       
   383                 yield 'n', (r, list(p for p in rlog.parentrevs(r)
       
   384                                         if p != -1))
       
   385                 if r in revs:
       
   386                     yield 'l', (r, "r%i" % r)
       
   387     elif repo:
       
   388         cl = repo.changelog
       
   389         tags = opts.get('tags')
       
   390         branches = opts.get('branches')
       
   391         if tags:
       
   392             labels = {}
       
   393             for l, n in repo.tags().items():
       
   394                 labels.setdefault(cl.rev(n), []).append(l)
       
   395         def events():
       
   396             b = "default"
       
   397             for r in cl:
       
   398                 if branches:
       
   399                     newb = cl.read(cl.node(r))[5]['branch']
       
   400                     if newb != b:
       
   401                         yield 'a', newb
       
   402                         b = newb
       
   403                 yield 'n', (r, list(p for p in cl.parentrevs(r)
       
   404                                         if p != -1))
       
   405                 if tags:
       
   406                     ls = labels.get(r)
       
   407                     if ls:
       
   408                         for l in ls:
       
   409                             yield 'l', (r, l)
       
   410     else:
       
   411         raise error.Abort(_('need repo for changelog dag'))
       
   412 
       
   413     for line in dagparser.dagtextlines(events(),
       
   414                                        addspaces=spaces,
       
   415                                        wraplabels=True,
       
   416                                        wrapannotations=True,
       
   417                                        wrapnonlinear=dots,
       
   418                                        usedots=dots,
       
   419                                        maxlinewidth=70):
       
   420         ui.write(line)
       
   421         ui.write("\n")