Mercurial > public > mercurial-scm > hg
diff 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 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Thu Apr 12 22:39:43 2018 +0900 +++ b/mercurial/cmdutil.py Thu Apr 12 22:59:49 2018 +0900 @@ -1603,7 +1603,7 @@ _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts) -def export(repo, revs, fntemplate='hg-%h.patch', fp=None, switch_parent=False, +def export(repo, revs, fntemplate='hg-%h.patch', switch_parent=False, opts=None, match=None): '''export changesets as hg patches @@ -1611,7 +1611,6 @@ repo: The repository from which we're exporting revisions. revs: A list of revisions to export as revision numbers. fntemplate: An optional string to use for generating patch file names. - fp: An optional file-like object to which patches should be written. switch_parent: If True, show diffs against second parent when not nullid. Default is false, which always shows diff against p1. opts: diff options to use for generating the patch. @@ -1623,17 +1622,19 @@ Side Effect: "HG Changeset Patch" data is emitted to one of the following destinations: - fp is specified: All revs are written to the specified - file-like object. fntemplate specified: Each rev is written to a unique file named using the given template. - Neither fp nor template specified: All revs written to repo.ui.write() + Otherwise: All revs written to repo.ui.write() ''' - if fp or not fntemplate: - _exportfile(repo, revs, fp, switch_parent, opts, match) + if not fntemplate: + _exportfile(repo, revs, None, switch_parent, opts, match) else: _exportfntemplate(repo, revs, fntemplate, switch_parent, opts, match) +def exportfile(repo, revs, fp, switch_parent=False, opts=None, match=None): + """Export changesets to the given file stream""" + _exportfile(repo, revs, fp, switch_parent, opts, match) + def showmarker(fm, marker, index=None): """utility function to display obsolescence marker in a readable way