def __init__(self, ui, path): if svn is None: raise MissingTool(_('Could not load Subversion python bindings')) converter_sink.__init__(self, ui, path) commandline.__init__(self, ui, 'svn') self.delete = [] self.setexec = [] self.delexec = [] self.copies = [] self.wc = None self.cwd = os.getcwd() path = os.path.realpath(path) created = False if os.path.isfile(os.path.join(path, '.svn', 'entries')): self.wc = path self.run0('update') else: wcpath = os.path.join(os.getcwd(), os.path.basename(path) + '-wc') if os.path.isdir(os.path.dirname(path)): if not os.path.exists(os.path.join(path, 'db', 'fs-type')): ui.status( _('initializing svn repository %r\n') % os.path.basename(path)) commandline(ui, 'svnadmin').run0('create', path) created = path path = util.normpath(path) if not path.startswith('/'): path = '/' + path path = 'file://' + path ui.status( _('initializing svn working copy %r\n') % os.path.basename(wcpath)) self.run0('checkout', path, wcpath) self.wc = wcpath self.opener = util.opener(self.wc) self.wopener = util.opener(self.wc) self.childmap = mapfile(ui, self.join('hg-childmap')) self.is_exec = util.checkexec(self.wc) and util.is_exec or None if created: hook = os.path.join(created, 'hooks', 'pre-revprop-change') fp = open(hook, 'w') fp.write(pre_revprop_change) fp.close() util.set_flags(hook, False, True) xport = transport.SvnRaTransport(url=geturl(path)) self.uuid = svn.ra.get_uuid(xport.ra)
def __init__(self, ui, path): if svn is None: raise MissingTool(_('Could not load Subversion python bindings')) converter_sink.__init__(self, ui, path) commandline.__init__(self, ui, 'svn') self.delete = [] self.setexec = [] self.delexec = [] self.copies = [] self.wc = None self.cwd = os.getcwd() path = os.path.realpath(path) created = False if os.path.isfile(os.path.join(path, '.svn', 'entries')): self.wc = path self.run0('update') else: wcpath = os.path.join(os.getcwd(), os.path.basename(path) + '-wc') if os.path.isdir(os.path.dirname(path)): if not os.path.exists(os.path.join(path, 'db', 'fs-type')): ui.status(_('initializing svn repository %r\n') % os.path.basename(path)) commandline(ui, 'svnadmin').run0('create', path) created = path path = util.normpath(path) if not path.startswith('/'): path = '/' + path path = 'file://' + path ui.status(_('initializing svn working copy %r\n') % os.path.basename(wcpath)) self.run0('checkout', path, wcpath) self.wc = wcpath self.opener = util.opener(self.wc) self.wopener = util.opener(self.wc) self.childmap = mapfile(ui, self.join('hg-childmap')) self.is_exec = util.checkexec(self.wc) and util.is_exec or None if created: hook = os.path.join(created, 'hooks', 'pre-revprop-change') fp = open(hook, 'w') fp.write(pre_revprop_change) fp.close() util.set_flags(hook, False, True) xport = transport.SvnRaTransport(url=geturl(path)) self.uuid = svn.ra.get_uuid(xport.ra)
def __init__(self, ui, repo): self.ui = ui self.path = repo.join('transplant') self.opener = util.opener(self.path) self.transplants = transplants(self.path, 'transplants', opener=self.opener)
def __init__(self, path=None, transplantfile=None, opener=None): self.path = path self.transplantfile = transplantfile self.opener = opener if not opener: self.opener = util.opener(self.path) self.transplants = [] self.dirty = False self.read()
def __init__(self, ui, repo): self.ui = ui self.repo = repo self.path = repo.join('imerge') self.opener = util.opener(self.path) self.wctx = self.repo.workingctx() self.conflicts = {} self.resolved = []
def __init__(self, ui, path, patchdir=None): """initializes everything, this was copied from mq""" self.basepath = path self.path = patchdir or os.path.join(path, 'attic') self.opener = util.opener(self.path) self.ui = ui self.applied = '' self.appliedfile = '.applied' self.currentpatch = '' self.currentfile = '.current' if not os.path.isdir(self.path): try: os.mkdir(self.path) except OSError, inst: if inst.errno != errno.EEXIST or not create: raise
def openbfdirstate(ui, repo): """ Return a dirstate object that tracks big files: i.e. its root is the repo root, but it is saved in .hg/bfiles/dirstate. """ admin = repo.join(longname) try: # Mercurial >= 1.9 opener = scmutil.opener(admin) except ImportError: # Mercurial <= 1.8 opener = util.opener(admin) if hasattr(repo.dirstate, "_validate"): bfdirstate = dirstate.dirstate(opener, ui, repo.root, repo.dirstate._validate) else: bfdirstate = dirstate.dirstate(opener, ui, repo.root) # If the bfiles dirstate does not exist, populate and create it. This # ensures that we create it on the first meaningful bfiles operation in # a new clone. It also gives us an easy way to forcibly rebuild bfiles # state: # rm .hg/bfiles/dirstate && hg bfstatus # Or even, if things are really messed up: # rm -rf .hg/bfiles && hg bfstatus # (although that can lose data, e.g. pending big file revisions in # .hg/bfiles/{pending,committed}). if not os.path.exists(os.path.join(admin, "dirstate")): util.makedirs(admin) matcher = getstandinmatcher(repo) for standin in dirstate_walk(repo.dirstate, matcher): bigfile = splitstandin(standin) hash = readstandin(repo, standin) try: curhash = hashfile(bigfile) except IOError, err: if err.errno == errno.ENOENT: dirstate_normaldirty(bfdirstate, bigfile) else: raise else: if curhash == hash: bfdirstate.normal(unixpath(bigfile)) else: dirstate_normaldirty(bfdirstate, bigfile) bfdirstate.write()
def open_bfdirstate(ui, repo): ''' Return a dirstate object that tracks big files: i.e. its root is the repo root, but it is saved in .hg/bfiles/dirstate. ''' admin = repo.join(long_name) opener = util.opener(admin) if hasattr(repo.dirstate, '_validate'): bfdirstate = dirstate.dirstate(opener, ui, repo.root, repo.dirstate._validate) else: bfdirstate = dirstate.dirstate(opener, ui, repo.root) # If the bfiles dirstate does not exist, populate and create it. This # ensures that we create it on the first meaningful bfiles operation in # a new clone. It also gives us an easy way to forcibly rebuild bfiles # state: # rm .hg/bfiles/dirstate && hg bfstatus # Or even, if things are really messed up: # rm -rf .hg/bfiles && hg bfstatus # (although that can lose data, e.g. pending big file revisions in # .hg/bfiles/{pending,committed}). if not os.path.exists(os.path.join(admin, 'dirstate')): util.makedirs(admin) matcher = get_standin_matcher(repo) for standin in dirstate_walk(repo.dirstate, matcher): bigfile = split_standin(standin) hash = read_standin(repo, standin) try: curhash = hashfile(bigfile) except IOError, err: if err.errno == errno.ENOENT: dirstate_normaldirty(bfdirstate, bigfile) else: raise else: if curhash == hash: bfdirstate.normal(unixpath(bigfile)) else: dirstate_normaldirty(bfdirstate, bigfile) bfdirstate.write()
def snapshot(ui, repo, files, node, tmproot): '''snapshot files as of some revision if not using snapshot, -I/-X does not work and recursive diff in tools like kdiff3 and meld displays too many files.''' dirname = os.path.basename(repo.root) if dirname == "": dirname = "root" if node is not None: dirname = '%s.%s' % (dirname, short(node)) base = os.path.join(tmproot, dirname) os.mkdir(base) if node is not None: ui.note( _('making snapshot of %d files from rev %s\n') % (len(files), short(node))) else: ui.note( _('making snapshot of %d files from working directory\n') % (len(files))) wopener = util.opener(base) fns_and_mtime = [] ctx = repo[node] for fn in files: wfn = util.pconvert(fn) if not wfn in ctx: # skipping new file after a merge ? continue ui.note(' %s\n' % wfn) dest = os.path.join(base, wfn) fctx = ctx[wfn] data = repo.wwritedata(wfn, fctx.data()) if 'l' in fctx.flags(): wopener.symlink(data, wfn) else: wopener(wfn, 'w').write(data) if 'x' in fctx.flags(): util.set_flags(dest, False, True) if node is None: fns_and_mtime.append( (dest, repo.wjoin(fn), os.path.getmtime(dest))) return dirname, fns_and_mtime
def __init__(self, ui, path, patchdir=None): """initializes everything, this was copied from mq""" self.basepath = path self.path = patchdir or os.path.join(path, 'attic') if scmutil: # since version 1.9 scmutil.opener is the right function self.opener = scmutil.opener(self.path, False) else: # we are at an older version, fall back self.opener = util.opener(self.path, False) self.ui = ui self.applied = '' self.appliedfile = '.applied' self.currentpatch = '' self.currentfile = '.current' if not os.path.isdir(self.path): try: os.mkdir(self.path) except OSError, inst: if inst.errno != errno.EEXIST or not create: raise
def snapshot(ui, repo, files, node, tmproot): '''snapshot files as of some revision if not using snapshot, -I/-X does not work and recursive diff in tools like kdiff3 and meld displays too many files.''' dirname = os.path.basename(repo.root) if dirname == "": dirname = "root" if node is not None: dirname = '%s.%s' % (dirname, short(node)) base = os.path.join(tmproot, dirname) os.mkdir(base) if node is not None: ui.note(_('making snapshot of %d files from rev %s\n') % (len(files), short(node))) else: ui.note(_('making snapshot of %d files from working directory\n') % (len(files))) wopener = util.opener(base) fns_and_mtime = [] ctx = repo[node] for fn in files: wfn = util.pconvert(fn) if not wfn in ctx: # File doesn't exist; could be a bogus modify continue ui.note(' %s\n' % wfn) dest = os.path.join(base, wfn) fctx = ctx[wfn] data = repo.wwritedata(wfn, fctx.data()) if 'l' in fctx.flags(): wopener.symlink(data, wfn) else: wopener(wfn, 'w').write(data) if 'x' in fctx.flags(): util.set_flags(dest, False, True) if node is None: fns_and_mtime.append((dest, repo.wjoin(fn), os.lstat(dest).st_mtime)) return dirname, fns_and_mtime
def shrink(ui, repo, **opts): """ Shrink revlog by re-ordering revisions. Will operate on manifest for the given repository if no other revlog is specified.""" # Unbuffer stdout for nice progress output. sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) if not repo.local(): raise util.Abort('not a local repository: %s' % repo.root) fn = opts.get('revlog') if not fn: indexfn = repo.sjoin('00manifest.i') else: if not fn.endswith('.i'): raise util.Abort('--revlog option must specify the revlog index ' 'file (*.i), not %s' % opts.get('revlog')) indexfn = os.path.realpath(fn) store = repo.sjoin('') if not indexfn.startswith(store): raise util.Abort('--revlog option must specify a revlog in %s, ' 'not %s' % (store, indexfn)) datafn = indexfn[:-2] + '.d' if not os.path.exists(indexfn): raise util.Abort('no such file: %s' % indexfn) if '00changelog' in indexfn: raise util.Abort( 'shrinking the changelog will corrupt your repository') if not os.path.exists(datafn): # This is just a lazy shortcut because I can't be bothered to # handle all the special cases that entail from no .d file. raise util.Abort('%s does not exist: revlog not big enough ' 'to be worth shrinking' % datafn) oldindexfn = indexfn + '.old' olddatafn = datafn + '.old' if os.path.exists(oldindexfn) or os.path.exists(olddatafn): raise util.Abort('one or both of\n' ' %s\n' ' %s\n' 'exists from a previous run; please clean up before ' 'running again' % (oldindexfn, olddatafn)) ui.write('shrinking %s\n' % indexfn) prefix = os.path.basename(indexfn)[:-1] (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn), prefix=prefix, suffix='.i') tmpdatafn = tmpindexfn[:-2] + '.d' os.close(tmpfd) r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn) r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn) # Don't use repo.transaction(), because then things get hairy with # paths: some need to be relative to .hg, and some need to be # absolute. Doing it this way keeps things simple: everything is an # absolute path. lock = repo.lock(wait=False) tr = transaction.transaction(ui.warn, open, repo.sjoin('journal')) try: try: order = toposort(ui, r1) writerevs(ui, r1, r2, order, tr) report(ui, datafn, tmpdatafn) tr.close() except: # Abort transaction first, so we truncate the files before # deleting them. tr.abort() if os.path.exists(tmpindexfn): os.unlink(tmpindexfn) if os.path.exists(tmpdatafn): os.unlink(tmpdatafn) raise if not opts.get('dry_run'): # Racy since both files cannot be renamed atomically util.os_link(indexfn, oldindexfn) util.os_link(datafn, olddatafn) util.rename(tmpindexfn, indexfn) util.rename(tmpdatafn, datafn) else: os.unlink(tmpindexfn) os.unlink(tmpdatafn) finally: lock.release() if not opts.get('dry_run'): ui.write( 'note: old revlog saved in:\n' ' %s\n' ' %s\n' '(You can delete those files when you are satisfied that your\n' 'repository is still sane. ' 'Running \'hg verify\' is strongly recommended.)\n' % (oldindexfn, olddatafn))
def _applymerge(self, repo, patchfile, sim, name, parent, force=False, **opts): """applies a patch using fancy merge technology.""" reverse = opts.get('reverse') opts['reverse'] = False def smwrapper(orig, *args, **opts): shelf = 'shelf:%s' % name if reverse: shelf += ' --reverse' opts['label'] = ['local', shelf] return orig(*args, **opts) def savediff(): opts = {'git': True} fp = opener('.saved', 'w') for chunk in patch.diff(repo, head, None, opts=patch.diffopts(self.ui, opts)): fp.write(chunk) fp.close() 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.) opener = util.opener('.hg/attic') smo = extensions.wrapfunction(simplemerge, 'simplemerge', smwrapper) quiet = self.ui.quiet self.ui.quiet = True whead, phead = None, None success = False try: head = repo.dirstate.parents()[0] # Save the open changes self.ui.note(_("saving open changes\n")) n = repo.commit('working', 'hgattic', None, force=1) savediff() whead = repo.heads(None)[0] # Set the workspace to match the base version for patching self.ui.note(_("applying diff to version specified in patch\n")) hg.clean(repo, parent) applydiff(self.join(patchfile)) n = repo.commit('patched', 'hgattic', None, force=1) phead = repo.heads(None)[0] if reverse: # Merge, using the working copy to avoid conflicts self.ui.note(_("applying reverse\n")) hgmerge = os.environ.get('HGMERGE') os.environ['HGMERGE'] = 'internal:other' hg.merge(repo, whead, force=True) os.environ['HGMERGE'] = hgmerge # Backout the patched version, this is where we want conflicts repo.commit('merge', 'hgattic', None, force=1) backout_opts = { 'rev': phead, 'merge': True, 'message': 'backout' } commands.backout(self.ui, repo, **backout_opts) else: # Merge the working copy with the patched copy self.ui.note(_("merging patch forward\n")) hg.merge(repo, whead, force=True) savediff() success = True finally: simplemerge.simplemerge = smo self.ui.note(_("cleanup\n")) hg.clean(repo, head) strip_opts = {'backup': False, 'nobackup': True, 'force': False} if phead and head != phead: self.strip(repo, phead) if whead and head != whead: self.strip(repo, whead) if not success: applydiff('.saved') self.ui.quiet = quiet if success: self.ui.note(_("applying updated patch\n")) success = self._applypatch(repo, '.saved', sim, force, **opts) return success
def shrink(ui, repo, **opts): """shrink a revlog by reordering revisions Rewrites all the entries in some revlog of the current repository (by default, the manifest log) to save space. Different sort algorithms have different performance characteristics. Use ``--sort`` to select a sort algorithm so you can determine which works best for your data. """ if not repo.local(): raise util.Abort(_('not a local repository: %s') % repo.root) fn = opts.get('revlog') if not fn: indexfn = repo.sjoin('00manifest.i') else: if not fn.endswith('.i'): raise util.Abort(_('--revlog option must specify the revlog index ' 'file (*.i), not %s') % opts.get('revlog')) indexfn = os.path.realpath(fn) store = repo.sjoin('') if not indexfn.startswith(store): raise util.Abort(_('--revlog option must specify a revlog in %s, ' 'not %s') % (store, indexfn)) sortname = opts['sort'] try: toposort = globals()['toposort_' + sortname] except KeyError: raise util.Abort(_('no such toposort algorithm: %s') % sortname) if not os.path.exists(indexfn): raise util.Abort(_('no such file: %s') % indexfn) if '00changelog' in indexfn: raise util.Abort(_('shrinking the changelog ' 'will corrupt your repository')) ui.write(_('shrinking %s\n') % indexfn) prefix = os.path.basename(indexfn)[:-1] tmpindexfn = util.mktempcopy(indexfn, emptyok=True) r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn) r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn) datafn, tmpdatafn = r1.datafile, r2.datafile oldindexfn = indexfn + '.old' olddatafn = datafn + '.old' if os.path.exists(oldindexfn) or os.path.exists(olddatafn): raise util.Abort(_('one or both of\n' ' %s\n' ' %s\n' 'exists from a previous run; please clean up ' 'before running again') % (oldindexfn, olddatafn)) # Don't use repo.transaction(), because then things get hairy with # paths: some need to be relative to .hg, and some need to be # absolute. Doing it this way keeps things simple: everything is an # absolute path. lock = repo.lock(wait=False) tr = transaction.transaction(ui.warn, open, repo.sjoin('journal')) def ignoremissing(func): def f(*args, **kw): try: return func(*args, **kw) except OSError, inst: if inst.errno != errno.ENOENT: raise return f
def shrink(ui, repo, **opts): """shrink a revlog by reordering revisions Rewrites all the entries in some revlog of the current repository (by default, the manifest log) to save space. Different sort algorithms have different performance characteristics. Use ``--sort`` to select a sort algorithm so you can determine which works best for your data. """ if not repo.local(): raise util.Abort(_('not a local repository: %s') % repo.root) fn = opts.get('revlog') if not fn: indexfn = repo.sjoin('00manifest.i') else: if not fn.endswith('.i'): raise util.Abort( _('--revlog option must specify the revlog index ' 'file (*.i), not %s') % opts.get('revlog')) indexfn = os.path.realpath(fn) store = repo.sjoin('') if not indexfn.startswith(store): raise util.Abort( _('--revlog option must specify a revlog in %s, ' 'not %s') % (store, indexfn)) sortname = opts['sort'] try: toposort = globals()['toposort_' + sortname] except KeyError: raise util.Abort(_('no such toposort algorithm: %s') % sortname) if not os.path.exists(indexfn): raise util.Abort(_('no such file: %s') % indexfn) if '00changelog' in indexfn: raise util.Abort( _('shrinking the changelog ' 'will corrupt your repository')) ui.write(_('shrinking %s\n') % indexfn) prefix = os.path.basename(indexfn)[:-1] tmpindexfn = util.mktempcopy(indexfn, emptyok=True) r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn) r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn) datafn, tmpdatafn = r1.datafile, r2.datafile oldindexfn = indexfn + '.old' olddatafn = datafn + '.old' if os.path.exists(oldindexfn) or os.path.exists(olddatafn): raise util.Abort( _('one or both of\n' ' %s\n' ' %s\n' 'exists from a previous run; please clean up ' 'before running again') % (oldindexfn, olddatafn)) # Don't use repo.transaction(), because then things get hairy with # paths: some need to be relative to .hg, and some need to be # absolute. Doing it this way keeps things simple: everything is an # absolute path. lock = repo.lock(wait=False) tr = transaction.transaction(ui.warn, open, repo.sjoin('journal')) def ignoremissing(func): def f(*args, **kw): try: return func(*args, **kw) except OSError, inst: if inst.errno != errno.ENOENT: raise return f
def shrink(ui, repo, **opts): """ Shrink revlog by re-ordering revisions. Will operate on manifest for the given repository if no other revlog is specified.""" # Unbuffer stdout for nice progress output. sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) if not repo.local(): raise util.Abort('not a local repository: %s' % repo.root) fn = opts.get('revlog') if not fn: indexfn = repo.sjoin('00manifest.i') else: if not fn.endswith('.i'): raise util.Abort('--revlog option must specify the revlog index ' 'file (*.i), not %s' % opts.get('revlog')) indexfn = os.path.realpath(fn) store = repo.sjoin('') if not indexfn.startswith(store): raise util.Abort('--revlog option must specify a revlog in %s, ' 'not %s' % (store, indexfn)) datafn = indexfn[:-2] + '.d' if not os.path.exists(indexfn): raise util.Abort('no such file: %s' % indexfn) if '00changelog' in indexfn: raise util.Abort('shrinking the changelog will corrupt your repository') if not os.path.exists(datafn): # This is just a lazy shortcut because I can't be bothered to # handle all the special cases that entail from no .d file. raise util.Abort('%s does not exist: revlog not big enough ' 'to be worth shrinking' % datafn) oldindexfn = indexfn + '.old' olddatafn = datafn + '.old' if os.path.exists(oldindexfn) or os.path.exists(olddatafn): raise util.Abort('one or both of\n' ' %s\n' ' %s\n' 'exists from a previous run; please clean up before ' 'running again' % (oldindexfn, olddatafn)) ui.write('shrinking %s\n' % indexfn) prefix = os.path.basename(indexfn)[:-1] (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn), prefix=prefix, suffix='.i') tmpdatafn = tmpindexfn[:-2] + '.d' os.close(tmpfd) r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn) r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn) # Don't use repo.transaction(), because then things get hairy with # paths: some need to be relative to .hg, and some need to be # absolute. Doing it this way keeps things simple: everything is an # absolute path. lock = repo.lock(wait=False) tr = transaction.transaction(ui.warn, open, repo.sjoin('journal')) try: try: order = toposort(ui, r1) writerevs(ui, r1, r2, order, tr) report(ui, datafn, tmpdatafn) tr.close() except: # Abort transaction first, so we truncate the files before # deleting them. tr.abort() if os.path.exists(tmpindexfn): os.unlink(tmpindexfn) if os.path.exists(tmpdatafn): os.unlink(tmpdatafn) raise if not opts.get('dry_run'): # Racy since both files cannot be renamed atomically util.os_link(indexfn, oldindexfn) util.os_link(datafn, olddatafn) util.rename(tmpindexfn, indexfn) util.rename(tmpdatafn, datafn) else: os.unlink(tmpindexfn) os.unlink(tmpdatafn) finally: lock.release() if not opts.get('dry_run'): ui.write('note: old revlog saved in:\n' ' %s\n' ' %s\n' '(You can delete those files when you are satisfied that your\n' 'repository is still sane. ' 'Running \'hg verify\' is strongly recommended.)\n' % (oldindexfn, olddatafn))
def _applymerge(self, repo, patchfile, sim, name, parent, force=False, **opts): """applies a patch using fancy merge technology.""" reverse = opts.get('reverse') opts['reverse'] = False def smwrapper(orig, *args, **opts): shelf = 'shelf:%s' % name if reverse: shelf += ' --reverse' opts['label'] = ['local', shelf] return orig(*args, **opts) def savediff(): opts = {'git': True} fp = opener('.saved', 'w') for chunk in patch.diff(repo, head, None, opts=patch.diffopts(self.ui, opts)): fp.write(chunk) fp.close() 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.) opener = util.opener('.hg/attic') smo = extensions.wrapfunction(simplemerge, 'simplemerge', smwrapper) quiet = self.ui.quiet self.ui.quiet = True whead, phead = None, None success = False try: head = repo.dirstate.parents()[0] # Save the open changes self.ui.note(_("saving open changes\n")) n = repo.commit('working', 'hgattic', None, force=1) savediff() whead = repo.heads(None)[0] # Set the workspace to match the base version for patching self.ui.note(_("applying diff to version specified in patch\n")) hg.clean(repo, parent) applydiff(self.join(patchfile)) n = repo.commit('patched', 'hgattic', None, force=1) phead = repo.heads(None)[0] if reverse: # Merge, using the working copy to avoid conflicts self.ui.note(_("applying reverse\n")) hgmerge = os.environ.get('HGMERGE') os.environ['HGMERGE'] = 'internal:other' hg.merge(repo, whead, force=True) os.environ['HGMERGE'] = hgmerge # Backout the patched version, this is where we want conflicts repo.commit('merge', 'hgattic', None, force=1) backout_opts = {'rev': phead, 'merge': True, 'message': 'backout'} commands.backout(self.ui, repo, **backout_opts) else: # Merge the working copy with the patched copy self.ui.note(_("merging patch forward\n")) hg.merge(repo, whead, force=True) savediff() success = True finally: simplemerge.simplemerge = smo self.ui.note(_("cleanup\n")) hg.clean(repo, head) strip_opts = {'backup': False, 'nobackup': True, 'force': False} if phead and head != phead: self.strip(repo, phead) if whead and head != whead: self.strip(repo, whead) if not success: applydiff('.saved') self.ui.quiet = quiet if success: self.ui.note(_("applying updated patch\n")) success = self._applypatch(repo, '.saved', sim, force, **opts) return success