mercurial/commands.py
changeset 4965 4106dde15aed
parent 4961 126f527b3ba3
parent 4938 02b127749dc0
child 4967 cf67b5f3743d
equal deleted inserted replaced
4964:ee983d0dbea8 4965:4106dde15aed
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 import demandimport; demandimport.enable()
     8 import demandimport; demandimport.enable()
     9 from node import *
     9 from node import *
    10 from i18n import _
    10 from i18n import _
    11 import bisect, os, re, sys, urllib, shlex, stat
    11 import bisect, os, re, sys, urllib, stat
    12 import ui, hg, util, revlog, bundlerepo, extensions
    12 import ui, hg, util, revlog, bundlerepo, extensions
    13 import difflib, patch, time, help, mdiff, tempfile
    13 import difflib, patch, time, help, mdiff, tempfile
    14 import errno, version, socket
    14 import errno, version, socket
    15 import archival, changegroup, cmdutil, hgweb.server, sshserver
    15 import archival, changegroup, cmdutil, hgweb.server, sshserver
    16 
    16 
  1360             if i[1]:
  1360             if i[1]:
  1361                 option_lists.append((_("options:\n"), i[1]))
  1361                 option_lists.append((_("options:\n"), i[1]))
  1362 
  1362 
  1363             addglobalopts(False)
  1363             addglobalopts(False)
  1364 
  1364 
  1365     def helplist(select=None):
  1365     def helplist(header, select=None):
  1366         h = {}
  1366         h = {}
  1367         cmds = {}
  1367         cmds = {}
  1368         for c, e in table.items():
  1368         for c, e in table.items():
  1369             f = c.split("|", 1)[0]
  1369             f = c.split("|", 1)[0]
  1370             if select and not select(f):
  1370             if select and not select(f):
  1378             if not doc:
  1378             if not doc:
  1379                 doc = _("(No help text available)")
  1379                 doc = _("(No help text available)")
  1380             h[f] = doc.splitlines(0)[0].rstrip()
  1380             h[f] = doc.splitlines(0)[0].rstrip()
  1381             cmds[f] = c.lstrip("^")
  1381             cmds[f] = c.lstrip("^")
  1382 
  1382 
       
  1383         if not h:
       
  1384             ui.status(_('no commands defined\n'))
       
  1385             return
       
  1386 
       
  1387         ui.status(header)
  1383         fns = h.keys()
  1388         fns = h.keys()
  1384         fns.sort()
  1389         fns.sort()
  1385         m = max(map(len, fns))
  1390         m = max(map(len, fns))
  1386         for f in fns:
  1391         for f in fns:
  1387             if ui.verbose:
  1392             if ui.verbose:
  1427         ui.status('\n')
  1432         ui.status('\n')
  1428 
  1433 
  1429         try:
  1434         try:
  1430             ct = mod.cmdtable
  1435             ct = mod.cmdtable
  1431         except AttributeError:
  1436         except AttributeError:
  1432             ct = None
  1437             ct = {}
  1433         if not ct:
  1438 
  1434             ui.status(_('no commands defined\n'))
       
  1435             return
       
  1436 
       
  1437         ui.status(_('list of commands:\n\n'))
       
  1438         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct])
  1439         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct])
  1439         helplist(modcmds.has_key)
  1440         helplist(_('list of commands:\n\n'), modcmds.has_key)
  1440 
  1441 
  1441     if name and name != 'shortlist':
  1442     if name and name != 'shortlist':
  1442         i = None
  1443         i = None
  1443         for f in (helpcmd, helptopic, helpext):
  1444         for f in (helpcmd, helptopic, helpext):
  1444             try:
  1445             try:
  1458             ui.status(_("Mercurial Distributed SCM\n"))
  1459             ui.status(_("Mercurial Distributed SCM\n"))
  1459         ui.status('\n')
  1460         ui.status('\n')
  1460 
  1461 
  1461         # list of commands
  1462         # list of commands
  1462         if name == "shortlist":
  1463         if name == "shortlist":
  1463             ui.status(_('basic commands:\n\n'))
  1464             header = _('basic commands:\n\n')
  1464         else:
  1465         else:
  1465             ui.status(_('list of commands:\n\n'))
  1466             header = _('list of commands:\n\n')
  1466 
  1467 
  1467         helplist()
  1468         helplist(header)
  1468 
  1469 
  1469     # list all option lists
  1470     # list all option lists
  1470     opt_output = []
  1471     opt_output = []
  1471     for title, options in option_lists:
  1472     for title, options in option_lists:
  1472         opt_output.append(("\n%s" % title, None))
  1473         opt_output.append(("\n%s" % title, None))
  2038         return 1
  2039         return 1
  2039     else:
  2040     else:
  2040         for name, path in ui.configitems("paths"):
  2041         for name, path in ui.configitems("paths"):
  2041             ui.write("%s = %s\n" % (name, path))
  2042             ui.write("%s = %s\n" % (name, path))
  2042 
  2043 
  2043 def postincoming(ui, repo, modheads, optupdate, wasempty):
  2044 def postincoming(ui, repo, modheads, optupdate):
  2044     if modheads == 0:
  2045     if modheads == 0:
  2045         return
  2046         return
  2046     if optupdate:
  2047     if optupdate:
  2047         if wasempty:
  2048         if modheads == 1:
  2048             return hg.update(repo, repo.lookup('default'))
  2049             return hg.update(repo, None)
  2049         elif modheads == 1:
       
  2050             return hg.update(repo, repo.changelog.tip()) # update
       
  2051         else:
  2050         else:
  2052             ui.status(_("not updating, since new heads added\n"))
  2051             ui.status(_("not updating, since new heads added\n"))
  2053     if modheads > 1:
  2052     if modheads > 1:
  2054         ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
  2053         ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
  2055     else:
  2054     else:
  2106             revs = [other.lookup(rev) for rev in revs]
  2105             revs = [other.lookup(rev) for rev in revs]
  2107         else:
  2106         else:
  2108             error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
  2107             error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
  2109             raise util.Abort(error)
  2108             raise util.Abort(error)
  2110 
  2109 
  2111     wasempty = repo.changelog.count() == 0
       
  2112     modheads = repo.pull(other, heads=revs, force=opts['force'])
  2110     modheads = repo.pull(other, heads=revs, force=opts['force'])
  2113     return postincoming(ui, repo, modheads, opts['update'], wasempty)
  2111     return postincoming(ui, repo, modheads, opts['update'])
  2114 
  2112 
  2115 def push(ui, repo, dest=None, **opts):
  2113 def push(ui, repo, dest=None, **opts):
  2116     """push changes to the specified destination
  2114     """push changes to the specified destination
  2117 
  2115 
  2118     Push changes from the local repository to the given destination.
  2116     Push changes from the local repository to the given destination.
  2209     To undo a remove before that, see hg revert.
  2207     To undo a remove before that, see hg revert.
  2210 
  2208 
  2211     Modified files and added files are not removed by default.  To
  2209     Modified files and added files are not removed by default.  To
  2212     remove them, use the -f/--force option.
  2210     remove them, use the -f/--force option.
  2213     """
  2211     """
  2214     names = []
       
  2215     if not opts['after'] and not pats:
  2212     if not opts['after'] and not pats:
  2216         raise util.Abort(_('no files specified'))
  2213         raise util.Abort(_('no files specified'))
  2217     files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
  2214     files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
  2218     exact = dict.fromkeys(files)
  2215     exact = dict.fromkeys(files)
  2219     mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5]
  2216     mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5]
  2679 
  2676 
  2680     Apply one or more compressed changegroup files generated by the
  2677     Apply one or more compressed changegroup files generated by the
  2681     bundle command.
  2678     bundle command.
  2682     """
  2679     """
  2683     fnames = (fname1,) + fnames
  2680     fnames = (fname1,) + fnames
  2684     result = None
       
  2685     wasempty = repo.changelog.count() == 0
       
  2686     for fname in fnames:
  2681     for fname in fnames:
  2687         if os.path.exists(fname):
  2682         if os.path.exists(fname):
  2688             f = open(fname, "rb")
  2683             f = open(fname, "rb")
  2689         else:
  2684         else:
  2690             f = urllib.urlopen(fname)
  2685             f = urllib.urlopen(fname)
  2691         gen = changegroup.readbundle(f, fname)
  2686         gen = changegroup.readbundle(f, fname)
  2692         modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
  2687         modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
  2693 
  2688 
  2694     return postincoming(ui, repo, modheads, opts['update'], wasempty)
  2689     return postincoming(ui, repo, modheads, opts['update'])
  2695 
  2690 
  2696 def update(ui, repo, node=None, rev=None, clean=False, date=None):
  2691 def update(ui, repo, node=None, rev=None, clean=False, date=None):
  2697     """update working directory
  2692     """update working directory
  2698 
  2693 
  2699     Update the working directory to the specified revision, or the
  2694     Update the working directory to the specified revision, or the