mercurial/commands.py
changeset 793 445970ccf57a
parent 791 040655ea0cc4
parent 783 4b06fc1c0f26
child 808 8f5637f0a0c0
equal deleted inserted replaced
792:49ec802b4a16 793:445970ccf57a
     7 
     7 
     8 from demandload import demandload
     8 from demandload import demandload
     9 demandload(globals(), "os re sys signal shutil")
     9 demandload(globals(), "os re sys signal shutil")
    10 demandload(globals(), "fancyopts ui hg util")
    10 demandload(globals(), "fancyopts ui hg util")
    11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
    11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
    12 demandload(globals(), "errno socket version struct")
    12 demandload(globals(), "errno socket version struct atexit")
    13 
    13 
    14 class UnknownCommand(Exception):
    14 class UnknownCommand(Exception):
    15     """Exception raised if command is not in the command table."""
    15     """Exception raised if command is not in the command table."""
    16 
    16 
    17 class Abort(Exception):
    17 class Abort(Exception):
   215         ui.write("%d:%s\n" % (rev, hg.hex(node)))
   215         ui.write("%d:%s\n" % (rev, hg.hex(node)))
   216         return
   216         return
   217 
   217 
   218     changes = changelog.read(changenode)
   218     changes = changelog.read(changenode)
   219 
   219 
   220     parents = [(log.rev(parent), hg.hex(parent))
   220     parents = [(log.rev(p), ui.verbose and hg.hex(p) or hg.short(p))
   221                for parent in log.parents(node)
   221                for p in log.parents(node)
   222                if ui.debugflag or parent != hg.nullid]
   222                if ui.debugflag or p != hg.nullid]
   223     if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1:
   223     if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1:
   224         parents = []
   224         parents = []
   225 
   225 
   226     ui.write("changeset:   %d:%s\n" % (changerev, hg.hex(changenode)))
   226     if ui.verbose:
       
   227         ui.write("changeset:   %d:%s\n" % (changerev, hg.hex(changenode)))
       
   228     else:
       
   229         ui.write("changeset:   %d:%s\n" % (changerev, hg.short(changenode)))
       
   230 
   227     for tag in repo.nodetags(changenode):
   231     for tag in repo.nodetags(changenode):
   228         ui.status("tag:         %s\n" % tag)
   232         ui.status("tag:         %s\n" % tag)
   229     for parent in parents:
   233     for parent in parents:
   230         ui.write("parent:      %d:%s\n" % parent)
   234         ui.write("parent:      %d:%s\n" % parent)
   231     if filelog:
   235     if filelog:
   232         ui.debug("file rev:    %d:%s\n" % (filerev, hg.hex(filenode)))
   236         ui.debug("file rev:    %d:%s\n" % (filerev, hg.hex(filenode)))
   233     ui.note("manifest:    %d:%s\n" % (repo.manifest.rev(changes[0]),
   237 
       
   238     ui.debug("manifest:    %d:%s\n" % (repo.manifest.rev(changes[0]),
   234                                       hg.hex(changes[0])))
   239                                       hg.hex(changes[0])))
   235     ui.status("user:        %s\n" % changes[1])
   240     ui.status("user:        %s\n" % changes[1])
   236     ui.status("date:        %s\n" % time.asctime(
   241     ui.status("date:        %s\n" % time.asctime(
   237         time.localtime(float(changes[2].split(' ')[0]))))
   242         time.localtime(float(changes[2].split(' ')[0]))))
       
   243 
   238     if ui.debugflag:
   244     if ui.debugflag:
   239         files = repo.changes(changelog.parents(changenode)[0], changenode)
   245         files = repo.changes(changelog.parents(changenode)[0], changenode)
   240         for key, value in zip(["files:", "files+:", "files-:"], files):
   246         for key, value in zip(["files:", "files+:", "files-:"], files):
   241             if value:
   247             if value:
   242                 ui.note("%-12s %s\n" % (key, " ".join(value)))
   248                 ui.note("%-12s %s\n" % (key, " ".join(value)))
   243     else:
   249     else:
   244         ui.note("files:       %s\n" % " ".join(changes[3]))
   250         ui.note("files:       %s\n" % " ".join(changes[3]))
       
   251 
   245     description = changes[4].strip()
   252     description = changes[4].strip()
   246     if description:
   253     if description:
   247         if ui.verbose:
   254         if ui.verbose:
   248             ui.status("description:\n")
   255             ui.status("description:\n")
   249             ui.status(description)
   256             ui.status(description)
   377     else:
   384     else:
   378         node = repo.dirstate.parents()[0]
   385         node = repo.dirstate.parents()[0]
   379     change = repo.changelog.read(node)
   386     change = repo.changelog.read(node)
   380     mmap = repo.manifest.read(change[0])
   387     mmap = repo.manifest.read(change[0])
   381     for src, abs, rel in walk(repo, pats, opts):
   388     for src, abs, rel in walk(repo, pats, opts):
       
   389         if abs not in mmap:
       
   390             ui.warn("warning: %s is not in the repository!\n" % rel)
       
   391             continue
       
   392 
   382         lines = repo.file(abs).annotate(mmap[abs])
   393         lines = repo.file(abs).annotate(mmap[abs])
   383         pieces = []
   394         pieces = []
   384 
   395 
   385         for o, f in opmap:
   396         for o, f in opmap:
   386             if opts[o]:
   397             if opts[o]:
   387                 l = [f(n) for n, dummy in lines]
   398                 l = [f(n) for n, dummy in lines]
   388                 m = max(map(len, l))
   399                 if l:
   389                 pieces.append(["%*s" % (m, x) for x in l])
   400                     m = max(map(len, l))
   390 
   401                     pieces.append(["%*s" % (m, x) for x in l])
   391         for p, l in zip(zip(*pieces), lines):
   402 
   392             ui.write("%s: %s" % (" ".join(p), l[1]))
   403         if pieces:
       
   404             for p, l in zip(zip(*pieces), lines):
       
   405                 ui.write("%s: %s" % (" ".join(p), l[1]))
   393 
   406 
   394 def cat(ui, repo, file1, rev=None, **opts):
   407 def cat(ui, repo, file1, rev=None, **opts):
   395     """output the latest or given revision of a file"""
   408     """output the latest or given revision of a file"""
   396     r = repo.file(relpath(repo, [file1])[0])
   409     r = repo.file(relpath(repo, [file1])[0])
   397     if rev:
   410     if rev:
   764         p = repo.dirstate.parents()
   777         p = repo.dirstate.parents()
   765 
   778 
   766     for n in p:
   779     for n in p:
   767         if n != hg.nullid:
   780         if n != hg.nullid:
   768             show_changeset(ui, repo, changenode=n)
   781             show_changeset(ui, repo, changenode=n)
       
   782 
       
   783 def paths(ui, repo, search = None):
       
   784     """show path or list of available paths"""
       
   785     if search:
       
   786         for name, path in ui.configitems("paths"):
       
   787             if name == search:
       
   788                 ui.write("%s\n" % path)
       
   789                 return
       
   790         ui.warn("not found!\n")
       
   791         return 1
       
   792     else:
       
   793         for name, path in ui.configitems("paths"):
       
   794             ui.write("%s = %s\n" % (name, path))
   769 
   795 
   770 def pull(ui, repo, source="default", **opts):
   796 def pull(ui, repo, source="default", **opts):
   771     """pull changes from the specified source"""
   797     """pull changes from the specified source"""
   772     source = ui.expandpath(source)
   798     source = ui.expandpath(source)
   773     ui.status('pulling from %s\n' % (source))
   799     ui.status('pulling from %s\n' % (source))
  1153          [('r', 'rev', [], 'revision'),
  1179          [('r', 'rev', [], 'revision'),
  1154           ('p', 'patch', None, 'show patch')],
  1180           ('p', 'patch', None, 'show patch')],
  1155          'hg log [-r REV1 [-r REV2]] [-p] [FILE]'),
  1181          'hg log [-r REV1 [-r REV2]] [-p] [FILE]'),
  1156     "manifest": (manifest, [], 'hg manifest [REV]'),
  1182     "manifest": (manifest, [], 'hg manifest [REV]'),
  1157     "parents": (parents, [], 'hg parents [REV]'),
  1183     "parents": (parents, [], 'hg parents [REV]'),
       
  1184     "paths": (paths, [], 'hg paths [name]'),
  1158     "^pull":
  1185     "^pull":
  1159         (pull,
  1186         (pull,
  1160          [('u', 'update', None, 'update working directory')],
  1187          [('u', 'update', None, 'update working directory')],
  1161          'hg pull [-u] [SOURCE]'),
  1188          'hg pull [-u] [SOURCE]'),
  1162     "^push": (push, [], 'hg push [DEST]'),
  1189     "^push": (push, [], 'hg push [DEST]'),
  1218               ('', 'profile', None, 'profile'),
  1245               ('', 'profile', None, 'profile'),
  1219               ('R', 'repository', "", 'repository root directory'),
  1246               ('R', 'repository', "", 'repository root directory'),
  1220               ('', 'traceback', None, 'print traceback on exception'),
  1247               ('', 'traceback', None, 'print traceback on exception'),
  1221               ('y', 'noninteractive', None, 'run non-interactively'),
  1248               ('y', 'noninteractive', None, 'run non-interactively'),
  1222               ('', 'version', None, 'output version information and exit'),
  1249               ('', 'version', None, 'output version information and exit'),
       
  1250               ('', 'time', None, 'time how long the command takes'),
  1223              ]
  1251              ]
  1224 
  1252 
  1225 norepo = "clone init version help debugindex debugindexdot"
  1253 norepo = "clone init version help debugindex debugindexdot"
  1226 
  1254 
  1227 def find(cmd):
  1255 def find(cmd):
  1300     except UnknownCommand, inst:
  1328     except UnknownCommand, inst:
  1301         u = ui.ui()
  1329         u = ui.ui()
  1302         u.warn("hg: unknown command '%s'\n" % inst.args[0])
  1330         u.warn("hg: unknown command '%s'\n" % inst.args[0])
  1303         help_(u)
  1331         help_(u)
  1304         sys.exit(1)
  1332         sys.exit(1)
       
  1333 
       
  1334     if options["time"]:
       
  1335         def get_times():
       
  1336             t = os.times()
       
  1337             if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
       
  1338                 t = (t[0], t[1], t[2], t[3], time.clock())
       
  1339             return t
       
  1340         s = get_times()
       
  1341         def print_time():
       
  1342             t = get_times()
       
  1343             u = ui.ui()
       
  1344             u.warn("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n" %
       
  1345                 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
       
  1346         atexit.register(print_time)
  1305 
  1347 
  1306     u = ui.ui(options["verbose"], options["debug"], options["quiet"],
  1348     u = ui.ui(options["verbose"], options["debug"], options["quiet"],
  1307               not options["noninteractive"])
  1349               not options["noninteractive"])
  1308 
  1350 
  1309     try:
  1351     try:
  1341         u.warn("interrupted!\n")
  1383         u.warn("interrupted!\n")
  1342     except IOError, inst:
  1384     except IOError, inst:
  1343         if hasattr(inst, "code"):
  1385         if hasattr(inst, "code"):
  1344             u.warn("abort: %s\n" % inst)
  1386             u.warn("abort: %s\n" % inst)
  1345         elif hasattr(inst, "reason"):
  1387         elif hasattr(inst, "reason"):
  1346             u.warn("abort: error %d: %s\n" % (inst.reason[0], inst.reason[1]))
  1388             u.warn("abort: error: %s\n" % inst.reason[1])
  1347         elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
  1389         elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
  1348             if u.debugflag: u.warn("broken pipe\n")
  1390             if u.debugflag: u.warn("broken pipe\n")
  1349         else:
  1391         else:
  1350             raise
  1392             raise
  1351     except OSError, inst:
  1393     except OSError, inst: