Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 26545:e99c3846d78a
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.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 05 Oct 2015 23:17:01 -0700 |
parents | 3e61b325e79a |
children | b9be8ab6e628 |
comparison
equal
deleted
inserted
replaced
26544:1e8e0b01faba | 26545:e99c3846d78a |
---|---|
989 return (msg, n, rejects) | 989 return (msg, n, rejects) |
990 finally: | 990 finally: |
991 lockmod.release(dsguard) | 991 lockmod.release(dsguard) |
992 os.unlink(tmpname) | 992 os.unlink(tmpname) |
993 | 993 |
994 # facility to let extensions include additional data in an exported patch | |
995 # list of identifiers to be executed in order | |
996 extraexport = [] | |
997 # mapping from identifier to actual export function | |
998 # function as to return a string to be added to the header or None | |
999 # it is given two arguments (sequencenumber, changectx) | |
1000 extraexportmap = {} | |
1001 | |
994 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, | 1002 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
995 opts=None, match=None): | 1003 opts=None, match=None): |
996 '''export changesets as hg patches.''' | 1004 '''export changesets as hg patches.''' |
997 | 1005 |
998 total = len(revs) | 1006 total = len(revs) |
1038 write("# Branch %s\n" % branch) | 1046 write("# Branch %s\n" % branch) |
1039 write("# Node ID %s\n" % hex(node)) | 1047 write("# Node ID %s\n" % hex(node)) |
1040 write("# Parent %s\n" % hex(prev)) | 1048 write("# Parent %s\n" % hex(prev)) |
1041 if len(parents) > 1: | 1049 if len(parents) > 1: |
1042 write("# Parent %s\n" % hex(parents[1])) | 1050 write("# Parent %s\n" % hex(parents[1])) |
1051 | |
1052 for headerid in extraexport: | |
1053 header = extraexportmap[headerid](seqno, ctx) | |
1054 if header is not None: | |
1055 write('# %s\n' % header) | |
1043 write(ctx.description().rstrip()) | 1056 write(ctx.description().rstrip()) |
1044 write("\n\n") | 1057 write("\n\n") |
1045 | 1058 |
1046 for chunk, label in patch.diffui(repo, prev, node, match, opts=opts): | 1059 for chunk, label in patch.diffui(repo, prev, node, match, opts=opts): |
1047 write(chunk, label=label) | 1060 write(chunk, label=label) |