mercurial/commands.py
changeset 339 a76fc9c4b67b
parent 338 1e091b3293d5
child 340 97a897d32dfc
equal deleted inserted replaced
338:1e091b3293d5 339:a76fc9c4b67b
   124             ui.status("\n")
   124             ui.status("\n")
   125         else:
   125         else:
   126             ui.status("summary:     %s\n" % description[0])
   126             ui.status("summary:     %s\n" % description[0])
   127     ui.status("\n")
   127     ui.status("\n")
   128 
   128 
       
   129 def tags_load(repo):
       
   130     repo.lookup(0) # prime the cache
       
   131     i = repo.tags.items()
       
   132     n = []
       
   133     for e in i:
       
   134         try:
       
   135             l = repo.changelog.rev(e[1])
       
   136         except KeyError:
       
   137             l = -2
       
   138         n.append((l, e))
       
   139     return n
       
   140 
   129 def help(ui, cmd=None):
   141 def help(ui, cmd=None):
   130     '''show help for a given command or all commands'''
   142     '''show help for a given command or all commands'''
   131     if cmd:
   143     if cmd:
   132         try:
   144         try:
   133             i = find(cmd)
   145             i = find(cmd)
   310 def history(ui, repo):
   322 def history(ui, repo):
   311     """show the changelog history"""
   323     """show the changelog history"""
   312     for i in range(repo.changelog.count() - 1, -1, -1):
   324     for i in range(repo.changelog.count() - 1, -1, -1):
   313         show_changeset(ui, repo, rev=i)
   325         show_changeset(ui, repo, rev=i)
   314 
   326 
       
   327 def identify(ui, repo):
       
   328     """print information about the working copy"""
       
   329     (c, a, d, u) = repo.diffdir(repo.root)
       
   330     mflag = (c or a or d or u) and "+" or ""
       
   331     parents = [parent for parent in repo.dirstate.parents()
       
   332                       if parent != hg.nullid]
       
   333     tstring = ''
       
   334     if not ui.quiet:
       
   335         taglist = [e[1] for e in tags_load(repo)]
       
   336         tstring = " %s" % ' + '.join([e[0] for e in taglist
       
   337                                       if e[0] != 'tip' and e[1] in parents])
       
   338 
       
   339     hexfunc = ui.verbose and hg.hex or hg.short
       
   340     pstring = '+'.join([hexfunc(parent) for parent in parents])
       
   341     ui.write("%s%s%s\n" % (pstring, mflag, tstring))
       
   342 
   315 def init(ui, source=None):
   343 def init(ui, source=None):
   316     """create a new repository or copy an existing one"""
   344     """create a new repository or copy an existing one"""
   317 
   345 
   318     if source:
   346     if source:
   319         paths = {}
   347         paths = {}
   510     for f in d: print "R", f
   538     for f in d: print "R", f
   511     for f in u: print "?", f
   539     for f in u: print "?", f
   512 
   540 
   513 def tags(ui, repo):
   541 def tags(ui, repo):
   514     """list repository tags"""
   542     """list repository tags"""
   515     repo.lookup(0) # prime the cache
   543     n = tags_load(repo)
   516     i = repo.tags.items()
       
   517     n = []
       
   518     for e in i:
       
   519         try:
       
   520             l = repo.changelog.rev(e[1])
       
   521         except KeyError:
       
   522             l = -2
       
   523         n.append((l, e))
       
   524 
   544 
   525     n.sort()
   545     n.sort()
   526     n.reverse()
   546     n.reverse()
   527     i = [ e[1] for e in n ]
   547     i = [ e[1] for e in n ]
   528     for k, n in i:
   548     for k, n in i:
   588     "export": (export, [], "hg export <changeset>"),
   608     "export": (export, [], "hg export <changeset>"),
   589     "forget": (forget, [], "hg forget [files]"),
   609     "forget": (forget, [], "hg forget [files]"),
   590     "heads": (heads, [], 'hg heads'),
   610     "heads": (heads, [], 'hg heads'),
   591     "history": (history, [], 'hg history'),
   611     "history": (history, [], 'hg history'),
   592     "help": (help, [], 'hg help [command]'),
   612     "help": (help, [], 'hg help [command]'),
       
   613     "identify|id": (identify, [], 'hg identify'),
   593     "init": (init, [], 'hg init [url]'),
   614     "init": (init, [], 'hg init [url]'),
   594     "log": (log, [], 'hg log <file>'),
   615     "log": (log, [], 'hg log <file>'),
   595     "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
   616     "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
   596     "parents": (parents, [], 'hg parents [node]'),
   617     "parents": (parents, [], 'hg parents [node]'),
   597     "patch|import": (patch,
   618     "patch|import": (patch,