mercurial/commands.py
changeset 1920 b7cc0f323a4c
parent 1917 7f578969f3f6
parent 1894 4c53aaf2d153
child 1937 3f6be77eda58
child 1940 7ae177a70f54
equal deleted inserted replaced
1919:8f565af14095 1920:b7cc0f323a4c
   274                               pathname),
   274                               pathname),
   275                 mode)
   275                 mode)
   276 
   276 
   277 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
   277 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
   278            changes=None, text=False, opts={}):
   278            changes=None, text=False, opts={}):
       
   279     if not node1:
       
   280         node1 = repo.dirstate.parents()[0]
       
   281     # reading the data for node1 early allows it to play nicely
       
   282     # with repo.changes and the revlog cache.
       
   283     change = repo.changelog.read(node1)
       
   284     mmap = repo.manifest.read(change[0])
       
   285     date1 = util.datestr(change[2])
       
   286 
   279     if not changes:
   287     if not changes:
   280         changes = repo.changes(node1, node2, files, match=match)
   288         changes = repo.changes(node1, node2, files, match=match)
   281     modified, added, removed, deleted, unknown = changes
   289     modified, added, removed, deleted, unknown = changes
   282     if files:
   290     if files:
   283         modified, added, removed = map(lambda x: filterfiles(files, x),
   291         modified, added, removed = map(lambda x: filterfiles(files, x),
   292         date2 = util.datestr(change[2])
   300         date2 = util.datestr(change[2])
   293         def read(f):
   301         def read(f):
   294             return repo.file(f).read(mmap2[f])
   302             return repo.file(f).read(mmap2[f])
   295     else:
   303     else:
   296         date2 = util.datestr()
   304         date2 = util.datestr()
   297         if not node1:
       
   298             node1 = repo.dirstate.parents()[0]
       
   299         def read(f):
   305         def read(f):
   300             return repo.wread(f)
   306             return repo.wread(f)
   301 
   307 
   302     if ui.quiet:
   308     if ui.quiet:
   303         r = None
   309         r = None
   304     else:
   310     else:
   305         hexfunc = ui.verbose and hex or short
   311         hexfunc = ui.verbose and hex or short
   306         r = [hexfunc(node) for node in [node1, node2] if node]
   312         r = [hexfunc(node) for node in [node1, node2] if node]
   307 
       
   308     change = repo.changelog.read(node1)
       
   309     mmap = repo.manifest.read(change[0])
       
   310     date1 = util.datestr(change[2])
       
   311 
   313 
   312     diffopts = ui.diffopts()
   314     diffopts = ui.diffopts()
   313     showfunc = opts.get('show_function') or diffopts['showfunc']
   315     showfunc = opts.get('show_function') or diffopts['showfunc']
   314     ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
   316     ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
   315     for f in modified:
   317     for f in modified:
   791     else:
   793     else:
   792         node = repo.dirstate.parents()[0]
   794         node = repo.dirstate.parents()[0]
   793     change = repo.changelog.read(node)
   795     change = repo.changelog.read(node)
   794     mmap = repo.manifest.read(change[0])
   796     mmap = repo.manifest.read(change[0])
   795 
   797 
   796     for src, abs, rel, exact in walk(repo, pats, opts):
   798     for src, abs, rel, exact in walk(repo, pats, opts, node=node):
   797         if abs not in mmap:
       
   798             ui.warn(_("warning: %s is not in the repository!\n") %
       
   799                     ((pats and rel) or abs))
       
   800             continue
       
   801 
       
   802         f = repo.file(abs)
   799         f = repo.file(abs)
   803         if not opts['text'] and util.binary(f.read(mmap[abs])):
   800         if not opts['text'] and util.binary(f.read(mmap[abs])):
   804             ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
   801             ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
   805             continue
   802             continue
   806 
   803 
   832 
   829 
   833     Unlike import/export, this exactly preserves all changeset
   830     Unlike import/export, this exactly preserves all changeset
   834     contents including permissions, rename data, and revision history.
   831     contents including permissions, rename data, and revision history.
   835     """
   832     """
   836     f = open(fname, "wb")
   833     f = open(fname, "wb")
   837     dest = ui.expandpath(dest, repo.root)
   834     dest = ui.expandpath(dest)
   838     other = hg.repository(ui, dest)
   835     other = hg.repository(ui, dest)
   839     o = repo.findoutgoing(other)
   836     o = repo.findoutgoing(other)
   840     cg = repo.changegroup(o, 'bundle')
   837     cg = repo.changegroup(o, 'bundle')
   841 
   838 
   842     try:
   839     try:
   894     For efficiency, hardlinks are used for cloning whenever the source
   891     For efficiency, hardlinks are used for cloning whenever the source
   895     and destination are on the same filesystem.  Some filesystems,
   892     and destination are on the same filesystem.  Some filesystems,
   896     such as AFS, implement hardlinking incorrectly, but do not report
   893     such as AFS, implement hardlinking incorrectly, but do not report
   897     errors.  In these cases, use the --pull option to avoid
   894     errors.  In these cases, use the --pull option to avoid
   898     hardlinking.
   895     hardlinking.
       
   896 
       
   897     See pull for valid source format details.
   899     """
   898     """
   900     if dest is None:
   899     if dest is None:
   901         dest = os.path.basename(os.path.normpath(source))
   900         dest = os.path.basename(os.path.normpath(source))
   902 
   901 
   903     if os.path.exists(dest):
   902     if os.path.exists(dest):
   919     if opts['ssh']:
   918     if opts['ssh']:
   920         ui.setconfig("ui", "ssh", opts['ssh'])
   919         ui.setconfig("ui", "ssh", opts['ssh'])
   921     if opts['remotecmd']:
   920     if opts['remotecmd']:
   922         ui.setconfig("ui", "remotecmd", opts['remotecmd'])
   921         ui.setconfig("ui", "remotecmd", opts['remotecmd'])
   923 
   922 
   924     if not os.path.exists(source):
   923     source = ui.expandpath(source)
   925         source = ui.expandpath(source)
       
   926 
   924 
   927     d = Dircleanup(dest)
   925     d = Dircleanup(dest)
   928     abspath = source
   926     abspath = source
   929     other = hg.repository(ui, source)
   927     other = hg.repository(ui, source)
   930 
   928 
   976     f.write("[paths]\n")
   974     f.write("[paths]\n")
   977     f.write("default = %s\n" % abspath)
   975     f.write("default = %s\n" % abspath)
   978     f.close()
   976     f.close()
   979 
   977 
   980     if not opts['noupdate']:
   978     if not opts['noupdate']:
   981         update(ui, repo)
   979         update(repo.ui, repo)
   982 
   980 
   983     d.close()
   981     d.close()
   984 
   982 
   985 def commit(ui, repo, *pats, **opts):
   983 def commit(ui, repo, *pats, **opts):
   986     """commit the specified files or all outstanding changes
   984     """commit the specified files or all outstanding changes
  1021     try:
  1019     try:
  1022         repo.commit(files, message, opts['user'], opts['date'], match)
  1020         repo.commit(files, message, opts['user'], opts['date'], match)
  1023     except ValueError, inst:
  1021     except ValueError, inst:
  1024         raise util.Abort(str(inst))
  1022         raise util.Abort(str(inst))
  1025 
  1023 
  1026 def docopy(ui, repo, pats, opts):
  1024 def docopy(ui, repo, pats, opts, wlock):
       
  1025     # called with the repo lock held
  1027     cwd = repo.getcwd()
  1026     cwd = repo.getcwd()
  1028     errors = 0
  1027     errors = 0
  1029     copied = []
  1028     copied = []
  1030     targets = {}
  1029     targets = {}
  1031 
  1030 
  1067         else:
  1066         else:
  1068             targetdir = os.path.dirname(reltarget) or '.'
  1067             targetdir = os.path.dirname(reltarget) or '.'
  1069             if not os.path.isdir(targetdir):
  1068             if not os.path.isdir(targetdir):
  1070                 os.makedirs(targetdir)
  1069                 os.makedirs(targetdir)
  1071             try:
  1070             try:
  1072                 shutil.copyfile(relsrc, reltarget)
  1071                 restore = repo.dirstate.state(abstarget) == 'r'
  1073                 shutil.copymode(relsrc, reltarget)
  1072                 if restore:
       
  1073                     repo.undelete([abstarget], wlock)
       
  1074                 try:
       
  1075                     shutil.copyfile(relsrc, reltarget)
       
  1076                     shutil.copymode(relsrc, reltarget)
       
  1077                     restore = False
       
  1078                 finally:
       
  1079                     if restore:
       
  1080                         repo.remove([abstarget], wlock)
  1074             except shutil.Error, inst:
  1081             except shutil.Error, inst:
  1075                 raise util.Abort(str(inst))
  1082                 raise util.Abort(str(inst))
  1076             except IOError, inst:
  1083             except IOError, inst:
  1077                 if inst.errno == errno.ENOENT:
  1084                 if inst.errno == errno.ENOENT:
  1078                     ui.warn(_('%s: deleted in working copy\n') % relsrc)
  1085                     ui.warn(_('%s: deleted in working copy\n') % relsrc)
  1082                     errors += 1
  1089                     errors += 1
  1083                     return
  1090                     return
  1084         if ui.verbose or not exact:
  1091         if ui.verbose or not exact:
  1085             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
  1092             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
  1086         targets[abstarget] = abssrc
  1093         targets[abstarget] = abssrc
  1087         repo.copy(origsrc, abstarget)
  1094         if abstarget != origsrc:
       
  1095             repo.copy(origsrc, abstarget, wlock)
  1088         copied.append((abssrc, relsrc, exact))
  1096         copied.append((abssrc, relsrc, exact))
  1089 
  1097 
  1090     def targetpathfn(pat, dest, srcs):
  1098     def targetpathfn(pat, dest, srcs):
  1091         if os.path.isdir(pat):
  1099         if os.path.isdir(pat):
  1092             abspfx = util.canonpath(repo.root, cwd, pat)
  1100             abspfx = util.canonpath(repo.root, cwd, pat)
  1190 
  1198 
  1191     NOTE: This command should be treated as experimental. While it
  1199     NOTE: This command should be treated as experimental. While it
  1192     should properly record copied files, this information is not yet
  1200     should properly record copied files, this information is not yet
  1193     fully used by merge, nor fully reported by log.
  1201     fully used by merge, nor fully reported by log.
  1194     """
  1202     """
  1195     errs, copied = docopy(ui, repo, pats, opts)
  1203     try:
       
  1204         wlock = repo.wlock(0)
       
  1205         errs, copied = docopy(ui, repo, pats, opts, wlock)
       
  1206     except lock.LockHeld, inst:
       
  1207         ui.warn(_("repository lock held by %s\n") % inst.args[0])
       
  1208         errs = 1
  1196     return errs
  1209     return errs
  1197 
  1210 
  1198 def debugancestor(ui, index, rev1, rev2):
  1211 def debugancestor(ui, index, rev1, rev2):
  1199     """find the ancestor revision of two revisions in a given index"""
  1212     """find the ancestor revision of two revisions in a given index"""
  1200     r = revlog.revlog(util.opener(os.getcwd()), index, "")
  1213     r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "")
  1201     a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
  1214     a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
  1202     ui.write("%d:%s\n" % (r.rev(a), hex(a)))
  1215     ui.write("%d:%s\n" % (r.rev(a), hex(a)))
       
  1216 
       
  1217 def debugcomplete(ui, cmd):
       
  1218     """returns the completion list associated with the given command"""
       
  1219     clist = findpossible(cmd).keys()
       
  1220     clist.sort()
       
  1221     ui.write("%s\n" % " ".join(clist))
  1203 
  1222 
  1204 def debugrebuildstate(ui, repo, rev=None):
  1223 def debugrebuildstate(ui, repo, rev=None):
  1205     """rebuild the dirstate as it would look like for the given revision"""
  1224     """rebuild the dirstate as it would look like for the given revision"""
  1206     if not rev:
  1225     if not rev:
  1207         rev = repo.changelog.tip()
  1226         rev = repo.changelog.tip()
  1244             errors += 1
  1263             errors += 1
  1245     if errors:
  1264     if errors:
  1246         error = _(".hg/dirstate inconsistent with current parent's manifest")
  1265         error = _(".hg/dirstate inconsistent with current parent's manifest")
  1247         raise util.Abort(error)
  1266         raise util.Abort(error)
  1248 
  1267 
  1249 def debugconfig(ui):
  1268 def debugconfig(ui, repo):
  1250     """show combined config settings from all hgrc files"""
  1269     """show combined config settings from all hgrc files"""
  1251     try:
       
  1252         repo = hg.repository(ui)
       
  1253     except hg.RepoError:
       
  1254         pass
       
  1255     for section, name, value in ui.walkconfig():
  1270     for section, name, value in ui.walkconfig():
  1256         ui.write('%s.%s=%s\n' % (section, name, value))
  1271         ui.write('%s.%s=%s\n' % (section, name, value))
  1257 
  1272 
  1258 def debugsetparents(ui, repo, rev1, rev2=None):
  1273 def debugsetparents(ui, repo, rev1, rev2=None):
  1259     """manually set the parents of the current working directory
  1274     """manually set the parents of the current working directory
  1281     for f in repo.dirstate.copies:
  1296     for f in repo.dirstate.copies:
  1282         ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f))
  1297         ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f))
  1283 
  1298 
  1284 def debugdata(ui, file_, rev):
  1299 def debugdata(ui, file_, rev):
  1285     """dump the contents of an data file revision"""
  1300     """dump the contents of an data file revision"""
  1286     r = revlog.revlog(util.opener(os.getcwd()), file_[:-2] + ".i", file_)
  1301     r = revlog.revlog(util.opener(os.getcwd(), audit=False),
       
  1302                       file_[:-2] + ".i", file_)
  1287     try:
  1303     try:
  1288         ui.write(r.revision(r.lookup(rev)))
  1304         ui.write(r.revision(r.lookup(rev)))
  1289     except KeyError:
  1305     except KeyError:
  1290         raise util.Abort(_('invalid revision identifier %s'), rev)
  1306         raise util.Abort(_('invalid revision identifier %s'), rev)
  1291 
  1307 
  1292 def debugindex(ui, file_):
  1308 def debugindex(ui, file_):
  1293     """dump the contents of an index file"""
  1309     """dump the contents of an index file"""
  1294     r = revlog.revlog(util.opener(os.getcwd()), file_, "")
  1310     r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "")
  1295     ui.write("   rev    offset  length   base linkrev" +
  1311     ui.write("   rev    offset  length   base linkrev" +
  1296              " nodeid       p1           p2\n")
  1312              " nodeid       p1           p2\n")
  1297     for i in range(r.count()):
  1313     for i in range(r.count()):
  1298         e = r.index[i]
  1314         e = r.index[i]
  1299         ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
  1315         ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
  1300                 i, e[0], e[1], e[2], e[3],
  1316                 i, e[0], e[1], e[2], e[3],
  1301             short(e[6]), short(e[4]), short(e[5])))
  1317             short(e[6]), short(e[4]), short(e[5])))
  1302 
  1318 
  1303 def debugindexdot(ui, file_):
  1319 def debugindexdot(ui, file_):
  1304     """dump an index DAG as a .dot file"""
  1320     """dump an index DAG as a .dot file"""
  1305     r = revlog.revlog(util.opener(os.getcwd()), file_, "")
  1321     r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "")
  1306     ui.write("digraph G {\n")
  1322     ui.write("digraph G {\n")
  1307     for i in range(r.count()):
  1323     for i in range(r.count()):
  1308         e = r.index[i]
  1324         e = r.index[i]
  1309         ui.write("\t%d -> %d\n" % (r.rev(e[4]), i))
  1325         ui.write("\t%d -> %d\n" % (r.rev(e[4]), i))
  1310         if e[5] != nullid:
  1326         if e[5] != nullid:
  1728     pull repo. These are the changesets that would be pulled if a pull
  1744     pull repo. These are the changesets that would be pulled if a pull
  1729     was requested.
  1745     was requested.
  1730 
  1746 
  1731     Currently only local repositories are supported.
  1747     Currently only local repositories are supported.
  1732     """
  1748     """
  1733     source = ui.expandpath(source, repo.root)
  1749     source = ui.expandpath(source)
  1734     other = hg.repository(ui, source)
  1750     other = hg.repository(ui, source)
  1735     if not other.local():
  1751     if not other.local():
  1736         raise util.Abort(_("incoming doesn't work for remote repositories yet"))
  1752         raise util.Abort(_("incoming doesn't work for remote repositories yet"))
  1737     o = repo.findincoming(other)
  1753     o = repo.findincoming(other)
  1738     if not o:
  1754     if not o:
  1915     """show changesets not found in destination
  1931     """show changesets not found in destination
  1916 
  1932 
  1917     Show changesets not found in the specified destination repo or the
  1933     Show changesets not found in the specified destination repo or the
  1918     default push repo. These are the changesets that would be pushed
  1934     default push repo. These are the changesets that would be pushed
  1919     if a push was requested.
  1935     if a push was requested.
  1920     """
  1936 
  1921     dest = ui.expandpath(dest, repo.root)
  1937     See pull for valid source format details.
       
  1938     """
       
  1939     dest = ui.expandpath(dest)
  1922     other = hg.repository(ui, dest)
  1940     other = hg.repository(ui, dest)
  1923     o = repo.findoutgoing(other)
  1941     o = repo.findoutgoing(other)
  1924     o = repo.changelog.nodesbetween(o)[0]
  1942     o = repo.changelog.nodesbetween(o)[0]
  1925     if opts['newest_first']:
  1943     if opts['newest_first']:
  1926         o.reverse()
  1944         o.reverse()
  1951     displayer = show_changeset(ui, repo, opts)
  1969     displayer = show_changeset(ui, repo, opts)
  1952     for n in p:
  1970     for n in p:
  1953         if n != nullid:
  1971         if n != nullid:
  1954             displayer.show(changenode=n, brinfo=br)
  1972             displayer.show(changenode=n, brinfo=br)
  1955 
  1973 
  1956 def paths(ui, search=None):
  1974 def paths(ui, repo, search=None):
  1957     """show definition of symbolic path names
  1975     """show definition of symbolic path names
  1958 
  1976 
  1959     Show definition of symbolic path name NAME. If no name is given, show
  1977     Show definition of symbolic path name NAME. If no name is given, show
  1960     definition of available names.
  1978     definition of available names.
  1961 
  1979 
  1962     Path names are defined in the [paths] section of /etc/mercurial/hgrc
  1980     Path names are defined in the [paths] section of /etc/mercurial/hgrc
  1963     and $HOME/.hgrc.  If run inside a repository, .hg/hgrc is used, too.
  1981     and $HOME/.hgrc.  If run inside a repository, .hg/hgrc is used, too.
  1964     """
  1982     """
  1965     try:
       
  1966         repo = hg.repository(ui=ui)
       
  1967     except hg.RepoError:
       
  1968         pass
       
  1969 
       
  1970     if search:
  1983     if search:
  1971         for name, path in ui.configitems("paths"):
  1984         for name, path in ui.configitems("paths"):
  1972             if name == search:
  1985             if name == search:
  1973                 ui.write("%s\n" % path)
  1986                 ui.write("%s\n" % path)
  1974                 return
  1987                 return
  1997     SSH requires an accessible shell account on the destination machine
  2010     SSH requires an accessible shell account on the destination machine
  1998     and a copy of hg in the remote path.  With SSH, paths are relative
  2011     and a copy of hg in the remote path.  With SSH, paths are relative
  1999     to the remote user's home directory by default; use two slashes at
  2012     to the remote user's home directory by default; use two slashes at
  2000     the start of a path to specify it as relative to the filesystem root.
  2013     the start of a path to specify it as relative to the filesystem root.
  2001     """
  2014     """
  2002     source = ui.expandpath(source, repo.root)
  2015     source = ui.expandpath(source)
  2003     ui.status(_('pulling from %s\n') % (source))
  2016     ui.status(_('pulling from %s\n') % (source))
  2004 
  2017 
  2005     if opts['ssh']:
  2018     if opts['ssh']:
  2006         ui.setconfig("ui", "ssh", opts['ssh'])
  2019         ui.setconfig("ui", "ssh", opts['ssh'])
  2007     if opts['remotecmd']:
  2020     if opts['remotecmd']:
  2042       ssh://[user@]host[:port][/path]
  2055       ssh://[user@]host[:port][/path]
  2043 
  2056 
  2044     SSH requires an accessible shell account on the destination
  2057     SSH requires an accessible shell account on the destination
  2045     machine and a copy of hg in the remote path.
  2058     machine and a copy of hg in the remote path.
  2046     """
  2059     """
  2047     dest = ui.expandpath(dest, repo.root)
  2060     dest = ui.expandpath(dest)
  2048     ui.status('pushing to %s\n' % (dest))
  2061     ui.status('pushing to %s\n' % (dest))
  2049 
  2062 
  2050     if opts['ssh']:
  2063     if opts['ssh']:
  2051         ui.setconfig("ui", "ssh", opts['ssh'])
  2064         ui.setconfig("ui", "ssh", opts['ssh'])
  2052     if opts['remotecmd']:
  2065     if opts['remotecmd']:
  2060     return r
  2073     return r
  2061 
  2074 
  2062 def rawcommit(ui, repo, *flist, **rc):
  2075 def rawcommit(ui, repo, *flist, **rc):
  2063     """raw commit interface (DEPRECATED)
  2076     """raw commit interface (DEPRECATED)
  2064 
  2077 
       
  2078     (DEPRECATED)
  2065     Lowlevel commit, for use in helper scripts.
  2079     Lowlevel commit, for use in helper scripts.
  2066 
  2080 
  2067     This command is not intended to be used by normal users, as it is
  2081     This command is not intended to be used by normal users, as it is
  2068     primarily useful for importing from other SCMs.
  2082     primarily useful for importing from other SCMs.
  2069 
  2083 
  2117     """
  2131     """
  2118     names = []
  2132     names = []
  2119     def okaytoremove(abs, rel, exact):
  2133     def okaytoremove(abs, rel, exact):
  2120         modified, added, removed, deleted, unknown = repo.changes(files=[abs])
  2134         modified, added, removed, deleted, unknown = repo.changes(files=[abs])
  2121         reason = None
  2135         reason = None
  2122         if modified:
  2136         if modified and not opts['force']:
  2123             reason = _('is modified')
  2137             reason = _('is modified')
  2124         elif added:
  2138         elif added:
  2125             reason = _('has been marked for add')
  2139             reason = _('has been marked for add')
  2126         elif unknown:
  2140         elif unknown:
  2127             reason = _('is not managed')
  2141             reason = _('is not managed')
  2152 
  2166 
  2153     NOTE: This command should be treated as experimental. While it
  2167     NOTE: This command should be treated as experimental. While it
  2154     should properly record rename files, this information is not yet
  2168     should properly record rename files, this information is not yet
  2155     fully used by merge, nor fully reported by log.
  2169     fully used by merge, nor fully reported by log.
  2156     """
  2170     """
  2157     errs, copied = docopy(ui, repo, pats, opts)
  2171     try:
  2158     names = []
  2172         wlock = repo.wlock(0)
  2159     for abs, rel, exact in copied:
  2173         errs, copied = docopy(ui, repo, pats, opts, wlock)
  2160         if ui.verbose or not exact:
  2174         names = []
  2161             ui.status(_('removing %s\n') % rel)
  2175         for abs, rel, exact in copied:
  2162         names.append(abs)
  2176             if ui.verbose or not exact:
  2163     repo.remove(names, unlink=True)
  2177                 ui.status(_('removing %s\n') % rel)
       
  2178             names.append(abs)
       
  2179         repo.remove(names, True, wlock)
       
  2180     except lock.LockHeld, inst:
       
  2181         ui.warn(_("repository lock held by %s\n") % inst.args[0])
       
  2182         errs = 1
  2164     return errs
  2183     return errs
  2165 
  2184 
  2166 def revert(ui, repo, *pats, **opts):
  2185 def revert(ui, repo, *pats, **opts):
  2167     """revert modified files or dirs back to their unmodified states
  2186     """revert modified files or dirs back to their unmodified states
  2168 
  2187 
  2169     Revert any uncommitted modifications made to the named files or
  2188     In its default mode, it reverts any uncommitted modifications made
  2170     directories.  This restores the contents of the affected files to
  2189     to the named files or directories.  This restores the contents of
  2171     an unmodified state.
  2190     the affected files to an unmodified state.
       
  2191 
       
  2192     Using the -r option, it reverts the given files or directories to
       
  2193     their state as of an earlier revision.  This can be helpful to "roll
       
  2194     back" some or all of a change that should not have been committed.
       
  2195 
       
  2196     Revert modifies the working directory.  It does not commit any
       
  2197     changes, or change the parent of the current working directory.
  2172 
  2198 
  2173     If a file has been deleted, it is recreated.  If the executable
  2199     If a file has been deleted, it is recreated.  If the executable
  2174     mode of a file was changed, it is reset.
  2200     mode of a file was changed, it is reset.
  2175 
  2201 
  2176     If names are given, all files matching the names are reverted.
  2202     If names are given, all files matching the names are reverted.
  2181            repo.dirstate.parents()[0]
  2207            repo.dirstate.parents()[0]
  2182 
  2208 
  2183     files, choose, anypats = matchpats(repo, pats, opts)
  2209     files, choose, anypats = matchpats(repo, pats, opts)
  2184     modified, added, removed, deleted, unknown = repo.changes(match=choose)
  2210     modified, added, removed, deleted, unknown = repo.changes(match=choose)
  2185     repo.forget(added)
  2211     repo.forget(added)
  2186     repo.undelete(removed + deleted)
  2212     repo.undelete(removed)
  2187 
  2213 
  2188     return repo.update(node, False, True, choose, False)
  2214     return repo.update(node, False, True, choose, False)
  2189 
  2215 
  2190 def root(ui, repo):
  2216 def root(ui, repo):
  2191     """print the root (top) of the current working dir
  2217     """print the root (top) of the current working dir
  2571           ('d', 'date', None, _('list the date')),
  2597           ('d', 'date', None, _('list the date')),
  2572           ('n', 'number', None, _('list the revision number (default)')),
  2598           ('n', 'number', None, _('list the revision number (default)')),
  2573           ('c', 'changeset', None, _('list the changeset')),
  2599           ('c', 'changeset', None, _('list the changeset')),
  2574           ('I', 'include', [], _('include names matching the given patterns')),
  2600           ('I', 'include', [], _('include names matching the given patterns')),
  2575           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2601           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2576          _('hg annotate [OPTION]... FILE...')),
  2602          _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
  2577     "bundle":
  2603     "bundle":
  2578         (bundle,
  2604         (bundle,
  2579          [],
  2605          [],
  2580          _('hg bundle FILE DEST')),
  2606          _('hg bundle FILE DEST')),
  2581     "cat":
  2607     "cat":
  2582         (cat,
  2608         (cat,
  2583          [('I', 'include', [], _('include names matching the given patterns')),
  2609          [('o', 'output', '', _('print output to file with formatted name')),
  2584           ('X', 'exclude', [], _('exclude names matching the given patterns')),
  2610           ('r', 'rev', '', _('print the given revision')),
  2585           ('o', 'output', '', _('print output to file with formatted name')),
  2611           ('I', 'include', [], _('include names matching the given patterns')),
  2586           ('r', 'rev', '', _('print the given revision'))],
  2612           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2587          _('hg cat [OPTION]... FILE...')),
  2613          _('hg cat [OPTION]... FILE...')),
  2588     "^clone":
  2614     "^clone":
  2589         (clone,
  2615         (clone,
  2590          [('U', 'noupdate', None, _('do not update the new working directory')),
  2616          [('U', 'noupdate', None, _('do not update the new working directory')),
  2591           ('e', 'ssh', '', _('specify ssh command to use')),
       
  2592           ('', 'pull', None, _('use pull protocol to copy metadata')),
       
  2593           ('r', 'rev', [],
  2617           ('r', 'rev', [],
  2594            _('a changeset you would like to have after cloning')),
  2618            _('a changeset you would like to have after cloning')),
       
  2619           ('', 'pull', None, _('use pull protocol to copy metadata')),
       
  2620           ('e', 'ssh', '', _('specify ssh command to use')),
  2595           ('', 'remotecmd', '',
  2621           ('', 'remotecmd', '',
  2596            _('specify hg command to run on the remote side'))],
  2622            _('specify hg command to run on the remote side'))],
  2597          _('hg clone [OPTION]... SOURCE [DEST]')),
  2623          _('hg clone [OPTION]... SOURCE [DEST]')),
  2598     "^commit|ci":
  2624     "^commit|ci":
  2599         (commit,
  2625         (commit,
  2600          [('A', 'addremove', None, _('run addremove during commit')),
  2626          [('A', 'addremove', None, _('run addremove during commit')),
  2601           ('I', 'include', [], _('include names matching the given patterns')),
       
  2602           ('X', 'exclude', [], _('exclude names matching the given patterns')),
       
  2603           ('m', 'message', '', _('use <text> as commit message')),
  2627           ('m', 'message', '', _('use <text> as commit message')),
  2604           ('l', 'logfile', '', _('read the commit message from <file>')),
  2628           ('l', 'logfile', '', _('read the commit message from <file>')),
  2605           ('d', 'date', '', _('record datecode as commit date')),
  2629           ('d', 'date', '', _('record datecode as commit date')),
  2606           ('u', 'user', '', _('record user as commiter'))],
  2630           ('u', 'user', '', _('record user as commiter')),
       
  2631           ('I', 'include', [], _('include names matching the given patterns')),
       
  2632           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2607          _('hg commit [OPTION]... [FILE]...')),
  2633          _('hg commit [OPTION]... [FILE]...')),
  2608     "copy|cp":
  2634     "copy|cp":
  2609         (copy,
  2635         (copy,
  2610          [('I', 'include', [], _('include names matching the given patterns')),
  2636          [('A', 'after', None, _('record a copy that has already occurred')),
  2611           ('X', 'exclude', [], _('exclude names matching the given patterns')),
       
  2612           ('A', 'after', None, _('record a copy that has already occurred')),
       
  2613           ('f', 'force', None,
  2637           ('f', 'force', None,
  2614            _('forcibly copy over an existing managed file'))],
  2638            _('forcibly copy over an existing managed file')),
       
  2639           ('I', 'include', [], _('include names matching the given patterns')),
       
  2640           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2615          _('hg copy [OPTION]... [SOURCE]... DEST')),
  2641          _('hg copy [OPTION]... [SOURCE]... DEST')),
  2616     "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
  2642     "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
       
  2643     "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')),
  2617     "debugrebuildstate":
  2644     "debugrebuildstate":
  2618         (debugrebuildstate,
  2645         (debugrebuildstate,
  2619          [('r', 'rev', "", _("revision to rebuild to"))],
  2646          [('r', 'rev', '', _('revision to rebuild to'))],
  2620          _('debugrebuildstate [-r REV] [REV]')),
  2647          _('debugrebuildstate [-r REV] [REV]')),
  2621     "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
  2648     "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
  2622     "debugconfig": (debugconfig, [], _('debugconfig')),
  2649     "debugconfig": (debugconfig, [], _('debugconfig')),
  2623     "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
  2650     "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
  2624     "debugstate": (debugstate, [], _('debugstate')),
  2651     "debugstate": (debugstate, [], _('debugstate')),
  2633          _('debugwalk [OPTION]... [FILE]...')),
  2660          _('debugwalk [OPTION]... [FILE]...')),
  2634     "^diff":
  2661     "^diff":
  2635         (diff,
  2662         (diff,
  2636          [('r', 'rev', [], _('revision')),
  2663          [('r', 'rev', [], _('revision')),
  2637           ('a', 'text', None, _('treat all files as text')),
  2664           ('a', 'text', None, _('treat all files as text')),
  2638           ('I', 'include', [], _('include names matching the given patterns')),
       
  2639           ('p', 'show-function', None,
  2665           ('p', 'show-function', None,
  2640            _('show which function each change is in')),
  2666            _('show which function each change is in')),
  2641           ('w', 'ignore-all-space', None,
  2667           ('w', 'ignore-all-space', None,
  2642            _('ignore white space when comparing lines')),
  2668            _('ignore white space when comparing lines')),
  2643           ('X', 'exclude', [],
  2669           ('I', 'include', [], _('include names matching the given patterns')),
  2644            _('exclude names matching the given patterns'))],
  2670           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2645          _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
  2671          _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
  2646     "^export":
  2672     "^export":
  2647         (export,
  2673         (export,
  2648          [('o', 'output', '', _('print output to file with formatted name')),
  2674          [('o', 'output', '', _('print output to file with formatted name')),
  2649           ('a', 'text', None, _('treat all files as text')),
  2675           ('a', 'text', None, _('treat all files as text')),
  2650           ('', 'switch-parent', None, _('diff against the second parent'))],
  2676           ('', 'switch-parent', None, _('diff against the second parent'))],
  2651          _('hg export [-a] [-o OUTFILE] REV...')),
  2677          _('hg export [-a] [-o OUTFILESPEC] REV...')),
  2652     "forget":
  2678     "forget":
  2653         (forget,
  2679         (forget,
  2654          [('I', 'include', [], _('include names matching the given patterns')),
  2680          [('I', 'include', [], _('include names matching the given patterns')),
  2655           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2681           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2656          _('hg forget [OPTION]... FILE...')),
  2682          _('hg forget [OPTION]... FILE...')),
  2657     "grep":
  2683     "grep":
  2658         (grep,
  2684         (grep,
  2659          [('0', 'print0', None, _('end fields with NUL')),
  2685          [('0', 'print0', None, _('end fields with NUL')),
  2660           ('I', 'include', [], _('include names matching the given patterns')),
       
  2661           ('X', 'exclude', [], _('exclude names matching the given patterns')),
       
  2662           ('', 'all', None, _('print all revisions that match')),
  2686           ('', 'all', None, _('print all revisions that match')),
  2663           ('i', 'ignore-case', None, _('ignore case when matching')),
  2687           ('i', 'ignore-case', None, _('ignore case when matching')),
  2664           ('l', 'files-with-matches', None,
  2688           ('l', 'files-with-matches', None,
  2665            _('print only filenames and revs that match')),
  2689            _('print only filenames and revs that match')),
  2666           ('n', 'line-number', None, _('print matching line numbers')),
  2690           ('n', 'line-number', None, _('print matching line numbers')),
  2667           ('r', 'rev', [], _('search in given revision range')),
  2691           ('r', 'rev', [], _('search in given revision range')),
  2668           ('u', 'user', None, _('print user who committed change'))],
  2692           ('u', 'user', None, _('print user who committed change')),
       
  2693           ('I', 'include', [], _('include names matching the given patterns')),
       
  2694           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2669          _('hg grep [OPTION]... PATTERN [FILE]...')),
  2695          _('hg grep [OPTION]... PATTERN [FILE]...')),
  2670     "heads":
  2696     "heads":
  2671         (heads,
  2697         (heads,
  2672          [('b', 'branches', None, _('show branches')),
  2698          [('b', 'branches', None, _('show branches')),
  2673           ('', 'style', '', _('display using template map file')),
  2699           ('', 'style', '', _('display using template map file')),
  2679     "import|patch":
  2705     "import|patch":
  2680         (import_,
  2706         (import_,
  2681          [('p', 'strip', 1,
  2707          [('p', 'strip', 1,
  2682            _('directory strip option for patch. This has the same\n') +
  2708            _('directory strip option for patch. This has the same\n') +
  2683            _('meaning as the corresponding patch option')),
  2709            _('meaning as the corresponding patch option')),
       
  2710           ('b', 'base', '', _('base path')),
  2684           ('f', 'force', None,
  2711           ('f', 'force', None,
  2685            _('skip check for outstanding uncommitted changes')),
  2712            _('skip check for outstanding uncommitted changes'))],
  2686           ('b', 'base', '', _('base path'))],
  2713          _('hg import [-p NUM] [-b BASE] [-f] PATCH...')),
  2687          _('hg import [-f] [-p NUM] [-b BASE] PATCH...')),
       
  2688     "incoming|in": (incoming,
  2714     "incoming|in": (incoming,
  2689          [('M', 'no-merges', None, _('do not show merges')),
  2715          [('M', 'no-merges', None, _('do not show merges')),
  2690           ('', 'style', '', _('display using template map file')),
  2716           ('', 'style', '', _('display using template map file')),
  2691           ('n', 'newest-first', None, _('show newest record first')),
  2717           ('n', 'newest-first', None, _('show newest record first')),
  2692           ('p', 'patch', None, _('show patch')),
  2718           ('p', 'patch', None, _('show patch')),
  2703           ('I', 'include', [], _('include names matching the given patterns')),
  2729           ('I', 'include', [], _('include names matching the given patterns')),
  2704           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2730           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2705          _('hg locate [OPTION]... [PATTERN]...')),
  2731          _('hg locate [OPTION]... [PATTERN]...')),
  2706     "^log|history":
  2732     "^log|history":
  2707         (log,
  2733         (log,
  2708          [('I', 'include', [], _('include names matching the given patterns')),
  2734          [('b', 'branches', None, _('show branches')),
  2709           ('X', 'exclude', [], _('exclude names matching the given patterns')),
       
  2710           ('b', 'branches', None, _('show branches')),
       
  2711           ('k', 'keyword', [], _('search for a keyword')),
  2735           ('k', 'keyword', [], _('search for a keyword')),
  2712           ('l', 'limit', '', _('limit number of changes displayed')),
  2736           ('l', 'limit', '', _('limit number of changes displayed')),
  2713           ('r', 'rev', [], _('show the specified revision or range')),
  2737           ('r', 'rev', [], _('show the specified revision or range')),
  2714           ('M', 'no-merges', None, _('do not show merges')),
  2738           ('M', 'no-merges', None, _('do not show merges')),
  2715           ('', 'style', '', _('display using template map file')),
  2739           ('', 'style', '', _('display using template map file')),
  2716           ('m', 'only-merges', None, _('show only merges')),
  2740           ('m', 'only-merges', None, _('show only merges')),
  2717           ('p', 'patch', None, _('show patch')),
  2741           ('p', 'patch', None, _('show patch')),
  2718           ('', 'template', '', _('display with template'))],
  2742           ('', 'template', '', _('display with template')),
  2719          _('hg log [-I] [-X] [-r REV]... [-p] [FILE]')),
  2743           ('I', 'include', [], _('include names matching the given patterns')),
       
  2744           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
       
  2745          _('hg log [OPTION]... [FILE]')),
  2720     "manifest": (manifest, [], _('hg manifest [REV]')),
  2746     "manifest": (manifest, [], _('hg manifest [REV]')),
  2721     "outgoing|out": (outgoing,
  2747     "outgoing|out": (outgoing,
  2722          [('M', 'no-merges', None, _('do not show merges')),
  2748          [('M', 'no-merges', None, _('do not show merges')),
  2723           ('p', 'patch', None, _('show patch')),
  2749           ('p', 'patch', None, _('show patch')),
  2724           ('', 'style', '', _('display using template map file')),
  2750           ('', 'style', '', _('display using template map file')),
  2725           ('n', 'newest-first', None, _('show newest record first')),
  2751           ('n', 'newest-first', None, _('show newest record first')),
  2726           ('', 'template', '', _('display with template'))],
  2752           ('', 'template', '', _('display with template'))],
  2727          _('hg outgoing [-p] [-n] [-M] [DEST]')),
  2753          _('hg outgoing [-M] [-p] [-n] [DEST]')),
  2728     "^parents":
  2754     "^parents":
  2729         (parents,
  2755         (parents,
  2730          [('b', 'branches', None, _('show branches')),
  2756          [('b', 'branches', None, _('show branches')),
  2731           ('', 'style', '', _('display using template map file')),
  2757           ('', 'style', '', _('display using template map file')),
  2732           ('', 'template', '', _('display with template'))],
  2758           ('', 'template', '', _('display with template'))],
  2738            _('update the working directory to tip after pull')),
  2764            _('update the working directory to tip after pull')),
  2739           ('e', 'ssh', '', _('specify ssh command to use')),
  2765           ('e', 'ssh', '', _('specify ssh command to use')),
  2740           ('r', 'rev', [], _('a specific revision you would like to pull')),
  2766           ('r', 'rev', [], _('a specific revision you would like to pull')),
  2741           ('', 'remotecmd', '',
  2767           ('', 'remotecmd', '',
  2742            _('specify hg command to run on the remote side'))],
  2768            _('specify hg command to run on the remote side'))],
  2743          _('hg pull [-u] [-e FILE] [-r rev]... [--remotecmd FILE] [SOURCE]')),
  2769          _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')),
  2744     "^push":
  2770     "^push":
  2745         (push,
  2771         (push,
  2746          [('f', 'force', None, _('force push')),
  2772          [('f', 'force', None, _('force push')),
  2747           ('e', 'ssh', '', _('specify ssh command to use')),
  2773           ('e', 'ssh', '', _('specify ssh command to use')),
  2748           ('r', 'rev', [], _('a specific revision you would like to push')),
  2774           ('r', 'rev', [], _('a specific revision you would like to push')),
  2749           ('', 'remotecmd', '',
  2775           ('', 'remotecmd', '',
  2750            _('specify hg command to run on the remote side'))],
  2776            _('specify hg command to run on the remote side'))],
  2751          _('hg push [-f] [-e FILE] [-r rev]... [--remotecmd FILE] [DEST]')),
  2777          _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')),
  2752     "rawcommit":
  2778     "debugrawcommit|rawcommit":
  2753         (rawcommit,
  2779         (rawcommit,
  2754          [('p', 'parent', [], _('parent')),
  2780          [('p', 'parent', [], _('parent')),
  2755           ('d', 'date', '', _('date code')),
  2781           ('d', 'date', '', _('date code')),
  2756           ('u', 'user', '', _('user')),
  2782           ('u', 'user', '', _('user')),
  2757           ('F', 'files', '', _('file list')),
  2783           ('F', 'files', '', _('file list')),
  2758           ('m', 'message', '', _('commit message')),
  2784           ('m', 'message', '', _('commit message')),
  2759           ('l', 'logfile', '', _('commit message file'))],
  2785           ('l', 'logfile', '', _('commit message file'))],
  2760          _('hg rawcommit [OPTION]... [FILE]...')),
  2786          _('hg debugrawcommit [OPTION]... [FILE]...')),
  2761     "recover": (recover, [], _('hg recover')),
  2787     "recover": (recover, [], _('hg recover')),
  2762     "^remove|rm":
  2788     "^remove|rm":
  2763         (remove,
  2789         (remove,
  2764          [('I', 'include', [], _('include names matching the given patterns')),
  2790          [('f', 'force', None, _('remove file even if modified')),
       
  2791           ('I', 'include', [], _('include names matching the given patterns')),
  2765           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2792           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2766          _('hg remove [OPTION]... FILE...')),
  2793          _('hg remove [OPTION]... FILE...')),
  2767     "rename|mv":
  2794     "rename|mv":
  2768         (rename,
  2795         (rename,
  2769          [('I', 'include', [], _('include names matching the given patterns')),
  2796          [('A', 'after', None, _('record a rename that has already occurred')),
  2770           ('X', 'exclude', [], _('exclude names matching the given patterns')),
       
  2771           ('A', 'after', None, _('record a rename that has already occurred')),
       
  2772           ('f', 'force', None,
  2797           ('f', 'force', None,
  2773            _('forcibly copy over an existing managed file'))],
  2798            _('forcibly copy over an existing managed file')),
  2774          _('hg rename [OPTION]... [SOURCE]... DEST')),
  2799           ('I', 'include', [], _('include names matching the given patterns')),
       
  2800           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
       
  2801          _('hg rename [OPTION]... SOURCE... DEST')),
  2775     "^revert":
  2802     "^revert":
  2776         (revert,
  2803         (revert,
  2777          [('I', 'include', [], _('include names matching the given patterns')),
  2804          [('r', 'rev', '', _('revision to revert to')),
  2778           ('X', 'exclude', [], _('exclude names matching the given patterns')),
  2805           ('I', 'include', [], _('include names matching the given patterns')),
  2779           ('r', 'rev', '', _('revision to revert to'))],
  2806           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2780          _('hg revert [-n] [-r REV] [NAME]...')),
  2807          _('hg revert [-r REV] [NAME]...')),
  2781     "root": (root, [], _('hg root')),
  2808     "root": (root, [], _('hg root')),
  2782     "^serve":
  2809     "^serve":
  2783         (serve,
  2810         (serve,
  2784          [('A', 'accesslog', '', _('name of access log file to write to')),
  2811          [('A', 'accesslog', '', _('name of access log file to write to')),
  2785           ('d', 'daemon', None, _('run server in background')),
  2812           ('d', 'daemon', None, _('run server in background')),
  2789           ('a', 'address', '', _('address to use')),
  2816           ('a', 'address', '', _('address to use')),
  2790           ('n', 'name', '',
  2817           ('n', 'name', '',
  2791            _('name to show in web pages (default: working dir)')),
  2818            _('name to show in web pages (default: working dir)')),
  2792           ('', 'pid-file', '', _('name of file to write process ID to')),
  2819           ('', 'pid-file', '', _('name of file to write process ID to')),
  2793           ('', 'stdio', None, _('for remote clients')),
  2820           ('', 'stdio', None, _('for remote clients')),
  2794           ('', 'templates', '', _('web templates to use')),
  2821           ('t', 'templates', '', _('web templates to use')),
  2795           ('', 'style', '', _('template style to use')),
  2822           ('', 'style', '', _('template style to use')),
  2796           ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
  2823           ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
  2797          _('hg serve [OPTION]...')),
  2824          _('hg serve [OPTION]...')),
  2798     "^status|st":
  2825     "^status|st":
  2799         (status,
  2826         (status,
  2813          [('l', 'local', None, _('make the tag local')),
  2840          [('l', 'local', None, _('make the tag local')),
  2814           ('m', 'message', '', _('message for tag commit log entry')),
  2841           ('m', 'message', '', _('message for tag commit log entry')),
  2815           ('d', 'date', '', _('record datecode as commit date')),
  2842           ('d', 'date', '', _('record datecode as commit date')),
  2816           ('u', 'user', '', _('record user as commiter')),
  2843           ('u', 'user', '', _('record user as commiter')),
  2817           ('r', 'rev', '', _('revision to tag'))],
  2844           ('r', 'rev', '', _('revision to tag'))],
  2818          _('hg tag [-r REV] [OPTION]... NAME')),
  2845          _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')),
  2819     "tags": (tags, [], _('hg tags')),
  2846     "tags": (tags, [], _('hg tags')),
  2820     "tip":
  2847     "tip":
  2821         (tip,
  2848         (tip,
  2822          [('b', 'branches', None, _('show branches')),
  2849          [('b', 'branches', None, _('show branches')),
  2823           ('', 'style', '', _('display using template map file')),
  2850           ('', 'style', '', _('display using template map file')),
  2824           ('p', 'patch', None, _('show patch')),
  2851           ('p', 'patch', None, _('show patch')),
  2825           ('', 'template', '', _('display with template'))],
  2852           ('', 'template', '', _('display with template'))],
  2826          _('hg [-b] [-p] tip')),
  2853          _('hg tip [-b] [-p]')),
  2827     "unbundle":
  2854     "unbundle":
  2828         (unbundle,
  2855         (unbundle,
  2829          [('u', 'update', None,
  2856          [('u', 'update', None,
  2830            _('update the working directory to tip after unbundle'))],
  2857            _('update the working directory to tip after unbundle'))],
  2831          _('hg unbundle [-u] FILE')),
  2858          _('hg unbundle [-u] FILE')),
  2842     "verify": (verify, [], _('hg verify')),
  2869     "verify": (verify, [], _('hg verify')),
  2843     "version": (show_version, [], _('hg version')),
  2870     "version": (show_version, [], _('hg version')),
  2844 }
  2871 }
  2845 
  2872 
  2846 globalopts = [
  2873 globalopts = [
  2847     ('R', 'repository', '', _('repository root directory')),
  2874     ('R', 'repository', '',
       
  2875      _('repository root directory or symbolic path name')),
  2848     ('', 'cwd', '', _('change working directory')),
  2876     ('', 'cwd', '', _('change working directory')),
  2849     ('y', 'noninteractive', None,
  2877     ('y', 'noninteractive', None,
  2850      _('do not prompt, assume \'yes\' for any required answers')),
  2878      _('do not prompt, assume \'yes\' for any required answers')),
  2851     ('q', 'quiet', None, _('suppress output')),
  2879     ('q', 'quiet', None, _('suppress output')),
  2852     ('v', 'verbose', None, _('enable additional output')),
  2880     ('v', 'verbose', None, _('enable additional output')),
  2857     ('', 'profile', None, _('print command execution profile')),
  2885     ('', 'profile', None, _('print command execution profile')),
  2858     ('', 'version', None, _('output version information and exit')),
  2886     ('', 'version', None, _('output version information and exit')),
  2859     ('h', 'help', None, _('display help and exit')),
  2887     ('h', 'help', None, _('display help and exit')),
  2860 ]
  2888 ]
  2861 
  2889 
  2862 norepo = ("clone init version help debugancestor debugconfig debugdata"
  2890 norepo = ("clone init version help debugancestor debugcomplete debugdata"
  2863           " debugindex debugindexdot paths")
  2891           " debugindex debugindexdot")
  2864 
  2892 optionalrepo = ("paths debugconfig")
  2865 def find(cmd):
  2893 
  2866     """Return (aliases, command table entry) for command string."""
  2894 def findpossible(cmd):
  2867     choice = None
  2895     """
  2868     count = 0
  2896     Return cmd -> (aliases, command table entry)
       
  2897     for each matching command
       
  2898     """
       
  2899     choice = {}
       
  2900     debugchoice = {}
  2869     for e in table.keys():
  2901     for e in table.keys():
  2870         aliases = e.lstrip("^").split("|")
  2902         aliases = e.lstrip("^").split("|")
  2871         if cmd in aliases:
  2903         if cmd in aliases:
  2872             return aliases, table[e]
  2904             choice[cmd] = (aliases, table[e])
       
  2905             continue
  2873         for a in aliases:
  2906         for a in aliases:
  2874             if a.startswith(cmd):
  2907             if a.startswith(cmd):
  2875                 count += 1
  2908                 if aliases[0].startswith("debug"):
  2876                 choice = aliases, table[e]
  2909                     debugchoice[a] = (aliases, table[e])
       
  2910                 else:
       
  2911                     choice[a] = (aliases, table[e])
  2877                 break
  2912                 break
  2878 
  2913 
  2879     if count > 1:
  2914     if not choice and debugchoice:
  2880         raise AmbiguousCommand(cmd)
  2915         choice = debugchoice
       
  2916 
       
  2917     return choice
       
  2918 
       
  2919 def find(cmd):
       
  2920     """Return (aliases, command table entry) for command string."""
       
  2921     choice = findpossible(cmd)
       
  2922 
       
  2923     if choice.has_key(cmd):
       
  2924         return choice[cmd]
       
  2925 
       
  2926     if len(choice) > 1:
       
  2927         clist = choice.keys()
       
  2928         clist.sort()
       
  2929         raise AmbiguousCommand(cmd, clist)
  2881 
  2930 
  2882     if choice:
  2931     if choice:
  2883         return choice
  2932         return choice.values()[0]
  2884 
  2933 
  2885     raise UnknownCommand(cmd)
  2934     raise UnknownCommand(cmd)
  2886 
  2935 
  2887 class SignalInterrupt(Exception):
  2936 class SignalInterrupt(Exception):
  2888     """Exception raised on SIGTERM and SIGHUP."""
  2937     """Exception raised on SIGTERM and SIGHUP."""
  2966                 components = name.split('.')
  3015                 components = name.split('.')
  2967                 for comp in components[1:]:
  3016                 for comp in components[1:]:
  2968                     mod = getattr(mod, comp)
  3017                     mod = getattr(mod, comp)
  2969                 return mod
  3018                 return mod
  2970             try:
  3019             try:
  2971                 mod = importh(x[0])
  3020                 try:
       
  3021                     mod = importh("hgext." + x[0])
       
  3022                 except ImportError:
       
  3023                     mod = importh(x[0])
  2972             except Exception, inst:
  3024             except Exception, inst:
  2973                 on_exception(Exception, inst)
  3025                 on_exception(Exception, inst)
  2974                 continue
  3026                 continue
  2975 
  3027 
  2976         external.append(mod)
  3028         external.append(mod)
  2981                 u.warn(_("module %s overrides %s\n") % (x.__name__, t))
  3033                 u.warn(_("module %s overrides %s\n") % (x.__name__, t))
  2982         table.update(cmdtable)
  3034         table.update(cmdtable)
  2983 
  3035 
  2984     try:
  3036     try:
  2985         cmd, func, args, options, cmdoptions = parse(u, args)
  3037         cmd, func, args, options, cmdoptions = parse(u, args)
       
  3038         if options["time"]:
       
  3039             def get_times():
       
  3040                 t = os.times()
       
  3041                 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
       
  3042                     t = (t[0], t[1], t[2], t[3], time.clock())
       
  3043                 return t
       
  3044             s = get_times()
       
  3045             def print_time():
       
  3046                 t = get_times()
       
  3047                 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
       
  3048                     (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
       
  3049             atexit.register(print_time)
       
  3050 
       
  3051         u.updateopts(options["verbose"], options["debug"], options["quiet"],
       
  3052                 not options["noninteractive"])
       
  3053 
       
  3054         # enter the debugger before command execution
       
  3055         if options['debugger']:
       
  3056             pdb.set_trace()
       
  3057 
       
  3058         try:
       
  3059             if options['cwd']:
       
  3060                 try:
       
  3061                     os.chdir(options['cwd'])
       
  3062                 except OSError, inst:
       
  3063                     raise util.Abort('%s: %s' %
       
  3064                                      (options['cwd'], inst.strerror))
       
  3065 
       
  3066             path = u.expandpath(options["repository"]) or ""
       
  3067             repo = path and hg.repository(u, path=path) or None
       
  3068 
       
  3069             if options['help']:
       
  3070                 help_(u, cmd, options['version'])
       
  3071                 sys.exit(0)
       
  3072             elif options['version']:
       
  3073                 show_version(u)
       
  3074                 sys.exit(0)
       
  3075             elif not cmd:
       
  3076                 help_(u, 'shortlist')
       
  3077                 sys.exit(0)
       
  3078 
       
  3079             if cmd not in norepo.split():
       
  3080                 try:
       
  3081                     if not repo:
       
  3082                         repo = hg.repository(u, path=path)
       
  3083                     u = repo.ui
       
  3084                     for x in external:
       
  3085                         if hasattr(x, 'reposetup'):
       
  3086                             x.reposetup(u, repo)
       
  3087                 except hg.RepoError:
       
  3088                     if cmd not in optionalrepo.split():
       
  3089                         raise
       
  3090                 d = lambda: func(u, repo, *args, **cmdoptions)
       
  3091             else:
       
  3092                 d = lambda: func(u, *args, **cmdoptions)
       
  3093 
       
  3094             try:
       
  3095                 if options['profile']:
       
  3096                     import hotshot, hotshot.stats
       
  3097                     prof = hotshot.Profile("hg.prof")
       
  3098                     try:
       
  3099                         try:
       
  3100                             return prof.runcall(d)
       
  3101                         except:
       
  3102                             try:
       
  3103                                 u.warn(_('exception raised - generating '
       
  3104                                          'profile anyway\n'))
       
  3105                             except:
       
  3106                                 pass
       
  3107                             raise
       
  3108                     finally:
       
  3109                         prof.close()
       
  3110                         stats = hotshot.stats.load("hg.prof")
       
  3111                         stats.strip_dirs()
       
  3112                         stats.sort_stats('time', 'calls')
       
  3113                         stats.print_stats(40)
       
  3114                 else:
       
  3115                     return d()
       
  3116             finally:
       
  3117                 u.flush()
       
  3118         except:
       
  3119             # enter the debugger when we hit an exception
       
  3120             if options['debugger']:
       
  3121                 pdb.post_mortem(sys.exc_info()[2])
       
  3122             if options['traceback']:
       
  3123                 traceback.print_exc()
       
  3124             raise
  2986     except ParseError, inst:
  3125     except ParseError, inst:
  2987         if inst.args[0]:
  3126         if inst.args[0]:
  2988             u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
  3127             u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
  2989             help_(u, inst.args[0])
  3128             help_(u, inst.args[0])
  2990         else:
  3129         else:
  2991             u.warn(_("hg: %s\n") % inst.args[1])
  3130             u.warn(_("hg: %s\n") % inst.args[1])
  2992             help_(u, 'shortlist')
  3131             help_(u, 'shortlist')
  2993         sys.exit(-1)
  3132         sys.exit(-1)
  2994     except AmbiguousCommand, inst:
  3133     except AmbiguousCommand, inst:
  2995         u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
  3134         u.warn(_("hg: command '%s' is ambiguous:\n    %s\n") %
       
  3135                 (inst.args[0], " ".join(inst.args[1])))
  2996         sys.exit(1)
  3136         sys.exit(1)
  2997     except UnknownCommand, inst:
  3137     except UnknownCommand, inst:
  2998         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
  3138         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
  2999         help_(u, 'shortlist')
  3139         help_(u, 'shortlist')
  3000         sys.exit(1)
  3140         sys.exit(1)
  3001 
       
  3002     if options["time"]:
       
  3003         def get_times():
       
  3004             t = os.times()
       
  3005             if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
       
  3006                 t = (t[0], t[1], t[2], t[3], time.clock())
       
  3007             return t
       
  3008         s = get_times()
       
  3009         def print_time():
       
  3010             t = get_times()
       
  3011             u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
       
  3012                 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
       
  3013         atexit.register(print_time)
       
  3014 
       
  3015     u.updateopts(options["verbose"], options["debug"], options["quiet"],
       
  3016               not options["noninteractive"])
       
  3017 
       
  3018     # enter the debugger before command execution
       
  3019     if options['debugger']:
       
  3020         pdb.set_trace()
       
  3021 
       
  3022     try:
       
  3023         try:
       
  3024             if options['help']:
       
  3025                 help_(u, cmd, options['version'])
       
  3026                 sys.exit(0)
       
  3027             elif options['version']:
       
  3028                 show_version(u)
       
  3029                 sys.exit(0)
       
  3030             elif not cmd:
       
  3031                 help_(u, 'shortlist')
       
  3032                 sys.exit(0)
       
  3033 
       
  3034             if options['cwd']:
       
  3035                 try:
       
  3036                     os.chdir(options['cwd'])
       
  3037                 except OSError, inst:
       
  3038                     raise util.Abort('%s: %s' %
       
  3039                                      (options['cwd'], inst.strerror))
       
  3040 
       
  3041             if cmd not in norepo.split():
       
  3042                 path = options["repository"] or ""
       
  3043                 repo = hg.repository(ui=u, path=path)
       
  3044                 for x in external:
       
  3045                     if hasattr(x, 'reposetup'):
       
  3046                         x.reposetup(u, repo)
       
  3047                 d = lambda: func(u, repo, *args, **cmdoptions)
       
  3048             else:
       
  3049                 d = lambda: func(u, *args, **cmdoptions)
       
  3050 
       
  3051             if options['profile']:
       
  3052                 import hotshot, hotshot.stats
       
  3053                 prof = hotshot.Profile("hg.prof")
       
  3054                 r = prof.runcall(d)
       
  3055                 prof.close()
       
  3056                 stats = hotshot.stats.load("hg.prof")
       
  3057                 stats.strip_dirs()
       
  3058                 stats.sort_stats('time', 'calls')
       
  3059                 stats.print_stats(40)
       
  3060                 return r
       
  3061             else:
       
  3062                 return d()
       
  3063         except:
       
  3064             # enter the debugger when we hit an exception
       
  3065             if options['debugger']:
       
  3066                 pdb.post_mortem(sys.exc_info()[2])
       
  3067             if options['traceback']:
       
  3068                 traceback.print_exc()
       
  3069             raise
       
  3070     except hg.RepoError, inst:
  3141     except hg.RepoError, inst:
  3071         u.warn(_("abort: "), inst, "!\n")
  3142         u.warn(_("abort: "), inst, "!\n")
  3072     except revlog.RevlogError, inst:
  3143     except revlog.RevlogError, inst:
  3073         u.warn(_("abort: "), inst, "!\n")
  3144         u.warn(_("abort: "), inst, "!\n")
  3074     except SignalInterrupt:
  3145     except SignalInterrupt:
  3111         if len(tb) > 2: # no
  3182         if len(tb) > 2: # no
  3112             raise
  3183             raise
  3113         u.debug(inst, "\n")
  3184         u.debug(inst, "\n")
  3114         u.warn(_("%s: invalid arguments\n") % cmd)
  3185         u.warn(_("%s: invalid arguments\n") % cmd)
  3115         help_(u, cmd)
  3186         help_(u, cmd)
  3116     except AmbiguousCommand, inst:
       
  3117         u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
       
  3118         help_(u, 'shortlist')
       
  3119     except UnknownCommand, inst:
       
  3120         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
       
  3121         help_(u, 'shortlist')
       
  3122     except SystemExit:
  3187     except SystemExit:
  3123         # don't catch this in the catch-all below
  3188         # don't catch this in the catch-all below
  3124         raise
  3189         raise
  3125     except:
  3190     except:
  3126         u.warn(_("** unknown exception encountered, details follow\n"))
  3191         u.warn(_("** unknown exception encountered, details follow\n"))