Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.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 | 3212afb33116 |
children | 3bb438ce4458 |
comparison
equal
deleted
inserted
replaced
10610:eea2db5f56ba | 10611:e764f24a45ee |
---|---|
1549 if header and (text or len(header) > 1): | 1549 if header and (text or len(header) > 1): |
1550 yield ''.join(header) | 1550 yield ''.join(header) |
1551 if text: | 1551 if text: |
1552 yield text | 1552 yield text |
1553 | 1553 |
1554 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, | |
1555 opts=None): | |
1556 '''export changesets as hg patches.''' | |
1557 | |
1558 total = len(revs) | |
1559 revwidth = max([len(str(rev)) for rev in revs]) | |
1560 | |
1561 def single(rev, seqno, fp): | |
1562 ctx = repo[rev] | |
1563 node = ctx.node() | |
1564 parents = [p.node() for p in ctx.parents() if p] | |
1565 branch = ctx.branch() | |
1566 if switch_parent: | |
1567 parents.reverse() | |
1568 prev = (parents and parents[0]) or nullid | |
1569 | |
1570 if not fp: | |
1571 fp = cmdutil.make_file(repo, template, node, total=total, | |
1572 seqno=seqno, revwidth=revwidth, | |
1573 mode='ab') | |
1574 if fp != sys.stdout and hasattr(fp, 'name'): | |
1575 repo.ui.note("%s\n" % fp.name) | |
1576 | |
1577 fp.write("# HG changeset patch\n") | |
1578 fp.write("# User %s\n" % ctx.user()) | |
1579 fp.write("# Date %d %d\n" % ctx.date()) | |
1580 if branch and (branch != 'default'): | |
1581 fp.write("# Branch %s\n" % branch) | |
1582 fp.write("# Node ID %s\n" % hex(node)) | |
1583 fp.write("# Parent %s\n" % hex(prev)) | |
1584 if len(parents) > 1: | |
1585 fp.write("# Parent %s\n" % hex(parents[1])) | |
1586 fp.write(ctx.description().rstrip()) | |
1587 fp.write("\n\n") | |
1588 | |
1589 for chunk in diff(repo, prev, node, opts=opts): | |
1590 fp.write(chunk) | |
1591 | |
1592 for seqno, rev in enumerate(revs): | |
1593 single(rev, seqno + 1, fp) | |
1594 | |
1595 def diffstatdata(lines): | 1554 def diffstatdata(lines): |
1596 filename, adds, removes = None, 0, 0 | 1555 filename, adds, removes = None, 0, 0 |
1597 for line in lines: | 1556 for line in lines: |
1598 if line.startswith('diff'): | 1557 if line.startswith('diff'): |
1599 if filename: | 1558 if filename: |