##// END OF EJS Templates
patch/diff: move patch.export() to cmdutil.export()...
Benoit Boissinot -
r10611:e764f24a default
parent child Browse files
Show More
@@ -113,7 +113,7 b' class ciamsg(object):'
113
113
114 n = self.ctx.node()
114 n = self.ctx.node()
115 pbuf = patchbuf()
115 pbuf = patchbuf()
116 patch.export(self.cia.repo, [n], fp=pbuf)
116 cmdutil.export(self.cia.repo, [n], fp=pbuf)
117 return patch.diffstat(pbuf.lines) or ''
117 return patch.diffstat(pbuf.lines) or ''
118
118
119 def logmsg(self):
119 def logmsg(self):
@@ -1681,7 +1681,7 b' class queue(object):'
1681 self.full_series.insert(0, patchname)
1681 self.full_series.insert(0, patchname)
1682
1682
1683 patchf = self.opener(patchname, "w")
1683 patchf = self.opener(patchname, "w")
1684 patch.export(repo, [n], fp=patchf, opts=diffopts)
1684 cmdutil.export(repo, [n], fp=patchf, opts=diffopts)
1685 patchf.close()
1685 patchf.close()
1686
1686
1687 se = statusentry(hex(n), patchname)
1687 se = statusentry(hex(n), patchname)
@@ -249,7 +249,7 b' def patchbomb(ui, repo, *revs, **opts):'
249 def getpatches(revs):
249 def getpatches(revs):
250 for r in cmdutil.revrange(repo, revs):
250 for r in cmdutil.revrange(repo, revs):
251 output = cStringIO.StringIO()
251 output = cStringIO.StringIO()
252 patch.export(repo, [r], fp=output,
252 cmdutil.export(repo, [r], fp=output,
253 opts=patch.diffopts(ui, opts))
253 opts=patch.diffopts(ui, opts))
254 yield output.getvalue().split('\n')
254 yield output.getvalue().split('\n')
255
255
@@ -660,6 +660,46 b' def service(opts, parentfn=None, initfn='
660 if runfn:
660 if runfn:
661 return runfn()
661 return runfn()
662
662
663 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
664 opts=None):
665 '''export changesets as hg patches.'''
666
667 total = len(revs)
668 revwidth = max([len(str(rev)) for rev in revs])
669
670 def single(rev, seqno, fp):
671 ctx = repo[rev]
672 node = ctx.node()
673 parents = [p.node() for p in ctx.parents() if p]
674 branch = ctx.branch()
675 if switch_parent:
676 parents.reverse()
677 prev = (parents and parents[0]) or nullid
678
679 if not fp:
680 fp = make_file(repo, template, node, total=total, seqno=seqno,
681 revwidth=revwidth, mode='ab')
682 if fp != sys.stdout and hasattr(fp, 'name'):
683 repo.ui.note("%s\n" % fp.name)
684
685 fp.write("# HG changeset patch\n")
686 fp.write("# User %s\n" % ctx.user())
687 fp.write("# Date %d %d\n" % ctx.date())
688 if branch and (branch != 'default'):
689 fp.write("# Branch %s\n" % branch)
690 fp.write("# Node ID %s\n" % hex(node))
691 fp.write("# Parent %s\n" % hex(prev))
692 if len(parents) > 1:
693 fp.write("# Parent %s\n" % hex(parents[1]))
694 fp.write(ctx.description().rstrip())
695 fp.write("\n\n")
696
697 for chunk in patch.diff(repo, prev, node, opts=opts):
698 fp.write(chunk)
699
700 for seqno, rev in enumerate(revs):
701 single(rev, seqno + 1, fp)
702
663 class changeset_printer(object):
703 class changeset_printer(object):
664 '''show changeset information when templating not requested.'''
704 '''show changeset information when templating not requested.'''
665
705
@@ -1204,7 +1204,7 b' def export(ui, repo, *changesets, **opts'
1204 ui.note(_('exporting patches:\n'))
1204 ui.note(_('exporting patches:\n'))
1205 else:
1205 else:
1206 ui.note(_('exporting patch:\n'))
1206 ui.note(_('exporting patch:\n'))
1207 patch.export(repo, revs, template=opts.get('output'),
1207 cmdutil.export(repo, revs, template=opts.get('output'),
1208 switch_parent=opts.get('switch_parent'),
1208 switch_parent=opts.get('switch_parent'),
1209 opts=patch.diffopts(ui, opts))
1209 opts=patch.diffopts(ui, opts))
1210
1210
@@ -1551,47 +1551,6 b' def trydiff(repo, revs, ctx1, ctx2, modi'
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:
General Comments 0
You need to be logged in to leave comments. Login now