Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 3643:b4ad640a3bcf
templates: move changeset templating bits to cmdutils
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 13 Nov 2006 13:26:57 -0600 |
parents | 770c4fc03b8e |
children | b984dcb1df71 |
comparison
equal
deleted
inserted
replaced
3642:b2c47652e8e3 | 3643:b4ad640a3bcf |
---|---|
7 | 7 |
8 from demandload import demandload | 8 from demandload import demandload |
9 from node import * | 9 from node import * |
10 from i18n import gettext as _ | 10 from i18n import gettext as _ |
11 demandload(globals(), "os re sys signal imp urllib pdb shlex") | 11 demandload(globals(), "os re sys signal imp urllib pdb shlex") |
12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") | 12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo") |
13 demandload(globals(), "difflib patch tempfile time") | 13 demandload(globals(), "difflib patch tempfile time") |
14 demandload(globals(), "traceback errno version atexit bz2") | 14 demandload(globals(), "traceback errno version atexit bz2") |
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") | 15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") |
16 | 16 |
17 class UnknownCommand(Exception): | 17 class UnknownCommand(Exception): |
293 if fh is not None: | 293 if fh is not None: |
294 fh.close() | 294 fh.close() |
295 if cleanup is not None: | 295 if cleanup is not None: |
296 os.unlink(cleanup) | 296 os.unlink(cleanup) |
297 | 297 |
298 class changeset_printer(object): | |
299 '''show changeset information when templating not requested.''' | |
300 | |
301 def __init__(self, ui, repo): | |
302 self.ui = ui | |
303 self.repo = repo | |
304 | |
305 def show(self, rev=0, changenode=None, brinfo=None, copies=None): | |
306 '''show a single changeset or file revision''' | |
307 log = self.repo.changelog | |
308 if changenode is None: | |
309 changenode = log.node(rev) | |
310 elif not rev: | |
311 rev = log.rev(changenode) | |
312 | |
313 if self.ui.quiet: | |
314 self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
315 return | |
316 | |
317 changes = log.read(changenode) | |
318 date = util.datestr(changes[2]) | |
319 extra = changes[5] | |
320 branch = extra.get("branch") | |
321 | |
322 hexfunc = self.ui.debugflag and hex or short | |
323 | |
324 parents = log.parentrevs(rev) | |
325 if not self.ui.debugflag: | |
326 if parents[1] == nullrev: | |
327 if parents[0] >= rev - 1: | |
328 parents = [] | |
329 else: | |
330 parents = [parents[0]] | |
331 parents = [(p, hexfunc(log.node(p))) for p in parents] | |
332 | |
333 self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode))) | |
334 | |
335 if branch: | |
336 self.ui.write(_("branch: %s\n") % branch) | |
337 for tag in self.repo.nodetags(changenode): | |
338 self.ui.write(_("tag: %s\n") % tag) | |
339 for parent in parents: | |
340 self.ui.write(_("parent: %d:%s\n") % parent) | |
341 | |
342 if brinfo and changenode in brinfo: | |
343 br = brinfo[changenode] | |
344 self.ui.write(_("branch: %s\n") % " ".join(br)) | |
345 | |
346 if self.ui.debugflag: | |
347 self.ui.write(_("manifest: %d:%s\n") % | |
348 (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
349 self.ui.write(_("user: %s\n") % changes[1]) | |
350 self.ui.write(_("date: %s\n") % date) | |
351 | |
352 if self.ui.debugflag: | |
353 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] | |
354 for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
355 files): | |
356 if value: | |
357 self.ui.write("%-12s %s\n" % (key, " ".join(value))) | |
358 elif changes[3] and self.ui.verbose: | |
359 self.ui.write(_("files: %s\n") % " ".join(changes[3])) | |
360 if copies and self.ui.verbose: | |
361 copies = ['%s (%s)' % c for c in copies] | |
362 self.ui.write(_("copies: %s\n") % ' '.join(copies)) | |
363 | |
364 if extra and self.ui.debugflag: | |
365 extraitems = extra.items() | |
366 extraitems.sort() | |
367 for key, value in extraitems: | |
368 self.ui.write(_("extra: %s=%s\n") | |
369 % (key, value.encode('string_escape'))) | |
370 | |
371 description = changes[4].strip() | |
372 if description: | |
373 if self.ui.verbose: | |
374 self.ui.write(_("description:\n")) | |
375 self.ui.write(description) | |
376 self.ui.write("\n\n") | |
377 else: | |
378 self.ui.write(_("summary: %s\n") % | |
379 description.splitlines()[0]) | |
380 self.ui.write("\n") | |
381 | |
382 def show_changeset(ui, repo, opts): | |
383 """show one changeset using template or regular display. | |
384 | |
385 Display format will be the first non-empty hit of: | |
386 1. option 'template' | |
387 2. option 'style' | |
388 3. [ui] setting 'logtemplate' | |
389 4. [ui] setting 'style' | |
390 If all of these values are either the unset or the empty string, | |
391 regular display via changeset_printer() is done. | |
392 """ | |
393 # options | |
394 tmpl = opts.get('template') | |
395 mapfile = None | |
396 if tmpl: | |
397 tmpl = templater.parsestring(tmpl, quoted=False) | |
398 else: | |
399 mapfile = opts.get('style') | |
400 # ui settings | |
401 if not mapfile: | |
402 tmpl = ui.config('ui', 'logtemplate') | |
403 if tmpl: | |
404 tmpl = templater.parsestring(tmpl) | |
405 else: | |
406 mapfile = ui.config('ui', 'style') | |
407 | |
408 if tmpl or mapfile: | |
409 if mapfile: | |
410 if not os.path.split(mapfile)[0]: | |
411 mapname = (templater.templatepath('map-cmdline.' + mapfile) | |
412 or templater.templatepath(mapfile)) | |
413 if mapname: mapfile = mapname | |
414 try: | |
415 t = templater.changeset_templater(ui, repo, mapfile) | |
416 except SyntaxError, inst: | |
417 raise util.Abort(inst.args[0]) | |
418 if tmpl: t.use_template(tmpl) | |
419 return t | |
420 return changeset_printer(ui, repo) | |
421 | |
422 def setremoteconfig(ui, opts): | 298 def setremoteconfig(ui, opts): |
423 "copy remote options to ui tree" | 299 "copy remote options to ui tree" |
424 if opts.get('ssh'): | 300 if opts.get('ssh'): |
425 ui.setconfig("ui", "ssh", opts['ssh']) | 301 ui.setconfig("ui", "ssh", opts['ssh']) |
426 if opts.get('remotecmd'): | 302 if opts.get('remotecmd'): |
1561 br = None | 1437 br = None |
1562 if opts['branches']: | 1438 if opts['branches']: |
1563 ui.warn(_("the --branches option is deprecated, " | 1439 ui.warn(_("the --branches option is deprecated, " |
1564 "please use 'hg branches' instead\n")) | 1440 "please use 'hg branches' instead\n")) |
1565 br = repo.branchlookup(heads) | 1441 br = repo.branchlookup(heads) |
1566 displayer = show_changeset(ui, repo, opts) | 1442 displayer = cmdutil.show_changeset(ui, repo, opts) |
1567 for n in heads: | 1443 for n in heads: |
1568 displayer.show(changenode=n, brinfo=br) | 1444 displayer.show(changenode=n, brinfo=br) |
1569 | 1445 |
1570 def identify(ui, repo): | 1446 def identify(ui, repo): |
1571 """print information about the working copy | 1447 """print information about the working copy |
1708 if opts['rev']: | 1584 if opts['rev']: |
1709 revs = [other.lookup(rev) for rev in opts['rev']] | 1585 revs = [other.lookup(rev) for rev in opts['rev']] |
1710 o = other.changelog.nodesbetween(incoming, revs)[0] | 1586 o = other.changelog.nodesbetween(incoming, revs)[0] |
1711 if opts['newest_first']: | 1587 if opts['newest_first']: |
1712 o.reverse() | 1588 o.reverse() |
1713 displayer = show_changeset(ui, other, opts) | 1589 displayer = cmdutil.show_changeset(ui, other, opts) |
1714 for n in o: | 1590 for n in o: |
1715 parents = [p for p in other.changelog.parents(n) if p != nullid] | 1591 parents = [p for p in other.changelog.parents(n) if p != nullid] |
1716 if opts['no_merges'] and len(parents) == 2: | 1592 if opts['no_merges'] and len(parents) == 2: |
1717 continue | 1593 continue |
1718 displayer.show(changenode=n) | 1594 displayer.show(changenode=n) |
1877 dcache[:] = [man, repo.manifest.readdelta(man)] | 1753 dcache[:] = [man, repo.manifest.readdelta(man)] |
1878 if fn in dcache[1]: | 1754 if fn in dcache[1]: |
1879 return ncache[fn].get(dcache[1][fn]) | 1755 return ncache[fn].get(dcache[1][fn]) |
1880 return None | 1756 return None |
1881 | 1757 |
1882 displayer = show_changeset(ui, repo, opts) | 1758 displayer = cmdutil.show_changeset(ui, repo, opts) |
1883 for st, rev, fns in changeiter: | 1759 for st, rev, fns in changeiter: |
1884 if st == 'window': | 1760 if st == 'window': |
1885 du = dui(ui) | 1761 du = dui(ui) |
1886 displayer.ui = du | 1762 displayer.ui = du |
1887 elif st == 'add': | 1763 elif st == 'add': |
2013 ui.status(_("no changes found\n")) | 1889 ui.status(_("no changes found\n")) |
2014 return | 1890 return |
2015 o = repo.changelog.nodesbetween(o, revs)[0] | 1891 o = repo.changelog.nodesbetween(o, revs)[0] |
2016 if opts['newest_first']: | 1892 if opts['newest_first']: |
2017 o.reverse() | 1893 o.reverse() |
2018 displayer = show_changeset(ui, repo, opts) | 1894 displayer = cmdutil.show_changeset(ui, repo, opts) |
2019 for n in o: | 1895 for n in o: |
2020 parents = [p for p in repo.changelog.parents(n) if p != nullid] | 1896 parents = [p for p in repo.changelog.parents(n) if p != nullid] |
2021 if opts['no_merges'] and len(parents) == 2: | 1897 if opts['no_merges'] and len(parents) == 2: |
2022 continue | 1898 continue |
2023 displayer.show(changenode=n) | 1899 displayer.show(changenode=n) |
2054 br = None | 1930 br = None |
2055 if branches is not None: | 1931 if branches is not None: |
2056 ui.warn(_("the --branches option is deprecated, " | 1932 ui.warn(_("the --branches option is deprecated, " |
2057 "please use 'hg branches' instead\n")) | 1933 "please use 'hg branches' instead\n")) |
2058 br = repo.branchlookup(p) | 1934 br = repo.branchlookup(p) |
2059 displayer = show_changeset(ui, repo, opts) | 1935 displayer = cmdutil.show_changeset(ui, repo, opts) |
2060 for n in p: | 1936 for n in p: |
2061 if n != nullid: | 1937 if n != nullid: |
2062 displayer.show(changenode=n, brinfo=br) | 1938 displayer.show(changenode=n, brinfo=br) |
2063 | 1939 |
2064 def paths(ui, repo, search=None): | 1940 def paths(ui, repo, search=None): |
2681 br = None | 2557 br = None |
2682 if opts['branches']: | 2558 if opts['branches']: |
2683 ui.warn(_("the --branches option is deprecated, " | 2559 ui.warn(_("the --branches option is deprecated, " |
2684 "please use 'hg branches' instead\n")) | 2560 "please use 'hg branches' instead\n")) |
2685 br = repo.branchlookup([n]) | 2561 br = repo.branchlookup([n]) |
2686 show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | 2562 cmdutil.show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
2687 if opts['patch']: | 2563 if opts['patch']: |
2688 patch.diff(repo, repo.changelog.parents(n)[0], n) | 2564 patch.diff(repo, repo.changelog.parents(n)[0], n) |
2689 | 2565 |
2690 def unbundle(ui, repo, fname, **opts): | 2566 def unbundle(ui, repo, fname, **opts): |
2691 """apply a changegroup file | 2567 """apply a changegroup file |
2750 if branch in br[x]: | 2626 if branch in br[x]: |
2751 found.append(x) | 2627 found.append(x) |
2752 if len(found) > 1: | 2628 if len(found) > 1: |
2753 repo.ui.warn(_("Found multiple heads for %s\n") % branch) | 2629 repo.ui.warn(_("Found multiple heads for %s\n") % branch) |
2754 for x in found: | 2630 for x in found: |
2755 show_changeset(ui, repo, {}).show(changenode=x, brinfo=br) | 2631 cmdutil.show_changeset(ui, repo, {}).show( |
2632 changenode=x, brinfo=br) | |
2756 raise util.Abort("") | 2633 raise util.Abort("") |
2757 if len(found) == 1: | 2634 if len(found) == 1: |
2758 node = found[0] | 2635 node = found[0] |
2759 repo.ui.warn(_("Using head %s for branch %s\n") | 2636 repo.ui.warn(_("Using head %s for branch %s\n") |
2760 % (short(node), branch)) | 2637 % (short(node), branch)) |