mercurial/commands.py
changeset 437 5b38a5af4019
parent 429 688d03d6997a
child 443 470a83212dda
equal deleted inserted replaced
436:6aeb4fee51f6 437:5b38a5af4019
   176             f = e[0]
   176             f = e[0]
   177             if f.__name__.startswith("debug"): continue
   177             if f.__name__.startswith("debug"): continue
   178             d = ""
   178             d = ""
   179             if f.__doc__:
   179             if f.__doc__:
   180                 d = f.__doc__.splitlines(0)[0].rstrip()
   180                 d = f.__doc__.splitlines(0)[0].rstrip()
   181             h[f.__name__] = d
   181             h[f.__name__.rstrip("_")] = d
   182 
   182 
   183         fns = h.keys()
   183         fns = h.keys()
   184         fns.sort()
   184         fns.sort()
   185         m = max(map(len, fns))
   185         m = max(map(len, fns))
   186         for f in fns:
   186         for f in fns:
   273 
   273 
   274 def copy(ui, repo, source, dest):
   274 def copy(ui, repo, source, dest):
   275     """mark a file as copied or renamed for the next commit"""
   275     """mark a file as copied or renamed for the next commit"""
   276     return repo.copy(*relpath(repo, (source, dest)))
   276     return repo.copy(*relpath(repo, (source, dest)))
   277 
   277 
   278 def debugaddchangegroup(ui, repo):
       
   279     data = sys.stdin.read()
       
   280     repo.addchangegroup(data)
       
   281 
       
   282 def debugchangegroup(ui, repo, roots):
       
   283     newer = repo.newer(map(repo.lookup, roots))
       
   284     for chunk in repo.changegroup(newer):
       
   285         sys.stdout.write(chunk)
       
   286 
       
   287 def debugindex(ui, file):
   278 def debugindex(ui, file):
   288     r = hg.revlog(hg.opener(""), file, "")
   279     r = hg.revlog(hg.opener(""), file, "")
   289     print "   rev    offset  length   base linkrev"+\
   280     print "   rev    offset  length   base linkrev"+\
   290           " p1           p2           nodeid"
   281           " p1           p2           nodeid"
   291     for i in range(r.count()):
   282     for i in range(r.count()):
   371         # tags for multiple parents separated by ' + '
   362         # tags for multiple parents separated by ' + '
   372         output.append(' + '.join(parenttags))
   363         output.append(' + '.join(parenttags))
   373 
   364 
   374     ui.write("%s\n" % ' '.join(output))
   365     ui.write("%s\n" % ' '.join(output))
   375 
   366 
       
   367 def import_(ui, repo, patch1, *patches, **opts):
       
   368     """import an ordered set of patches"""
       
   369     try:
       
   370         import psyco
       
   371         psyco.full()
       
   372     except:
       
   373         pass
       
   374 
       
   375     patches = (patch1,) + patches
       
   376     
       
   377     d = opts["base"]
       
   378     strip = opts["strip"]
       
   379     quiet = ui.quiet and "> /dev/null" or ""
       
   380 
       
   381     for patch in patches:
       
   382         ui.status("applying %s\n" % patch)
       
   383         pf = os.path.join(d, patch)
       
   384 
       
   385         text = ""
       
   386         for l in file(pf):
       
   387             if l[:4] == "--- ": break
       
   388             text += l
       
   389 
       
   390         # make sure text isn't empty
       
   391         if not text: text = "imported patch %s\n" % patch
       
   392 
       
   393         f = os.popen("patch -p%d < %s" % (strip, pf))
       
   394         files = []
       
   395         for l in f.read().splitlines():
       
   396             l.rstrip('\r\n');
       
   397             if not quiet:
       
   398                 print l
       
   399             if l[:14] == 'patching file ':
       
   400                 files.append(l[14:])
       
   401         f.close()
       
   402 
       
   403         if len(files) > 0:
       
   404             addremove(ui, repo, *files)
       
   405         repo.commit(files, text)
       
   406 
   376 def init(ui, source=None, **opts):
   407 def init(ui, source=None, **opts):
   377     """create a new repository or copy an existing one"""
   408     """create a new repository or copy an existing one"""
   378 
   409 
   379     if source:
   410     if source:
   380         paths = {}
   411         paths = {}
   442         p = repo.dirstate.parents()
   473         p = repo.dirstate.parents()
   443 
   474 
   444     for n in p:
   475     for n in p:
   445         if n != hg.nullid:
   476         if n != hg.nullid:
   446             show_changeset(ui, repo, changenode=n)
   477             show_changeset(ui, repo, changenode=n)
   447 
       
   448 def patch(ui, repo, patch1, *patches, **opts):
       
   449     """import an ordered set of patches"""
       
   450     try:
       
   451         import psyco
       
   452         psyco.full()
       
   453     except:
       
   454         pass
       
   455 
       
   456     patches = (patch1,) + patches
       
   457     
       
   458     d = opts["base"]
       
   459     strip = opts["strip"]
       
   460     quiet = opts["quiet"] and "> /dev/null" or ""
       
   461 
       
   462     for patch in patches:
       
   463         ui.status("applying %s\n" % patch)
       
   464         pf = os.path.join(d, patch)
       
   465 
       
   466         text = ""
       
   467         for l in file(pf):
       
   468             if l[:4] == "--- ": break
       
   469             text += l
       
   470 
       
   471         # make sure text isn't empty
       
   472         if not text: text = "imported patch %s\n" % patch
       
   473 
       
   474         f = os.popen("patch -p%d < %s" % (strip, pf))
       
   475         files = []
       
   476         for l in f.read().splitlines():
       
   477             l.rstrip('\r\n');
       
   478             if not quiet:
       
   479                 print l
       
   480             if l[:14] == 'patching file ':
       
   481                 files.append(l[14:])
       
   482         f.close()
       
   483 
       
   484         if len(files) > 0:
       
   485             addremove(ui, repo, *files)
       
   486         repo.commit(files, text)
       
   487 
   478 
   488 def pull(ui, repo, source="default", **opts):
   479 def pull(ui, repo, source="default", **opts):
   489     """pull changes from the specified source"""
   480     """pull changes from the specified source"""
   490     paths = {}
   481     paths = {}
   491     for name, path in ui.configitems("paths"):
   482     for name, path in ui.configitems("paths"):
   662 # Command options and aliases are listed here, alphabetically
   653 # Command options and aliases are listed here, alphabetically
   663 
   654 
   664 table = {
   655 table = {
   665     "add": (add, [], "hg add [files]"),
   656     "add": (add, [], "hg add [files]"),
   666     "addremove": (addremove, [], "hg addremove [files]"),
   657     "addremove": (addremove, [], "hg addremove [files]"),
   667     "ann|annotate": (annotate,
   658     "annotate": (annotate,
   668                      [('r', 'revision', '', 'revision'),
   659                      [('r', 'revision', '', 'revision'),
   669                       ('u', 'user', None, 'show user'),
   660                       ('u', 'user', None, 'show user'),
   670                       ('n', 'number', None, 'show revision number'),
   661                       ('n', 'number', None, 'show revision number'),
   671                       ('c', 'changeset', None, 'show changeset')],
   662                       ('c', 'changeset', None, 'show changeset')],
   672                      'hg annotate [-u] [-c] [-n] [-r id] [files]'),
   663                      'hg annotate [-u] [-c] [-n] [-r id] [files]'),
   673     "cat|dump": (cat, [], 'hg cat <file> [rev]'),
   664     "cat": (cat, [], 'hg cat <file> [rev]'),
   674     "commit|ci": (commit,
   665     "commit|ci": (commit,
   675                   [('t', 'text', "", 'commit text'),
   666                   [('t', 'text', "", 'commit text'),
   676                    ('A', 'addremove', None, 'run add/remove during commit'),
   667                    ('A', 'addremove', None, 'run add/remove during commit'),
   677                    ('l', 'logfile', "", 'commit text file'),
   668                    ('l', 'logfile', "", 'commit text file'),
   678                    ('d', 'date', "", 'data'),
   669                    ('d', 'date', "", 'data'),
   679                    ('u', 'user', "", 'user')],
   670                    ('u', 'user', "", 'user')],
   680                   'hg commit [files]'),
   671                   'hg commit [files]'),
   681     "copy": (copy, [], 'hg copy <source> <dest>'),
   672     "copy": (copy, [], 'hg copy <source> <dest>'),
   682     "debugaddchangegroup": (debugaddchangegroup, [], 'debugaddchangegroup'),
       
   683     "debugchangegroup": (debugchangegroup, [], 'debugchangegroup [roots]'),
       
   684     "debugindex": (debugindex, [], 'debugindex <file>'),
   673     "debugindex": (debugindex, [], 'debugindex <file>'),
   685     "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'),
   674     "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'),
   686     "diff": (diff, [('r', 'rev', [], 'revision')],
   675     "diff": (diff, [('r', 'rev', [], 'revision')],
   687              'hg diff [-r A] [-r B] [files]'),
   676              'hg diff [-r A] [-r B] [files]'),
   688     "export": (export, [], "hg export <changeset>"),
   677     "export": (export, [], "hg export <changeset>"),
   689     "forget": (forget, [], "hg forget [files]"),
   678     "forget": (forget, [], "hg forget [files]"),
   690     "heads": (heads, [], 'hg heads'),
   679     "heads": (heads, [], 'hg heads'),
   691     "history": (history, [], 'hg history'),
   680     "history": (history, [], 'hg history'),
   692     "help": (help, [], 'hg help [command]'),
   681     "help": (help, [], 'hg help [command]'),
   693     "identify|id": (identify, [], 'hg identify'),
   682     "identify|id": (identify, [], 'hg identify'),
       
   683     "import|patch": (import_,
       
   684                      [('p', 'strip', 1, 'path strip'),
       
   685                       ('b', 'base', "", 'base path')],
       
   686                      "hg import [options] <patches>"),
   694     "init": (init, [('u', 'update', None, 'update after init')],
   687     "init": (init, [('u', 'update', None, 'update after init')],
   695              'hg init [options] [url]'),
   688              'hg init [options] [url]'),
   696     "log": (log, [], 'hg log <file>'),
   689     "log": (log, [], 'hg log <file>'),
   697     "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
   690     "manifest": (manifest, [], 'hg manifest [rev]'),
   698     "parents": (parents, [], 'hg parents [node]'),
   691     "parents": (parents, [], 'hg parents [node]'),
   699     "patch|import": (patch,
   692     "pull": (pull, 
   700                      [('p', 'strip', 1, 'path strip'),
       
   701                       ('b', 'base', "", 'base path'),
       
   702                       ('q', 'quiet', "", 'silence diff')],
       
   703                      "hg import [options] patches"),
       
   704     "pull|merge": (pull, 
       
   705                   [('u', 'update', None, 'update working directory')],
   693                   [('u', 'update', None, 'update working directory')],
   706 		  'hg pull [options] [source]'),
   694 		  'hg pull [options] [source]'),
   707     "push": (push, [], 'hg push <destination>'),
   695     "push": (push, [], 'hg push <destination>'),
   708     "rawcommit": (rawcommit,
   696     "rawcommit": (rawcommit,
   709                   [('p', 'parent', [], 'parent'),
   697                   [('p', 'parent', [], 'parent'),
   712                    ('F', 'files', "", 'file list'),
   700                    ('F', 'files', "", 'file list'),
   713                    ('t', 'text', "", 'commit text'),
   701                    ('t', 'text', "", 'commit text'),
   714                    ('l', 'logfile', "", 'commit text file')],
   702                    ('l', 'logfile', "", 'commit text file')],
   715                   'hg rawcommit [options] [files]'),
   703                   'hg rawcommit [options] [files]'),
   716     "recover": (recover, [], "hg recover"),
   704     "recover": (recover, [], "hg recover"),
   717     "remove": (remove, [], "hg remove [files]"),
   705     "remove|rm": (remove, [], "hg remove [files]"),
   718     "serve": (serve, [('p', 'port', 8000, 'listen port'),
   706     "serve": (serve, [('p', 'port', 8000, 'listen port'),
   719                       ('a', 'address', '', 'interface address'),
   707                       ('a', 'address', '', 'interface address'),
   720                       ('n', 'name', os.getcwd(), 'repository name'),
   708                       ('n', 'name', os.getcwd(), 'repository name'),
   721                       ('t', 'templates', "", 'template map')],
   709                       ('t', 'templates', "", 'template map')],
   722               "hg serve [options]"),
   710               "hg serve [options]"),
   726                    ('u', 'user', "", 'user')],
   714                    ('u', 'user', "", 'user')],
   727             'hg tag [options] <name> [rev]'),
   715             'hg tag [options] <name> [rev]'),
   728     "tags": (tags, [], 'hg tags'),
   716     "tags": (tags, [], 'hg tags'),
   729     "tip": (tip, [], 'hg tip'),
   717     "tip": (tip, [], 'hg tip'),
   730     "undo": (undo, [], 'hg undo'),
   718     "undo": (undo, [], 'hg undo'),
   731     "update|up|checkout|co|resolve": (update,
   719     "update|up|checkout|co":
   732                                       [('m', 'merge', None,
   720             (update,
   733                                         'allow merging of conflicts'),
   721              [('m', 'merge', None, 'allow merging of conflicts'),
   734                                        ('C', 'clean', None,
   722               ('C', 'clean', None, 'overwrite locally modified files')],
   735                                         'overwrite locally modified files')],
   723              'hg update [options] [node]'),
   736                                        'hg update [options] [node]'),
       
   737     "verify": (verify, [], 'hg verify'),
   724     "verify": (verify, [], 'hg verify'),
   738     }
   725     }
   739 
   726 
   740 norepo = "init version help debugindex debugindexdot"
   727 norepo = "init version help debugindex debugindexdot"
   741 
   728