diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -24,7 +24,6 @@ from mercurial.node import ( wdirrev, ) from mercurial.pycompat import open -from mercurial.thirdparty.jaraco.collections import Projection from mercurial import ( bookmarks, cmdutil, @@ -86,19 +85,6 @@ def _nothingtorebase(): return 1 -def retained_extras(): - """ - Yield the names of the extras to be retained. - """ - # graft - yield b'source' - yield b'intermediate-source' - - -def _save_extras(ctx, extra): - extra.update(Projection(retained_extras(), ctx.extra())) - - def _savebranch(ctx, extra): extra[b'branch'] = ctx.branch() @@ -199,7 +185,7 @@ class rebaseruntime: self.date = opts.get('date', None) e = opts.get('extrafn') # internal, used by e.g. hgsubversion - self.extrafns = [_save_extras] + self.extrafns = [rewriteutil.preserve_extras_on_rebase] if e: self.extrafns = [e] diff --git a/mercurial/rewriteutil.py b/mercurial/rewriteutil.py --- a/mercurial/rewriteutil.py +++ b/mercurial/rewriteutil.py @@ -27,6 +27,21 @@ from . import ( NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b') +# set of extra entry that should survive a rebase-like operation, extensible by extensions +retained_extras_on_rebase = { + b'source', + b'intermediate-source', +} + + +def preserve_extras_on_rebase(old_ctx, new_extra): + """preserve the relevant `extra` entry from old_ctx on rebase-like operation""" + new_extra.update( + (key, value) + for key, value in old_ctx.extra().items() + if key in retained_extras_on_rebase + ) + def _formatrevs(repo, revs, maxrevs=4): """returns a string summarizing revisions in a decent size diff --git a/mercurial/thirdparty/jaraco/__init__.py b/mercurial/thirdparty/jaraco/__init__.py deleted file mode 100644 diff --git a/mercurial/thirdparty/jaraco/collections.py b/mercurial/thirdparty/jaraco/collections.py deleted file mode 100644 --- a/mercurial/thirdparty/jaraco/collections.py +++ /dev/null @@ -1,56 +0,0 @@ -# adapted from jaraco.collections 3.9 - -import collections - - -class Projection(collections.abc.Mapping): - """ - Project a set of keys over a mapping - - >>> sample = {'a': 1, 'b': 2, 'c': 3} - >>> prj = Projection(['a', 'c', 'd'], sample) - >>> prj == {'a': 1, 'c': 3} - True - - Keys should only appear if they were specified and exist in the space. - - >>> sorted(list(prj.keys())) - ['a', 'c'] - - Attempting to access a key not in the projection - results in a KeyError. - - >>> prj['b'] - Traceback (most recent call last): - ... - KeyError: 'b' - - Use the projection to update another dict. - - >>> target = {'a': 2, 'b': 2} - >>> target.update(prj) - >>> target == {'a': 1, 'b': 2, 'c': 3} - True - - Also note that Projection keeps a reference to the original dict, so - if you modify the original dict, that could modify the Projection. - - >>> del sample['a'] - >>> dict(prj) - {'c': 3} - """ - - def __init__(self, keys, space): - self._keys = tuple(keys) - self._space = space - - def __getitem__(self, key): - if key not in self._keys: - raise KeyError(key) - return self._space[key] - - def __iter__(self): - return iter(set(self._keys).intersection(self._space)) - - def __len__(self): - return len(tuple(iter(self))) diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1303,7 +1303,6 @@ packages = [ 'mercurial.templates', 'mercurial.thirdparty', 'mercurial.thirdparty.attr', - 'mercurial.thirdparty.jaraco', 'mercurial.thirdparty.zope', 'mercurial.thirdparty.zope.interface', 'mercurial.upgrade_utils',