mercurial/commands.py
changeset 11336 3dfbe26cfded
parent 11331 997ab9af81df
child 11337 0f3c8a47960e
equal deleted inserted replaced
11335:3201ff1459dd 11336:3dfbe26cfded
    12 import hg, util, revlog, bundlerepo, extensions, copies, error
    12 import hg, util, revlog, bundlerepo, extensions, copies, error
    13 import patch, help, mdiff, url, encoding, templatekw, discovery
    13 import patch, help, mdiff, url, encoding, templatekw, discovery
    14 import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server
    14 import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server
    15 import merge as mergemod
    15 import merge as mergemod
    16 import minirst, revset
    16 import minirst, revset
       
    17 import dagparser
    17 
    18 
    18 # Commands start here, listed alphabetically
    19 # Commands start here, listed alphabetically
    19 
    20 
    20 def add(ui, repo, *pats, **opts):
    21 def add(ui, repo, *pats, **opts):
    21     """add the specified files on the next commit
    22     """add the specified files on the next commit
  1020         rev = None
  1021         rev = None
  1021     for k, v in sorted(repo[rev].substate.items()):
  1022     for k, v in sorted(repo[rev].substate.items()):
  1022         ui.write('path %s\n' % k)
  1023         ui.write('path %s\n' % k)
  1023         ui.write(' source   %s\n' % v[0])
  1024         ui.write(' source   %s\n' % v[0])
  1024         ui.write(' revision %s\n' % v[1])
  1025         ui.write(' revision %s\n' % v[1])
       
  1026 
       
  1027 def debugdag(ui, repo, file_=None, *revs, **opts):
       
  1028     """format the changelog or an index DAG as a concise textual description
       
  1029 
       
  1030     If you pass a revlog index, the revlog's DAG is emitted. If you list
       
  1031     revision numbers, they get labelled in the output as rN.
       
  1032 
       
  1033     Otherwise, the changelog DAG of the current repo is emitted.
       
  1034     """
       
  1035     spaces = opts.get('spaces')
       
  1036     dots = opts.get('dots')
       
  1037     if file_:
       
  1038         rlog = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
       
  1039         revs = set((int(r) for r in revs))
       
  1040         def events():
       
  1041             for r in rlog:
       
  1042                 yield 'n', (r, list(set(p for p in rlog.parentrevs(r) if p != -1)))
       
  1043                 if r in revs:
       
  1044                     yield 'l', (r, "r%i" % r)
       
  1045     elif repo:
       
  1046         cl = repo.changelog
       
  1047         tags = opts.get('tags')
       
  1048         branches = opts.get('branches')
       
  1049         if tags:
       
  1050             labels = {}
       
  1051             for l, n in repo.tags().items():
       
  1052                 labels.setdefault(cl.rev(n), []).append(l)
       
  1053         def events():
       
  1054             b = "default"
       
  1055             for r in cl:
       
  1056                 if branches:
       
  1057                     newb = cl.read(cl.node(r))[5]['branch']
       
  1058                     if newb != b:
       
  1059                         yield 'a', newb
       
  1060                         b = newb
       
  1061                 yield 'n', (r, list(set(p for p in cl.parentrevs(r) if p != -1)))
       
  1062                 if tags:
       
  1063                     ls = labels.get(r)
       
  1064                     if ls:
       
  1065                         for l in ls:
       
  1066                             yield 'l', (r, l)
       
  1067     else:
       
  1068         raise util.Abort(_('need repo for changelog dag'))
       
  1069 
       
  1070     for line in dagparser.dagtextlines(events(),
       
  1071                                        addspaces=spaces,
       
  1072                                        wraplabels=True,
       
  1073                                        wrapannotations=True,
       
  1074                                        wrapnonlinear=dots,
       
  1075                                        usedots=dots,
       
  1076                                        maxlinewidth=70):
       
  1077         ui.write(line)
       
  1078         ui.write("\n")
  1025 
  1079 
  1026 def debugdata(ui, file_, rev):
  1080 def debugdata(ui, file_, rev):
  1027     """dump the contents of a data file revision"""
  1081     """dump the contents of a data file revision"""
  1028     r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
  1082     r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
  1029     try:
  1083     try:
  3873     "debugcommands": (debugcommands, [], _('[COMMAND]')),
  3927     "debugcommands": (debugcommands, [], _('[COMMAND]')),
  3874     "debugcomplete":
  3928     "debugcomplete":
  3875         (debugcomplete,
  3929         (debugcomplete,
  3876          [('o', 'options', None, _('show the command options'))],
  3930          [('o', 'options', None, _('show the command options'))],
  3877          _('[-o] CMD')),
  3931          _('[-o] CMD')),
       
  3932     "debugdag":
       
  3933         (debugdag,
       
  3934          [('t', 'tags', None, _('use tags as labels')),
       
  3935           ('b', 'branches', None, _('annotate with branch names')),
       
  3936           ('', 'dots', None, _('use dots for runs')),
       
  3937           ('s', 'spaces', None, _('separate elements by spaces')),
       
  3938          ],
       
  3939          _('[OPTION]... [FILE [REV]...]')),
  3878     "debugdate":
  3940     "debugdate":
  3879         (debugdate,
  3941         (debugdate,
  3880          [('e', 'extended', None, _('try extended date formats'))],
  3942          [('e', 'extended', None, _('try extended date formats'))],
  3881          _('[-e] DATE [RANGE]')),
  3943          _('[-e] DATE [RANGE]')),
  3882     "debugdata": (debugdata, [], _('FILE REV')),
  3944     "debugdata": (debugdata, [], _('FILE REV')),
  4231     "version": (version_, []),
  4293     "version": (version_, []),
  4232 }
  4294 }
  4233 
  4295 
  4234 norepo = ("clone init version help debugcommands debugcomplete debugdata"
  4296 norepo = ("clone init version help debugcommands debugcomplete debugdata"
  4235           " debugindex debugindexdot debugdate debuginstall debugfsinfo")
  4297           " debugindex debugindexdot debugdate debuginstall debugfsinfo")
  4236 optionalrepo = ("identify paths serve showconfig debugancestor")
  4298 optionalrepo = ("identify paths serve showconfig debugancestor debugdag")