export: introduce a generic way to add patch header on export
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 05 Oct 2015 23:17:01 -0700
changeset 26545 e99c3846d78a
parent 26544 1e8e0b01faba
child 26546 500386e65759
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.
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Mon Oct 05 00:23:20 2015 -0700
+++ b/mercurial/cmdutil.py	Mon Oct 05 23:17:01 2015 -0700
@@ -991,6 +991,14 @@
         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 @@
         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")