##// END OF EJS Templates
export: port _exportsingle() to formatter...
Yuya Nishihara -
r37620:52670eaa default
parent child Browse files
Show More
@@ -1522,7 +1522,7 b' extraexport = []'
1522 1522 # it is given two arguments (sequencenumber, changectx)
1523 1523 extraexportmap = {}
1524 1524
1525 def _exportsingle(repo, ctx, match, switch_parent, seqno, write, diffopts):
1525 def _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts):
1526 1526 node = scmutil.binnode(ctx)
1527 1527 parents = [p.node() for p in ctx.parents() if p]
1528 1528 branch = ctx.branch()
@@ -1534,42 +1534,53 b' def _exportsingle(repo, ctx, match, swit'
1534 1534 else:
1535 1535 prev = nullid
1536 1536
1537 write("# HG changeset patch\n")
1538 write("# User %s\n" % ctx.user())
1539 write("# Date %d %d\n" % ctx.date())
1540 write("# %s\n" % dateutil.datestr(ctx.date()))
1541 if branch and branch != 'default':
1542 write("# Branch %s\n" % branch)
1543 write("# Node ID %s\n" % hex(node))
1544 write("# Parent %s\n" % hex(prev))
1537 fm.context(ctx=ctx)
1538 fm.plain('# HG changeset patch\n')
1539 fm.write('user', '# User %s\n', ctx.user())
1540 fm.plain('# Date %d %d\n' % ctx.date())
1541 fm.write('date', '# %s\n', fm.formatdate(ctx.date()))
1542 fm.condwrite(branch and branch != 'default',
1543 'branch', '# Branch %s\n', branch)
1544 fm.write('node', '# Node ID %s\n', hex(node))
1545 fm.plain('# Parent %s\n' % hex(prev))
1545 1546 if len(parents) > 1:
1546 write("# Parent %s\n" % hex(parents[1]))
1547
1547 fm.plain('# Parent %s\n' % hex(parents[1]))
1548 fm.data(parents=fm.formatlist(pycompat.maplist(hex, parents), name='node'))
1549
1550 # TODO: redesign extraexportmap function to support formatter
1548 1551 for headerid in extraexport:
1549 1552 header = extraexportmap[headerid](seqno, ctx)
1550 1553 if header is not None:
1551 write('# %s\n' % header)
1552 write(ctx.description().rstrip())
1553 write("\n\n")
1554
1555 for chunk, label in patch.diffui(repo, prev, node, match, opts=diffopts):
1556 write(chunk, label=label)
1554 fm.plain('# %s\n' % header)
1555
1556 fm.write('desc', '%s\n', ctx.description().rstrip())
1557 fm.plain('\n')
1558
1559 if fm.isplain():
1560 chunkiter = patch.diffui(repo, prev, node, match, opts=diffopts)
1561 for chunk, label in chunkiter:
1562 fm.plain(chunk, label=label)
1563 else:
1564 chunkiter = patch.diff(repo, prev, node, match, opts=diffopts)
1565 # TODO: make it structured?
1566 fm.data(diff=b''.join(chunkiter))
1557 1567
1558 1568 def _exportfile(repo, revs, fp, switch_parent, diffopts, match):
1559 1569 """Export changesets to stdout or a single file"""
1560 1570 dest = '<unnamed>'
1561 1571 if fp:
1562 1572 dest = getattr(fp, 'name', dest)
1563 def write(s, **kw):
1564 fp.write(s)
1573 fm = formatter.formatter(repo.ui, fp, 'export', {})
1565 1574 else:
1566 write = repo.ui.write
1575 fm = repo.ui.formatter('export', {})
1567 1576
1568 1577 for seqno, rev in enumerate(revs, 1):
1569 1578 ctx = repo[rev]
1570 1579 if not dest.startswith('<'):
1571 1580 repo.ui.note("%s\n" % dest)
1572 _exportsingle(repo, ctx, match, switch_parent, seqno, write, diffopts)
1581 fm.startitem()
1582 _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts)
1583 fm.end()
1573 1584
1574 1585 def _exportfntemplate(repo, revs, fntemplate, switch_parent, diffopts, match):
1575 1586 """Export changesets to possibly multiple files"""
@@ -1584,13 +1595,12 b' def _exportfntemplate(repo, revs, fntemp'
1584 1595 filemap.setdefault(dest, []).append((seqno, rev))
1585 1596
1586 1597 for dest in filemap:
1587 with open(dest, 'wb') as fo:
1598 with formatter.openformatter(repo.ui, dest, 'export', {}) as fm:
1588 1599 repo.ui.note("%s\n" % dest)
1589 def write(s, **kw):
1590 fo.write(s)
1591 1600 for seqno, rev in filemap[dest]:
1601 fm.startitem()
1592 1602 ctx = repo[rev]
1593 _exportsingle(repo, ctx, match, switch_parent, seqno, write,
1603 _exportsingle(repo, ctx, fm, match, switch_parent, seqno,
1594 1604 diffopts)
1595 1605
1596 1606 def export(repo, revs, fntemplate='hg-%h.patch', fp=None, switch_parent=False,
General Comments 0
You need to be logged in to leave comments. Login now