obsfate: refactor obsfate data computing
Refactor how obsfate data are computed in order to reuse this logic later when
hooking on default log output.
--- a/hgext3rd/evolve/templatekw.py Thu Jun 29 16:49:33 2017 +0200
+++ b/hgext3rd/evolve/templatekw.py Mon Jun 26 17:19:03 2017 +0200
@@ -140,10 +140,12 @@
'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl,
}
-@eh.templatekw("obsfate")
-def showobsfate(repo, ctx, **args):
+def obsfatedata(repo, ctx):
+ """compute the raw data needed for computing obsfate
+ Returns a list of dict
+ """
if not ctx.obsolete():
- return ''
+ return None
successorssets, pathcache = closestsuccessors(repo, ctx.node())
@@ -172,7 +174,20 @@
values = []
for sset, rawmarkers in fullsuccessorsets:
raw = obshistory.preparesuccessorset(sset, rawmarkers)
+ values.append(raw)
+ return values
+
+@eh.templatekw("obsfate")
+def showobsfate(repo, ctx, **args):
+ # Get the needed obsfate data
+ values = obsfatedata(repo, ctx)
+
+ if values is None:
+ return ''
+
+ # Format each successorset successors list
+ for raw in values:
# As we can't do something like
# "{join(map(nodeshort, successors), ', '}" in template, manually
# create a correct textual representation
@@ -183,8 +198,7 @@
raw['successors'] = templatekw._hybrid(gen, raw['successors'], makemap,
joinfmt)
- values.append(raw)
-
+ # And then format them
# Insert default obsfate templates
args['templ'].cache.update(obsfatedefaulttempl(repo.ui))