# HG changeset patch # User Pierre-Yves David # Date 1523972758 -7200 # Node ID 1043e9c5435555fbb3e3b2862ef6384caf567114 # Parent 0407965ae79eca1cc1407974c40f03e7013e2693 compat: adapt `amend --patch` to the new `patch.extract` API diff -r 0407965ae79e -r 1043e9c54355 hgext3rd/evolve/cmdrewrite.py --- a/hgext3rd/evolve/cmdrewrite.py Tue Apr 17 15:04:15 2018 +0200 +++ b/hgext3rd/evolve/cmdrewrite.py Tue Apr 17 15:45:58 2018 +0200 @@ -11,6 +11,7 @@ from __future__ import absolute_import +import contextlib import random from mercurial import ( @@ -226,34 +227,42 @@ """utility function to use filestore and patchrepo to apply a patch to the repository with metadata being extracted from the patch""" metadata = patch.extract(ui, fp) + if util.safehasattr(metadata, 'get'): # < hg-4.6 + @contextlib.contextmanager + def patchcontext(): + yield metadata + patchcontext = patchcontext() + else: + patchcontext = metadata pold = old.p1() - # store the metadata from the patch to variables - parents = (metadata.get('p1'), metadata.get('p2')) - date = metadata.get('date') or old.date() - branch = metadata.get('branch') or old.branch() - user = metadata.get('user') or old.user() - # XXX: we must extract extras from the patchfile too - extra = old.extra() - message = metadata.get('message') or old.description() - store = patch.filestore() - fp.seek(0) - try: - files = set() - # beware: next line may raise a PatchError to be handled by the caller - # of this function - patch.patchrepo(ui, repo, pold, store, fp, 1, '', - files=files, eolmode=None) + with patchcontext as metadata: + # store the metadata from the patch to variables + parents = (metadata.get('p1'), metadata.get('p2')) + date = metadata.get('date') or old.date() + branch = metadata.get('branch') or old.branch() + user = metadata.get('user') or old.user() + # XXX: we must extract extras from the patchfile too + extra = old.extra() + message = metadata.get('message') or old.description() + store = patch.filestore() + fp.seek(0) + try: + files = set() + # beware: next line may raise a PatchError to be handled by the caller + # of this function + patch.patchrepo(ui, repo, pold, store, fp, 1, '', + files=files, eolmode=None) - memctx = context.memctx(repo, parents, message, files=files, - filectxfn=store, - user=user, - date=date, - branch=branch, - extra=extra) - newcm = memctx.commit() - finally: - store.close() + memctx = context.memctx(repo, parents, message, files=files, + filectxfn=store, + user=user, + date=date, + branch=branch, + extra=extra) + newcm = memctx.commit() + finally: + store.close() return newcm def _writectxmetadata(repo, ctx, fp):