mercurial/cmdutil.py
changeset 32431 9fd9f91b0c43
parent 32430 1f4be037f558
child 32432 75544176bc28
equal deleted inserted replaced
32430:1f4be037f558 32431:9fd9f91b0c43
  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.
  1161     Side Effect:
  1161     Side Effect:
  1162       "HG Changeset Patch" data is emitted to one of the following
  1162       "HG Changeset Patch" data is emitted to one of the following
  1163       destinations:
  1163       destinations:
  1164         fp is specified: All revs are written to the specified
  1164         fp is specified: All revs are written to the specified
  1165                          file-like object.
  1165                          file-like object.
  1166         template specified: Each rev is written to a unique file named using
  1166         fntemplate specified: Each rev is written to a unique file named using
  1167                             the given template.
  1167                             the given template.
  1168         Neither fp nor template specified: All revs written to repo.ui.write()
  1168         Neither fp nor template specified: All revs written to repo.ui.write()
  1169     '''
  1169     '''
  1170 
  1170 
  1171     total = len(revs)
  1171     total = len(revs)
  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)