Mercurial > hg
diff mercurial/commands.py @ 2567:2748253b49c2
Merge context patches
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 05 Jul 2006 13:28:25 -0500 |
parents | 5b426676f616 d8560b458f76 |
children | 82e3b2966862 83cfd95eafb5 |
line wrap: on
line diff
--- a/mercurial/commands.py Tue Jul 04 15:36:05 2006 -0700 +++ b/mercurial/commands.py Wed Jul 05 13:28:25 2006 -0500 @@ -248,11 +248,11 @@ seen[rev] = 1 yield str(rev) -def make_filename(repo, r, pat, node=None, +def make_filename(repo, pat, node, total=None, seqno=None, revwidth=None, pathname=None): node_expander = { 'H': lambda: hex(node), - 'R': lambda: str(r.rev(node)), + 'R': lambda: str(repo.changelog.rev(node)), 'h': lambda: short(node), } expander = { @@ -292,7 +292,7 @@ raise util.Abort(_("invalid format spec '%%%s' in output file name"), inst.args[0]) -def make_file(repo, r, pat, node=None, +def make_file(repo, pat, node=None, total=None, seqno=None, revwidth=None, mode='wb', pathname=None): if not pat or pat == '-': return 'w' in mode and sys.stdout or sys.stdin @@ -300,7 +300,7 @@ return pat if hasattr(pat, 'read') and 'r' in mode: return pat - return open(make_filename(repo, r, pat, node, total, seqno, revwidth, + return open(make_filename(repo, pat, node, total, seqno, revwidth, pathname), mode) @@ -741,15 +741,18 @@ ucache = {} def getname(rev): - cl = repo.changelog.read(repo.changelog.node(rev)) - return trimuser(ui, cl[1], rev, ucache) + try: + return ucache[rev] + except: + u = trimuser(ui, repo.changectx(rev).user(), rev, ucache) + ucache[rev] = u + return u dcache = {} def getdate(rev): datestr = dcache.get(rev) if datestr is None: - cl = repo.changelog.read(repo.changelog.node(rev)) - datestr = dcache[rev] = util.datestr(cl[2]) + datestr = dcache[rev] = util.datestr(repo.changectx(rev).date()) return datestr if not pats: @@ -760,20 +763,15 @@ if not opts['user'] and not opts['changeset'] and not opts['date']: opts['number'] = 1 - if opts['rev']: - node = repo.changelog.lookup(opts['rev']) - else: - node = repo.dirstate.parents()[0] - change = repo.changelog.read(node) - mmap = repo.manifest.read(change[0]) + ctx = repo.changectx(opts['rev'] or repo.dirstate.parents()[0]) for src, abs, rel, exact in walk(repo, pats, opts, node=node): - f = repo.file(abs) - if not opts['text'] and util.binary(f.read(mmap[abs])): + fctx = ctx.filectx(abs) + if not opts['text'] and util.binary(fctx.data()): ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) continue - lines = f.annotate(mmap[abs]) + lines = fctx.annotate() pieces = [] for o, f in opmap: @@ -819,7 +817,7 @@ raise util.Abort(_('uncommitted merge - please provide a ' 'specific revision')) - dest = make_filename(repo, repo.changelog, dest, node) + dest = make_filename(repo, dest, node) if os.path.realpath(dest) == repo.root: raise util.Abort(_('repository root cannot be destination')) dummy, matchfn, dummy = matchpats(repo, [], opts) @@ -830,7 +828,7 @@ raise util.Abort(_('cannot archive plain files to stdout')) dest = sys.stdout if not prefix: prefix = os.path.basename(repo.root) + '-%h' - prefix = make_filename(repo, repo.changelog, prefix, node) + prefix = make_filename(repo, prefix, node) archival.archive(repo, dest, node, kind, not opts['no_decode'], matchfn, prefix) @@ -920,19 +918,10 @@ %d dirname of file being printed, or '.' if in repo root %p root-relative path name of file being printed """ - mf = {} - rev = opts['rev'] - if rev: - node = repo.lookup(rev) - else: - node = repo.changelog.tip() - change = repo.changelog.read(node) - mf = repo.manifest.read(change[0]) - for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): - r = repo.file(abs) - n = mf[abs] - fp = make_file(repo, r, opts['output'], node=n, pathname=abs) - fp.write(r.read(n)) + ctx = repo.changectx(opts['rev'] or -1) + for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, ctx.node()): + fp = make_file(repo, opts['output'], ctx.node(), pathname=abs) + fp.write(ctx.filectx(abs).data()) def clone(ui, source, dest=None, **opts): """make a copy of an existing repository @@ -1501,8 +1490,7 @@ prev = (parents and parents[0]) or nullid change = repo.changelog.read(node) - fp = make_file(repo, repo.changelog, opts['output'], - node=node, total=total, seqno=seqno, + fp = make_file(repo, opts['output'], node, total=total, seqno=seqno, revwidth=revwidth) if fp != sys.stdout: ui.note("%s\n" % fp.name)