def applydiff(name): files = {} patch.patch(self.join(patchfile), self.ui, strip=1, files=files) files2 = {} for k in files.keys(): files2[k.strip('\r')]=files[k] updatedir(self.ui, repo, files2, similarity=sim/100.)
def applyone(self, repo, node, cl, patchfile, merge=False, log=False, filter=None): '''apply the patch in patchfile to the repository as a transplant''' (manifest, user, (time, timezone), files, message) = cl[:5] date = "%d %d" % (time, timezone) extra = {'transplant_source': node} if filter: (user, date, message) = self.filter(filter, node, cl, patchfile) if log: # we don't translate messages inserted into commits message += '\n(transplanted from %s)' % revlog.hex(node) self.ui.status(_('applying %s\n') % short(node)) self.ui.note('%s %s\n%s\n' % (user, date, message)) if not patchfile and not merge: raise util.Abort(_('can only omit patchfile if merging')) if patchfile: try: files = set() patch.patch(self.ui, repo, patchfile, files=files, eolmode=None) files = list(files) except Exception, inst: seriespath = os.path.join(self.path, 'series') if os.path.exists(seriespath): os.unlink(seriespath) p1 = repo.dirstate.p1() p2 = node self.log(user, date, message, p1, p2, merge=merge) self.ui.write(str(inst) + '\n') raise TransplantError(_('fix up the merge and run ' 'hg transplant --continue'))
def applydiff(name): files = {} patch.patch(self.join(patchfile), self.ui, strip=1, files=files) files2 = {} for k in files.keys(): files2[k.strip('\r')] = files[k] updatedir(self.ui, repo, files2, similarity=sim / 100.)
def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges): parent = ctx.parents()[0].node() hg.update(repo, parent) fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') fp = os.fdopen(fd, 'w') diffopts = patch.diffopts(ui, opts) diffopts.git = True gen = patch.diff(repo, parent, newnode, opts=diffopts) for chunk in gen: fp.write(chunk) fp.close() files = {} try: patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None) finally: files = patch.updatedir(ui, repo, files) os.unlink(patchfile) newmessage = '\n***\n'.join( [ctx.description(), ] + [repo[r].description() for r in internalchanges] + [oldctx.description(), ]) newmessage = ui.edit(newmessage, ui.username()) n = repo.commit(text=newmessage, user=ui.username(), date=max(ctx.date(), oldctx.date()), extra=oldctx.extra()) return repo[n], [n, ], [oldctx.node(), ctx.node() ], [newnode, ] # xxx
def pick(ui, repo, ctx, ha, opts): oldctx = repo[ha] if oldctx.parents()[0] == ctx: ui.debug('node %s unchanged\n' % ha) return oldctx, [], [], [] hg.update(repo, ctx.node()) fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') fp = os.fdopen(fd, 'w') diffopts = patch.diffopts(ui, opts) diffopts.git = True gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts) for chunk in gen: fp.write(chunk) fp.close() try: files = {} try: patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None) if not files: ui.warn(_('%s: empty changeset') % node.hex(ha)) return ctx, [], [], [] finally: files = patch.updatedir(ui, repo, files) os.unlink(patchfile) except Exception, inst: raise util.Abort(_('Fix up the change and run ' 'hg histedit --continue'))
def applyone(self, repo, node, cl, patchfile, merge=False, log=False, filter=None): '''apply the patch in patchfile to the repository as a transplant''' (manifest, user, (time, timezone), files, message) = cl[:5] date = "%d %d" % (time, timezone) extra = {'transplant_source': node} if filter: (user, date, message) = self.filter(filter, node, cl, patchfile) if log: # we don't translate messages inserted into commits message += '\n(transplanted from %s)' % nodemod.hex(node) self.ui.status(_('applying %s\n') % nodemod.short(node)) self.ui.note('%s %s\n%s\n' % (user, date, message)) if not patchfile and not merge: raise error.Abort(_('can only omit patchfile if merging')) if patchfile: try: files = set() patch.patch(self.ui, repo, patchfile, files=files, eolmode=None) files = list(files) except Exception as inst: seriespath = os.path.join(self.path, 'series') if os.path.exists(seriespath): os.unlink(seriespath) p1 = repo.dirstate.p1() p2 = node self.log(user, date, message, p1, p2, merge=merge) self.ui.write(str(inst) + '\n') raise TransplantError(_('fix up the working directory and run ' 'hg transplant --continue')) else: files = None if merge: p1, p2 = repo.dirstate.parents() repo.setparents(p1, node) m = match.always(repo.root, '') else: m = match.exact(repo.root, '', files) n = repo.commit(message, user, date, extra=extra, match=m, editor=self.getcommiteditor()) if not n: self.ui.warn(_('skipping emptied changeset %s\n') % nodemod.short(node)) return None if not merge: self.transplants.set(n, node) return n
def applydiff(name): # hg 1.9 changes the params for patch! if ishg19orhigher: patch.patch(self.ui, repo, self.join(patchfile), strip=1) else: files = {} patch.patch(self.join(patchfile), self.ui, strip=1, files=files) files2 = {} for k in files.keys(): files2[k.strip('\r')]=files[k] updatedir(self.ui, repo, files2, similarity=sim/100.)
def _applypatch(self, repo, patchfile, sim, force=False, **opts): """applies a patch the old fashioned way.""" def epwrapper(orig, *epargs, **epopts): if opts.get('reverse'): epargs[1].append('-R') return orig(*epargs, **epopts) def adwrapper(orig, *adargs, **adopts): if opts.get('reverse'): adopts['reverse'] = True return orig(*adargs, **adopts) epo = extensions.wrapfunction(patch, 'externalpatch', epwrapper) ado = extensions.wrapfunction(patch, 'applydiff', adwrapper) files, success = {}, True try: try: fuzz = patch.patch(self.join(patchfile), self.ui, strip=1, cwd=repo.root, files=files) updatedir(self.ui, repo, files, similarity=sim / 100.) except Exception, inst: self.ui.note(str(inst) + '\n') if not self.ui.verbose: self.ui.warn('patch failed, unable to continue (try -v)\n') success = False finally: patch.externalpatch = epo patch.applydiff = ado return success
def _applypatch(self, repo, patchfile, sim, force=False, **opts): """applies a patch the old fashioned way.""" def epwrapper(orig, *epargs, **epopts): if opts.get('reverse'): epargs[1].append('-R') return orig(*epargs, **epopts) def adwrapper(orig, *adargs, **adopts): if opts.get('reverse'): adopts['reverse'] = True return orig(*adargs, **adopts) epo = extensions.wrapfunction(patch, 'externalpatch', epwrapper) ado = extensions.wrapfunction(patch, 'applydiff', adwrapper) files, success = {}, True try: try: fuzz = patch.patch(self.join(patchfile), self.ui, strip = 1, cwd = repo.root, files = files) updatedir(self.ui, repo, files, similarity = sim/100.) except Exception, inst: self.ui.note(str(inst) + '\n') if not self.ui.verbose: self.ui.warn('patch failed, unable to continue (try -v)\n') success = False finally: patch.externalpatch = epo patch.applydiff = ado return success
def _applypatch(self, repo, patchfile, sim, force=False, **opts): """applies a patch the old fashioned way.""" def epwrapper(orig, *epargs, **epopts): if opts.get('reverse'): epargs[1].append('-R') return orig(*epargs, **epopts) def adwrapper(orig, *adargs, **adopts): if opts.get('reverse'): adopts['reverse'] = True return orig(*adargs, **adopts) # Mercurial 1.9 deprecates external patching, will be removed in future if getattr(patch, "externalpatch", None): epo = extensions.wrapfunction(patch, 'externalpatch', epwrapper) elif getattr(patch, "_externalpatch", None): epo = extensions.wrapfunction(patch, '_externalpatch', epwrapper) else: epo = None; ado = extensions.wrapfunction(patch, 'applydiff', adwrapper) files, success = {}, True try: try: # hg 1.9 changes the params for patch! if ishg19orhigher: fuzz = patch.patch(self.ui, repo, self.join(patchfile), strip = 1) else: # patch(patchname, ui, strip=1, cwd=None, files=None, eolmode='strict') fuzz = patch.patch(self.join(patchfile), self.ui, strip = 1, cwd = repo.root, files = files) updatedir(self.ui, repo, files, similarity = sim/100.) except Exception, inst: self.ui.note(str(inst) + '\n') if not self.ui.verbose: self.ui.warn('patch failed, unable to continue (try -v)\n') success = False finally: if epo: if getattr(patch, "externalpatch", None): patch.externalpatch = epo else: patch._externalpatch = epo patch.applydiff = ado return success
def edit(ui, repo, ctx, ha, opts): oldctx = repo[ha] hg.update(repo, ctx.node()) fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') fp = os.fdopen(fd, 'w') diffopts = patch.diffopts(ui, opts) diffopts.git = True gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts) for chunk in gen: fp.write(chunk) fp.close() try: files = {} try: patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None) finally: files = patch.updatedir(ui, repo, files) os.unlink(patchfile) except Exception, inst: pass
def applypatch(ui, repo, patchname, strip=1, files=None, eolmode="strict", similarity=0): # in mercurial < 1.9, patch.patch expects files to be a dictionary that # will be filled with filenames that have been changed, and requires # that this be run through updatedir if files is None: files = set() filedict = {} try: retval = patch.patch(patchname, ui, strip=strip, cwd=repo.root, files=filedict, eolmode=eolmode) finally: updatedir(ui, repo, filedict) files.update(filedict.keys()) return retval
def patch(self, repo, patchfile): '''Apply patchfile to the working directory. patchfile: name of patch file''' files = set() try: fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1, files=files, eolmode=None) return (True, list(files), fuzz) except Exception, inst: self.ui.note(str(inst) + '\n') if not self.ui.verbose: self.ui.warn(_("patch failed, unable to continue (try -v)\n")) self.ui.traceback() return (False, list(files), False)
def applyone(self, repo, node, cl, patchfile, merge=False, log=False, filter=None): '''apply the patch in patchfile to the repository as a transplant''' (manifest, user, (time, timezone), files, message) = cl[:5] date = "%d %d" % (time, timezone) extra = {'transplant_source': node} if filter: (user, date, message) = self.filter(filter, cl, patchfile) if log: message += '\n(transplanted from %s)' % revlog.hex(node) self.ui.status(_('applying %s\n') % revlog.short(node)) self.ui.note('%s %s\n%s\n' % (user, date, message)) if not patchfile and not merge: raise util.Abort(_('can only omit patchfile if merging')) if patchfile: try: files = {} try: fuzz = patch.patch(patchfile, self.ui, cwd=repo.root, files=files) if not files: self.ui.warn( _('%s: empty changeset') % revlog.hex(node)) return None finally: files = patch.updatedir(self.ui, repo, files) except Exception, inst: if filter: os.unlink(patchfile) seriespath = os.path.join(self.path, 'series') if os.path.exists(seriespath): os.unlink(seriespath) p1 = repo.dirstate.parents()[0] p2 = node self.log(user, date, message, p1, p2, merge=merge) self.ui.write(str(inst) + '\n') raise util.Abort( _('Fix up the merge and run hg transplant --continue'))
def applypatch(ui, repo, patchname, strip=1, files=None, eolmode='strict', similarity=0): # in mercurial < 1.9, patch.patch expects files to be a dictionary that # will be filled with filenames that have been changed, and requires # that this be run through updatedir if files is None: files = set() filedict = {} try: retval = patch.patch(patchname, ui, strip=strip, cwd=repo.root, files=filedict, eolmode=eolmode) finally: updatedir(ui, repo, filedict) files.update(filedict.keys()) return retval
def applyone(self, repo, node, cl, patchfile, merge=False, log=False, filter=None): '''apply the patch in patchfile to the repository as a transplant''' (manifest, user, (time, timezone), files, message) = cl[:5] date = "%d %d" % (time, timezone) extra = {'transplant_source': node} if filter: (user, date, message) = self.filter(filter, cl, patchfile) if log: message += '\n(transplanted from %s)' % revlog.hex(node) self.ui.status(_('applying %s\n') % revlog.short(node)) self.ui.note('%s %s\n%s\n' % (user, date, message)) if not patchfile and not merge: raise util.Abort(_('can only omit patchfile if merging')) if patchfile: try: files = {} try: fuzz = patch.patch(patchfile, self.ui, cwd=repo.root, files=files) if not files: self.ui.warn(_('%s: empty changeset') % revlog.hex(node)) return None finally: files = patch.updatedir(self.ui, repo, files) except Exception, inst: if filter: os.unlink(patchfile) seriespath = os.path.join(self.path, 'series') if os.path.exists(seriespath): os.unlink(seriespath) p1 = repo.dirstate.parents()[0] p2 = node self.log(user, date, message, p1, p2, merge=merge) self.ui.write(str(inst) + '\n') raise util.Abort(_('Fix up the merge and run hg transplant --continue'))
# There's a race here whereby if the patch (or part thereof) # is applied within the same second as the clean above (such # that modification time doesn't change) and if the size of # that file does not change, Hg may not see the change. # # We sleep a full second to avoid this, as sleeping merely # until the next second begins would require very close clock # synchronization on network filesystems. # time.sleep(1) files = {} try: diff = self.bu.backupfile('diff') try: fuzz = patch.patch(diff, self.ws.ui, strip=1, cwd=self.ws.repo.root, files=files) if fuzz: raise util.Abort('working copy diff applied with fuzz') except Exception, e: raise util.Abort("couldn't apply working copy diff: %s\n" " %s" % (diff, e)) finally: if Version.at_least("1.7"): cmdutil.updatedir(self.ws.ui, self.ws.repo, files) else: patch.updatedir(self.ws.ui, self.ws.repo, files) if not self.bu.exists('renames'): return #
class CdmUncommittedBackup(object): '''Backup of uncommitted changes''' def __init__(self, backup, ws): self.ws = ws self.bu = backup def _clobbering_renames(self): '''Return a list of pairs of files representing renames/copies that clobber already versioned files. [(oldname newname)...]''' # # Note that this doesn't handle uncommitted merges # as CdmUncommittedBackup itself doesn't. # wctx = self.ws.repo.workingctx() parent = wctx.parents()[0] ret = [] for fname in wctx.added() + wctx.modified(): rn = wctx.filectx(fname).renamed() if rn and fname in parent: ret.append((rn[0], fname)) return ret def backup(self): '''Backup uncommitted changes''' if self.ws.merged(): raise util.Abort("Unable to backup an uncommitted merge.\n" "Please complete your merge and commit") dirstate = node.hex(self.ws.repo.changectx().node()) fp = None try: try: fp = open(self.bu.backupfile('dirstate'), 'w') fp.write(dirstate + '\n') except EnvironmentError, e: raise util.Abort("couldn't save working copy parent: %s" % e) finally: if fp and not fp.closed: fp.close() try: try: fp = open(self.bu.backupfile('renames'), 'w') for cons in self._clobbering_renames(): fp.write("%s %s\n" % cons) except EnvironmentError, e: raise util.Abort("couldn't save clobbering copies: %s" % e) finally: if fp and not fp.closed: fp.close() try: try: fp = open(self.bu.backupfile('diff'), 'w') patch.diff(self.ws.repo, fp=fp, opts=patch.diffopts(self.ws.ui, opts={'git': True})) except EnvironmentError, e: raise util.Abort("couldn't save working copy diff: %s" % e) finally: if fp and not fp.closed: fp.close() def _dirstate(self): '''Return the current working copy node''' fp = None try: try: fp = open(self.bu.backupfile('dirstate')) dirstate = fp.readline().strip() return dirstate except EnvironmentError, e: raise util.Abort("couldn't read saved parent: %s" % e) finally: if fp and not fp.closed: fp.close() def restore(self): '''Restore uncommitted changes''' diff = self.bu.backupfile('diff') dirstate = self._dirstate() try: self.ws.clean(rev=dirstate) except util.Abort, e: raise util.Abort("couldn't update to saved node: %s" % e) if not os.path.exists(diff): return # # There's a race here whereby if the patch (or part thereof) # is applied within the same second as the clean above (such # that mtime doesn't change) and if the size of that file # does not change, Hg may not see the change. # # We sleep a full second to avoid this, as sleeping merely # until the next second begins would require very close clock # synchronization on network filesystems. # time.sleep(1) files = {} try: try: fuzz = patch.patch(diff, self.ws.ui, strip=1, cwd=self.ws.repo.root, files=files) if fuzz: raise util.Abort('working copy diff applied with fuzz') except Exception, e: raise util.Abort("couldn't apply working copy diff: %s\n" " %s" % (diff, e)) finally: patch.updatedir(self.ws.ui, self.ws.repo, files) if not os.path.exists(self.bu.backupfile('renames')): return # # We need to re-apply name changes where the new name # (rename/copy destination) is an already versioned file, as # Hg would otherwise ignore them. # try: fp = open(self.bu.backupfile('renames')) for line in fp: source, dest = line.strip().split() self.ws.repo.copy(source, dest) except EnvironmentError, e: raise util.Abort('unable to open renames file: %s' % e)