1139 # mapping from identifier to actual export function |
1139 # mapping from identifier to actual export function |
1140 # function as to return a string to be added to the header or None |
1140 # function as to return a string to be added to the header or None |
1141 # it is given two arguments (sequencenumber, changectx) |
1141 # it is given two arguments (sequencenumber, changectx) |
1142 extraexportmap = {} |
1142 extraexportmap = {} |
1143 |
1143 |
1144 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
1144 def export(repo, revs, fntemplate='hg-%h.patch', fp=None, switch_parent=False, |
1145 opts=None, match=None): |
1145 opts=None, match=None): |
1146 '''export changesets as hg patches |
1146 '''export changesets as hg patches |
1147 |
1147 |
1148 Args: |
1148 Args: |
1149 repo: The repository from which we're exporting revisions. |
1149 repo: The repository from which we're exporting revisions. |
1150 revs: A list of revisions to export as revision numbers. |
1150 revs: A list of revisions to export as revision numbers. |
1151 template: An optional string to use for generating patch file names. |
1151 fntemplate: An optional string to use for generating patch file names. |
1152 fp: An optional file-like object to which patches should be written. |
1152 fp: An optional file-like object to which patches should be written. |
1153 switch_parent: If True, show diffs against second parent when not nullid. |
1153 switch_parent: If True, show diffs against second parent when not nullid. |
1154 Default is false, which always shows diff against p1. |
1154 Default is false, which always shows diff against p1. |
1155 opts: diff options to use for generating the patch. |
1155 opts: diff options to use for generating the patch. |
1156 match: If specified, only export changes to files matching this matcher. |
1156 match: If specified, only export changes to files matching this matcher. |
1184 prev = parents[0] |
1184 prev = parents[0] |
1185 else: |
1185 else: |
1186 prev = nullid |
1186 prev = nullid |
1187 |
1187 |
1188 shouldclose = False |
1188 shouldclose = False |
1189 if not fp and len(template) > 0: |
1189 if not fp and len(fntemplate) > 0: |
1190 desc_lines = ctx.description().rstrip().split('\n') |
1190 desc_lines = ctx.description().rstrip().split('\n') |
1191 desc = desc_lines[0] #Commit always has a first line. |
1191 desc = desc_lines[0] #Commit always has a first line. |
1192 fp = makefileobj(repo, template, node, desc=desc, total=total, |
1192 fp = makefileobj(repo, fntemplate, node, desc=desc, total=total, |
1193 seqno=seqno, revwidth=revwidth, mode='wb', |
1193 seqno=seqno, revwidth=revwidth, mode='wb', |
1194 modemap=filemode) |
1194 modemap=filemode) |
1195 shouldclose = True |
1195 shouldclose = True |
1196 if fp and not getattr(fp, 'name', '<unnamed>').startswith('<'): |
1196 if fp and not getattr(fp, 'name', '<unnamed>').startswith('<'): |
1197 repo.ui.note("%s\n" % fp.name) |
1197 repo.ui.note("%s\n" % fp.name) |