Mercurial > evolve
view hgext/obsolete.py @ 923:a94ce5400e1b stable
evolve: protect call to rebase within a wlock (#42, #35, #16)
Without a wlock, repo.commit would blow away the dirstate's parents on OSes
that have no 'os.symlink' support in python, leading evolve to produce a merge
instead of a rebase. If a user ran the rebase command instead of evolve, then
things would work because rebase is wrapped in a giant wlock.
Unfortunately, we can't use the same idea of wrapping the evolve command in one
giant wlock because that's too early in the process. If the lock did wrap the
entire evolve command, then the working directory would save its current
parents which, since rebase hasn't been called yet, would be just
p1.
Therefore, we need to obtain the lock *after* the dirstate's parents are
changed but *before* the call to rebase. This way ensures that when a conflict
happens the working directory correctly shows both parent changeset.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Fri, 25 Apr 2014 19:58:33 -0500 |
parents | 9825c7da5b54 |
children | f3867e60d072 |
line wrap: on
line source
# Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org> # Logilab SA <contact@logilab.fr> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. """Deprecated extension that formely introduces "Changeset Obsolescence". This concept is now partially in Mercurial core (starting with mercurial 2.3). The remaining logic have been grouped with the evolve extension. Some code cemains in this extensions to detect and convert prehistoric format of obsolete marker than early user may have create. Keep it enabled if you were such user. """ from mercurial import util try: from mercurial import obsolete if not obsolete._enabled: obsolete._enabled = True except ImportError: raise util.Abort('Obsolete extension requires Mercurial 2.3 (or later)') import sys import json from mercurial import cmdutil from mercurial import error from mercurial.node import bin, nullid ##################################################################### ### Older format management ### ##################################################################### # Code related to detection and management of older legacy format never # handled by core def reposetup(ui, repo): """Detect that a repo still contains some old obsolete format """ if not repo.local(): return for arg in sys.argv: if 'debugc' in arg: break else: data = repo.opener.tryread('obsolete-relations') if not data: data = repo.sopener.tryread('obsoletemarkers') if data: raise util.Abort('old format of obsolete marker detected!\n' 'run `hg debugconvertobsolete` once.') def _obsdeserialise(flike): """read a file like object serialised with _obsserialise this desierialize into a {subject -> objects} mapping this was the very first format ever.""" rels = {} for line in flike: subhex, objhex = line.split() subnode = bin(subhex) if subnode == nullid: subnode = None rels.setdefault( subnode, set()).add(bin(objhex)) return rels cmdtable = {} command = cmdutil.command(cmdtable) @command('debugconvertobsolete', [], '') def cmddebugconvertobsolete(ui, repo): """import markers from an .hg/obsolete-relations file""" cnt = 0 err = 0 l = repo.lock() some = False try: unlink = [] tr = repo.transaction('convert-obsolete') try: repo._importoldobsolete = True store = repo.obsstore ### very first format try: f = repo.opener('obsolete-relations') try: some = True for line in f: subhex, objhex = line.split() suc = bin(subhex) prec = bin(objhex) sucs = (suc==nullid) and [] or [suc] meta = { 'date': '%i %i' % util.makedate(), 'user': ui.username(), } try: store.create(tr, prec, sucs, 0, meta) cnt += 1 except ValueError: repo.ui.write_err("invalid old marker line: %s" % (line)) err += 1 finally: f.close() unlink.append(repo.join('obsolete-relations')) except IOError: pass ### second (json) format data = repo.sopener.tryread('obsoletemarkers') if data: some = True for oldmark in json.loads(data): del oldmark['id'] # dropped for now del oldmark['reason'] # unused until then oldobject = str(oldmark.pop('object')) oldsubjects = [str(s) for s in oldmark.pop('subjects', [])] LOOKUP_ERRORS = (error.RepoLookupError, error.LookupError) if len(oldobject) != 40: try: oldobject = repo[oldobject].node() except LOOKUP_ERRORS: pass if any(len(s) != 40 for s in oldsubjects): try: oldsubjects = [repo[s].node() for s in oldsubjects] except LOOKUP_ERRORS: pass oldmark['date'] = '%i %i' % tuple(oldmark['date']) meta = dict((k.encode('utf-8'), v.encode('utf-8')) for k, v in oldmark.iteritems()) try: succs = [bin(n) for n in oldsubjects] succs = [n for n in succs if n != nullid] store.create(tr, bin(oldobject), succs, 0, meta) cnt += 1 except ValueError: repo.ui.write_err("invalid marker %s -> %s\n" % (oldobject, oldsubjects)) err += 1 unlink.append(repo.sjoin('obsoletemarkers')) tr.close() for path in unlink: util.unlink(path) finally: tr.release() finally: del repo._importoldobsolete l.release() if not some: ui.warn('nothing to do\n') ui.status('%i obsolete marker converted\n' % cnt) if err: ui.write_err('%i conversion failed. check you graph!\n' % err)