Mercurial > public > mercurial-scm > hg
diff mercurial/cmdutil.py @ 10611:e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
This API change will allow us to break a cycle between patch and cmdutil.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Mon, 08 Mar 2010 19:43:24 +0100 |
parents | 87fce8c5e29d |
children | b2b71c304de0 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Mar 08 11:12:48 2010 -0600 +++ b/mercurial/cmdutil.py Mon Mar 08 19:43:24 2010 +0100 @@ -660,6 +660,46 @@ if runfn: return runfn() +def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, + opts=None): + '''export changesets as hg patches.''' + + total = len(revs) + revwidth = max([len(str(rev)) for rev in revs]) + + def single(rev, seqno, fp): + ctx = repo[rev] + node = ctx.node() + parents = [p.node() for p in ctx.parents() if p] + branch = ctx.branch() + if switch_parent: + parents.reverse() + prev = (parents and parents[0]) or nullid + + if not fp: + fp = make_file(repo, template, node, total=total, seqno=seqno, + revwidth=revwidth, mode='ab') + if fp != sys.stdout and hasattr(fp, 'name'): + repo.ui.note("%s\n" % fp.name) + + fp.write("# HG changeset patch\n") + fp.write("# User %s\n" % ctx.user()) + fp.write("# Date %d %d\n" % ctx.date()) + if branch and (branch != 'default'): + fp.write("# Branch %s\n" % branch) + fp.write("# Node ID %s\n" % hex(node)) + fp.write("# Parent %s\n" % hex(prev)) + if len(parents) > 1: + fp.write("# Parent %s\n" % hex(parents[1])) + fp.write(ctx.description().rstrip()) + fp.write("\n\n") + + for chunk in patch.diff(repo, prev, node, opts=opts): + fp.write(chunk) + + for seqno, rev in enumerate(revs): + single(rev, seqno + 1, fp) + class changeset_printer(object): '''show changeset information when templating not requested.'''