comparison mercurial/cmdutil.py @ 37603:678d760c71ff

export: extract function to write patch to file object (API) This is common use case of cmdutil.export(), and we wouldn't want to handle formatter thingy everywhere. .. api:: The ``fp`` argument is removed from ``cmdutil.export()``. Use ``cmdutil.exportfile()`` instead.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 12 Apr 2018 22:59:49 +0900
parents 52670eaa14b4
children daafaff4e5be
comparison
equal deleted inserted replaced
37602:52670eaa14b4 37603:678d760c71ff
1601 fm.startitem() 1601 fm.startitem()
1602 ctx = repo[rev] 1602 ctx = repo[rev]
1603 _exportsingle(repo, ctx, fm, match, switch_parent, seqno, 1603 _exportsingle(repo, ctx, fm, match, switch_parent, seqno,
1604 diffopts) 1604 diffopts)
1605 1605
1606 def export(repo, revs, fntemplate='hg-%h.patch', fp=None, switch_parent=False, 1606 def export(repo, revs, fntemplate='hg-%h.patch', switch_parent=False,
1607 opts=None, match=None): 1607 opts=None, match=None):
1608 '''export changesets as hg patches 1608 '''export changesets as hg patches
1609 1609
1610 Args: 1610 Args:
1611 repo: The repository from which we're exporting revisions. 1611 repo: The repository from which we're exporting revisions.
1612 revs: A list of revisions to export as revision numbers. 1612 revs: A list of revisions to export as revision numbers.
1613 fntemplate: An optional string to use for generating patch file names. 1613 fntemplate: An optional string to use for generating patch file names.
1614 fp: An optional file-like object to which patches should be written.
1615 switch_parent: If True, show diffs against second parent when not nullid. 1614 switch_parent: If True, show diffs against second parent when not nullid.
1616 Default is false, which always shows diff against p1. 1615 Default is false, which always shows diff against p1.
1617 opts: diff options to use for generating the patch. 1616 opts: diff options to use for generating the patch.
1618 match: If specified, only export changes to files matching this matcher. 1617 match: If specified, only export changes to files matching this matcher.
1619 1618
1621 Nothing. 1620 Nothing.
1622 1621
1623 Side Effect: 1622 Side Effect:
1624 "HG Changeset Patch" data is emitted to one of the following 1623 "HG Changeset Patch" data is emitted to one of the following
1625 destinations: 1624 destinations:
1626 fp is specified: All revs are written to the specified
1627 file-like object.
1628 fntemplate specified: Each rev is written to a unique file named using 1625 fntemplate specified: Each rev is written to a unique file named using
1629 the given template. 1626 the given template.
1630 Neither fp nor template specified: All revs written to repo.ui.write() 1627 Otherwise: All revs written to repo.ui.write()
1631 ''' 1628 '''
1632 if fp or not fntemplate: 1629 if not fntemplate:
1633 _exportfile(repo, revs, fp, switch_parent, opts, match) 1630 _exportfile(repo, revs, None, switch_parent, opts, match)
1634 else: 1631 else:
1635 _exportfntemplate(repo, revs, fntemplate, switch_parent, opts, match) 1632 _exportfntemplate(repo, revs, fntemplate, switch_parent, opts, match)
1633
1634 def exportfile(repo, revs, fp, switch_parent=False, opts=None, match=None):
1635 """Export changesets to the given file stream"""
1636 _exportfile(repo, revs, fp, switch_parent, opts, match)
1636 1637
1637 def showmarker(fm, marker, index=None): 1638 def showmarker(fm, marker, index=None):
1638 """utility function to display obsolescence marker in a readable way 1639 """utility function to display obsolescence marker in a readable way
1639 1640
1640 To be used by debug function.""" 1641 To be used by debug function."""