Mercurial > evolve
changeset 361:ac7969043677
obsolete: adapt to core: marker are written in transaction now
author | Pierre-Yves.David@ens-lyon.org |
---|---|
date | Fri, 13 Jul 2012 13:07:42 +0200 |
parents | 6390ab3aea93 |
children | 5bc3e5dc2637 |
files | hgext/obsolete.py |
diffstat | 1 files changed, 90 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/obsolete.py Wed Jul 11 21:07:02 2012 +0200 +++ b/hgext/obsolete.py Fri Jul 13 13:07:42 2012 +0200 @@ -544,69 +544,77 @@ l = repo.lock() some = False try: - repo._importoldobsolete = True - store = repo.obsstore - ### very first format + unlink = [] + tr = repo.transaction('convert-obsolete') try: - f = repo.opener('obsolete-relations') + 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 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(), - } + 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: - store.create(prec, sucs, 0, meta) + 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 old marker line: %s" - % (line)) + repo.ui.write_err("invalid marker %s -> %s\n" + % (oldobject, oldsubjects)) err += 1 - finally: - f.close() - util.unlink(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(bin(oldobject), succs, - 0, meta) - cnt += 1 - except ValueError: - repo.ui.write_err("invalid marker %s -> %s\n" - % (oldobject, oldsubjects)) - err += 1 - util.unlink(repo.sjoin('obsoletemarkers')) + unlink.append(repo.sjoin('obsoletemarkers')) + tr.close() + for path in unlink: + util.unlink(path) + finally: + tr.release() finally: del repo._importoldobsolete l.release() @@ -686,13 +694,18 @@ if new != oldnode: lock = repo.lock() try: - meta = { - 'date': '%i %i' % util.makedate(), - 'user': ui.username(), - } - repo.obsstore.create(oldnode, [new], 0, meta) - repo._clearobsoletecache() - repo._turn_extinct_secret() + tr = repo.transaction('post-amend-obst') + try: + meta = { + 'date': '%i %i' % util.makedate(), + 'user': ui.username(), + } + repo.obsstore.create(tr, oldnode, [new], 0, meta) + tr.close() + repo._clearobsoletecache() + repo._turn_extinct_secret() + finally: + tr.release() finally: lock.release() return new @@ -897,15 +910,20 @@ % {'sub': short(sub), 'obj': short(obj)}) lock = self.lock() try: - meta = { - 'date': '%i %i' % util.makedate(), - 'user': ui.username(), - } - subs = (sub == nullid) and [] or [sub] - mid = self.obsstore.create(obj, subs, 0, meta) - self._clearobsoletecache() - self._turn_extinct_secret() - return mid + tr = self.transaction('add-obsolete') + try: + meta = { + 'date': '%i %i' % util.makedate(), + 'user': ui.username(), + } + subs = (sub == nullid) and [] or [sub] + mid = self.obsstore.create(tr, obj, subs, 0, meta) + tr.close() + self._clearobsoletecache() + self._turn_extinct_secret() + return mid + finally: + tr.release() finally: lock.release()