# HG changeset patch # User Pierre-Yves David # Date 2015-10-06 06:17:01 # Node ID e99c3846d78a0ee7e8abf6841da725513ac38a24 # Parent 1e8e0b01faba14e905d18b8dfc737125007e9e34 export: introduce a generic way to add patch header on export Extensions currently have no easy way to add data to exported patch. This is now fixed using a generic mechanism in the same fashion used by bundle2. Tests are coming in the next changeset with its first user. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -991,6 +991,14 @@ def tryimportone(ui, repo, hunk, parents lockmod.release(dsguard) os.unlink(tmpname) +# facility to let extensions include additional data in an exported patch +# list of identifiers to be executed in order +extraexport = [] +# mapping from identifier to actual export function +# function as to return a string to be added to the header or None +# it is given two arguments (sequencenumber, changectx) +extraexportmap = {} + def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, opts=None, match=None): '''export changesets as hg patches.''' @@ -1040,6 +1048,11 @@ def export(repo, revs, template='hg-%h.p write("# Parent %s\n" % hex(prev)) if len(parents) > 1: write("# Parent %s\n" % hex(parents[1])) + + for headerid in extraexport: + header = extraexportmap[headerid](seqno, ctx) + if header is not None: + write('# %s\n' % header) write(ctx.description().rstrip()) write("\n\n")