changeset 50440:2cd959fe631a

extras: extract function for projecting names from a gettable object
author Jason R. Coombs <jaraco@jaraco.com>
date Tue, 21 Mar 2023 17:17:09 -0400
parents c0fbd63d66a7
children e8f1e0e295bb
files hgext/rebase.py
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Sat Mar 25 23:02:33 2023 +0100
+++ b/hgext/rebase.py	Tue Mar 21 17:17:09 2023 -0400
@@ -84,13 +84,19 @@
     return 1
 
 
+graft_extras = b'source', b'intermediate-source'
+
+
+def _project(orig, names):
+    """Project a subset of names from orig."""
+    values = (orig.get(name, None) for name in names)
+    return {
+        name: value for name, value in zip(names, values) if value is not None
+    }
+
+
 def _savegraft(ctx, extra):
-    s = ctx.extra().get(b'source', None)
-    if s is not None:
-        extra[b'source'] = s
-    s = ctx.extra().get(b'intermediate-source', None)
-    if s is not None:
-        extra[b'intermediate-source'] = s
+    extra.update(_project(ctx.extra(), graft_extras))
 
 
 def _savebranch(ctx, extra):