168 except KeyError, inst: |
168 except KeyError, inst: |
169 raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
169 raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
170 inst.args[0]) |
170 inst.args[0]) |
171 |
171 |
172 def makefileobj(repo, pat, node=None, desc=None, total=None, |
172 def makefileobj(repo, pat, node=None, desc=None, total=None, |
173 seqno=None, revwidth=None, mode='wb', pathname=None): |
173 seqno=None, revwidth=None, mode='wb', modemap={}, |
|
174 pathname=None): |
174 |
175 |
175 writable = mode not in ('r', 'rb') |
176 writable = mode not in ('r', 'rb') |
176 |
177 |
177 if not pat or pat == '-': |
178 if not pat or pat == '-': |
178 fp = writable and repo.ui.fout or repo.ui.fin |
179 fp = writable and repo.ui.fout or repo.ui.fin |
194 return wrappedfileobj(fp) |
195 return wrappedfileobj(fp) |
195 if util.safehasattr(pat, 'write') and writable: |
196 if util.safehasattr(pat, 'write') and writable: |
196 return pat |
197 return pat |
197 if util.safehasattr(pat, 'read') and 'r' in mode: |
198 if util.safehasattr(pat, 'read') and 'r' in mode: |
198 return pat |
199 return pat |
199 return open(makefilename(repo, pat, node, desc, total, seqno, revwidth, |
200 fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname) |
200 pathname), |
201 mode = modemap.get(fn, mode) |
201 mode) |
202 if mode == 'wb': |
|
203 modemap[fn] = 'ab' |
|
204 return open(fn, mode) |
202 |
205 |
203 def openrevlog(repo, cmd, file_, opts): |
206 def openrevlog(repo, cmd, file_, opts): |
204 """opens the changelog, manifest, a filelog or a given revlog""" |
207 """opens the changelog, manifest, a filelog or a given revlog""" |
205 cl = opts['changelog'] |
208 cl = opts['changelog'] |
206 mf = opts['manifest'] |
209 mf = opts['manifest'] |
537 opts=None): |
540 opts=None): |
538 '''export changesets as hg patches.''' |
541 '''export changesets as hg patches.''' |
539 |
542 |
540 total = len(revs) |
543 total = len(revs) |
541 revwidth = max([len(str(rev)) for rev in revs]) |
544 revwidth = max([len(str(rev)) for rev in revs]) |
|
545 filemode = {} |
542 |
546 |
543 def single(rev, seqno, fp): |
547 def single(rev, seqno, fp): |
544 ctx = repo[rev] |
548 ctx = repo[rev] |
545 node = ctx.node() |
549 node = ctx.node() |
546 parents = [p.node() for p in ctx.parents() if p] |
550 parents = [p.node() for p in ctx.parents() if p] |
552 shouldclose = False |
556 shouldclose = False |
553 if not fp and len(template) > 0: |
557 if not fp and len(template) > 0: |
554 desc_lines = ctx.description().rstrip().split('\n') |
558 desc_lines = ctx.description().rstrip().split('\n') |
555 desc = desc_lines[0] #Commit always has a first line. |
559 desc = desc_lines[0] #Commit always has a first line. |
556 fp = makefileobj(repo, template, node, desc=desc, total=total, |
560 fp = makefileobj(repo, template, node, desc=desc, total=total, |
557 seqno=seqno, revwidth=revwidth, mode='ab') |
561 seqno=seqno, revwidth=revwidth, mode='wb', |
|
562 modemap=filemode) |
558 if fp != template: |
563 if fp != template: |
559 shouldclose = True |
564 shouldclose = True |
560 if fp and fp != sys.stdout and util.safehasattr(fp, 'name'): |
565 if fp and fp != sys.stdout and util.safehasattr(fp, 'name'): |
561 repo.ui.note("%s\n" % fp.name) |
566 repo.ui.note("%s\n" % fp.name) |
562 |
567 |