equal
deleted
inserted
replaced
117 originalchunks = patch.parsepatch(originaldiff) |
117 originalchunks = patch.parsepatch(originaldiff) |
118 |
118 |
119 # 1. filter patch, so we have intending-to apply subset of it |
119 # 1. filter patch, so we have intending-to apply subset of it |
120 try: |
120 try: |
121 chunks = filterfn(ui, originalchunks) |
121 chunks = filterfn(ui, originalchunks) |
122 except patch.PatchError, err: |
122 except patch.PatchError as err: |
123 raise util.Abort(_('error parsing patch: %s') % err) |
123 raise util.Abort(_('error parsing patch: %s') % err) |
124 |
124 |
125 # We need to keep a backup of files that have been newly added and |
125 # We need to keep a backup of files that have been newly added and |
126 # modified during the recording process because there is a previous |
126 # modified during the recording process because there is a previous |
127 # version without the edit in the workdir |
127 # version without the edit in the workdir |
151 backups = {} |
151 backups = {} |
152 if tobackup: |
152 if tobackup: |
153 backupdir = repo.join('record-backups') |
153 backupdir = repo.join('record-backups') |
154 try: |
154 try: |
155 os.mkdir(backupdir) |
155 os.mkdir(backupdir) |
156 except OSError, err: |
156 except OSError as err: |
157 if err.errno != errno.EEXIST: |
157 if err.errno != errno.EEXIST: |
158 raise |
158 raise |
159 try: |
159 try: |
160 # backup continues |
160 # backup continues |
161 for f in tobackup: |
161 for f in tobackup: |
187 if dopatch: |
187 if dopatch: |
188 try: |
188 try: |
189 ui.debug('applying patch\n') |
189 ui.debug('applying patch\n') |
190 ui.debug(fp.getvalue()) |
190 ui.debug(fp.getvalue()) |
191 patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
191 patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
192 except patch.PatchError, err: |
192 except patch.PatchError as err: |
193 raise util.Abort(str(err)) |
193 raise util.Abort(str(err)) |
194 del fp |
194 del fp |
195 |
195 |
196 # 4. We prepared working directory according to filtered |
196 # 4. We prepared working directory according to filtered |
197 # patch. Now is the time to delegate the job to |
197 # patch. Now is the time to delegate the job to |
307 try: |
307 try: |
308 if logfile == '-': |
308 if logfile == '-': |
309 message = ui.fin.read() |
309 message = ui.fin.read() |
310 else: |
310 else: |
311 message = '\n'.join(util.readfile(logfile).splitlines()) |
311 message = '\n'.join(util.readfile(logfile).splitlines()) |
312 except IOError, inst: |
312 except IOError as inst: |
313 raise util.Abort(_("can't read commit message '%s': %s") % |
313 raise util.Abort(_("can't read commit message '%s': %s") % |
314 (logfile, inst.strerror)) |
314 (logfile, inst.strerror)) |
315 return message |
315 return message |
316 |
316 |
317 def mergeeditform(ctxorbool, baseformname): |
317 def mergeeditform(ctxorbool, baseformname): |
416 c = pat[i] |
416 c = pat[i] |
417 c = expander[c]() |
417 c = expander[c]() |
418 newname.append(c) |
418 newname.append(c) |
419 i += 1 |
419 i += 1 |
420 return ''.join(newname) |
420 return ''.join(newname) |
421 except KeyError, inst: |
421 except KeyError as inst: |
422 raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
422 raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
423 inst.args[0]) |
423 inst.args[0]) |
424 |
424 |
425 def makefileobj(repo, pat, node=None, desc=None, total=None, |
425 def makefileobj(repo, pat, node=None, desc=None, total=None, |
426 seqno=None, revwidth=None, mode='wb', modemap=None, |
426 seqno=None, revwidth=None, mode='wb', modemap=None, |
603 os.rename(src, tmp) |
603 os.rename(src, tmp) |
604 os.rename(tmp, target) |
604 os.rename(tmp, target) |
605 else: |
605 else: |
606 util.copyfile(src, target) |
606 util.copyfile(src, target) |
607 srcexists = True |
607 srcexists = True |
608 except IOError, inst: |
608 except IOError as inst: |
609 if inst.errno == errno.ENOENT: |
609 if inst.errno == errno.ENOENT: |
610 ui.warn(_('%s: deleted in working directory\n') % relsrc) |
610 ui.warn(_('%s: deleted in working directory\n') % relsrc) |
611 srcexists = False |
611 srcexists = False |
612 else: |
612 else: |
613 ui.warn(_('%s: cannot copy - %s\n') % |
613 ui.warn(_('%s: cannot copy - %s\n') % |
771 raise util.Abort(_('child process failed to start')) |
771 raise util.Abort(_('child process failed to start')) |
772 writepid(pid) |
772 writepid(pid) |
773 finally: |
773 finally: |
774 try: |
774 try: |
775 os.unlink(lockpath) |
775 os.unlink(lockpath) |
776 except OSError, e: |
776 except OSError as e: |
777 if e.errno != errno.ENOENT: |
777 if e.errno != errno.ENOENT: |
778 raise |
778 raise |
779 if parentfn: |
779 if parentfn: |
780 return parentfn(pid) |
780 return parentfn(pid) |
781 else: |
781 else: |
896 partial = opts.get('partial', False) |
896 partial = opts.get('partial', False) |
897 files = set() |
897 files = set() |
898 try: |
898 try: |
899 patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, |
899 patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, |
900 files=files, eolmode=None, similarity=sim / 100.0) |
900 files=files, eolmode=None, similarity=sim / 100.0) |
901 except patch.PatchError, e: |
901 except patch.PatchError as e: |
902 if not partial: |
902 if not partial: |
903 raise util.Abort(str(e)) |
903 raise util.Abort(str(e)) |
904 if partial: |
904 if partial: |
905 rejects = True |
905 rejects = True |
906 |
906 |
940 try: |
940 try: |
941 files = set() |
941 files = set() |
942 try: |
942 try: |
943 patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix, |
943 patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix, |
944 files, eolmode=None) |
944 files, eolmode=None) |
945 except patch.PatchError, e: |
945 except patch.PatchError as e: |
946 raise util.Abort(str(e)) |
946 raise util.Abort(str(e)) |
947 if opts.get('exact'): |
947 if opts.get('exact'): |
948 editor = None |
948 editor = None |
949 else: |
949 else: |
950 editor = getcommiteditor(editform='import.bypass') |
950 editor = getcommiteditor(editform='import.bypass') |
1457 if types['footer']: |
1457 if types['footer']: |
1458 if not self.footer: |
1458 if not self.footer: |
1459 self.footer = templater.stringify(self.t(types['footer'], |
1459 self.footer = templater.stringify(self.t(types['footer'], |
1460 **props)) |
1460 **props)) |
1461 |
1461 |
1462 except KeyError, inst: |
1462 except KeyError as inst: |
1463 msg = _("%s: no key named '%s'") |
1463 msg = _("%s: no key named '%s'") |
1464 raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
1464 raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
1465 except SyntaxError, inst: |
1465 except SyntaxError as inst: |
1466 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
1466 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
1467 |
1467 |
1468 def gettemplate(ui, tmpl, style): |
1468 def gettemplate(ui, tmpl, style): |
1469 """ |
1469 """ |
1470 Find the template matching the given template spec or style. |
1470 Find the template matching the given template spec or style. |
1521 return changeset_printer(ui, repo, matchfn, opts, buffered) |
1521 return changeset_printer(ui, repo, matchfn, opts, buffered) |
1522 |
1522 |
1523 try: |
1523 try: |
1524 t = changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, |
1524 t = changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, |
1525 buffered) |
1525 buffered) |
1526 except SyntaxError, inst: |
1526 except SyntaxError as inst: |
1527 raise util.Abort(inst.args[0]) |
1527 raise util.Abort(inst.args[0]) |
1528 return t |
1528 return t |
1529 |
1529 |
1530 def showmarker(ui, marker): |
1530 def showmarker(ui, marker): |
1531 """utility function to display obsolescence marker in a readable way |
1531 """utility function to display obsolescence marker in a readable way |
2680 ui = repo.ui |
2680 ui = repo.ui |
2681 tmpl, mapfile = gettemplate(ui, tmpl, None) |
2681 tmpl, mapfile = gettemplate(ui, tmpl, None) |
2682 |
2682 |
2683 try: |
2683 try: |
2684 t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False) |
2684 t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False) |
2685 except SyntaxError, inst: |
2685 except SyntaxError as inst: |
2686 raise util.Abort(inst.args[0]) |
2686 raise util.Abort(inst.args[0]) |
2687 |
2687 |
2688 for k, v in repo.ui.configitems('committemplate'): |
2688 for k, v in repo.ui.configitems('committemplate'): |
2689 if k != 'changeset': |
2689 if k != 'changeset': |
2690 t.t.cache[k] = v |
2690 t.t.cache[k] = v |
3113 |
3113 |
3114 chunks = recordfilter(repo.ui, originalchunks) |
3114 chunks = recordfilter(repo.ui, originalchunks) |
3115 if reversehunks: |
3115 if reversehunks: |
3116 chunks = patch.reversehunks(chunks) |
3116 chunks = patch.reversehunks(chunks) |
3117 |
3117 |
3118 except patch.PatchError, err: |
3118 except patch.PatchError as err: |
3119 raise util.Abort(_('error parsing patch: %s') % err) |
3119 raise util.Abort(_('error parsing patch: %s') % err) |
3120 |
3120 |
3121 newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
3121 newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
3122 # Apply changes |
3122 # Apply changes |
3123 fp = cStringIO.StringIO() |
3123 fp = cStringIO.StringIO() |
3126 dopatch = fp.tell() |
3126 dopatch = fp.tell() |
3127 fp.seek(0) |
3127 fp.seek(0) |
3128 if dopatch: |
3128 if dopatch: |
3129 try: |
3129 try: |
3130 patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
3130 patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
3131 except patch.PatchError, err: |
3131 except patch.PatchError as err: |
3132 raise util.Abort(str(err)) |
3132 raise util.Abort(str(err)) |
3133 del fp |
3133 del fp |
3134 else: |
3134 else: |
3135 for f in actions['revert'][0]: |
3135 for f in actions['revert'][0]: |
3136 wsize = checkout(f) |
3136 wsize = checkout(f) |