diff hgext3rd/evolve/templatekw.py @ 2594:a3fbe5293bf6 stable

merge with stable
author Boris Feld <boris.feld@octobus.net>
date Fri, 16 Jun 2017 11:32:21 +0200
parents 606722a686ef 1991935fb603
children 54ac473663ff 3d432af2f6cd
line wrap: on
line diff
--- a/hgext3rd/evolve/templatekw.py	Wed May 31 22:15:34 2017 +0200
+++ b/hgext3rd/evolve/templatekw.py	Fri Jun 16 11:32:21 2017 +0200
@@ -91,7 +91,7 @@
     if not ctx.obsolete():
         return ''
 
-    ssets = closestsuccessors(repo, ctx.node())
+    ssets, _ = closestsuccessors(repo, ctx.node())
 
     data = []
     gen = []
@@ -106,13 +106,66 @@
     return templatekw._hybrid(iter(gen), data, lambda x: {'successorset': x},
                               lambda d: d["successorset"])
 
-@eh.templatekw("obsfate_quiet")
-def showobsfate_quiet(repo, ctx, templ, **args):
+def obsfatedefaulttempl():
+    """ Returns a dict with the default templates for obs fate
+    """
+    # Prepare templates
+    verbtempl = '{verb}'
+    usertempl = '{if(users, " by {join(users, ", ")}")}'
+    succtempl = '{if(successors, " as ")}{successors}' # Bypass if limitation
+    datetempleq = ' (at {min_date|isodate})'
+    datetemplnoteq = ' (between {min_date|isodate} and {max_date|isodate})'
+    datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq)
+    newline = '\n'
+
+    # Assemble them
+    return {
+        'obsfate_quiet': verbtempl + succtempl + newline,
+        'obsfate': verbtempl + usertempl + succtempl + newline,
+        'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl + newline
+    }
+
+@eh.templatekw("obsfate")
+def showobsfate(repo, ctx, **args):
     if not ctx.obsolete():
         return ''
 
-    successorssets = closestsuccessors(repo, ctx.node())
-    return obshistory._humanizedobsfate(*obshistory._getobsfateandsuccs(repo, ctx, successorssets))
+    successorssets, pathcache = closestsuccessors(repo, ctx.node())
+
+    # closestsuccessors returns an empty list for pruned revisions, remap it
+    # into a list containing en empty list for future processing
+    if successorssets == []:
+        successorssets = [[]]
+
+    values = []
+    for successorset in successorssets:
+        raw = obshistory._preparesuccessorset(successorset, pathcache)
+
+        # As we can't do something like
+        # "{join(map(nodeshort, successors), ', '}" in template, manually
+        # create a correct textual representation
+        gen = ', '.join(map(node.short, raw['successors']))
+
+        makemap = lambda x: {'successor': x}
+        joinfmt = lambda d: "%s" % d['successor']
+        raw['successors'] = templatekw._hybrid(gen, raw['successors'], makemap,
+                                               joinfmt)
+
+        values.append(raw)
+
+    # Insert default obsfate templates
+    args['templ'].cache.update(obsfatedefaulttempl())
+
+    if repo.ui.quiet:
+        name = "obsfate_quiet"
+    elif repo.ui.verbose:
+        name = "obsfate_verbose"
+    elif repo.ui.debugflag:
+        name = "obsfate_debug"
+    else:
+        name = "obsfate"
+
+    return templatekw.showlist(name, values, args, separator=' + ')
 
 # copy from mercurial.obsolete with a small change to stop at first known changeset.
 
@@ -127,6 +180,9 @@
     # set version of above list for fast loop detection
     # element added to "toproceed" must be added here
     stackedset = set(toproceed)
+
+    pathscache = {}
+
     if cache is None:
         cache = {}
     while toproceed:
@@ -156,6 +212,7 @@
                             # of one of those successors we add it to the
                             # `toproceed` stack and stop all work for this
                             # iteration.
+                            pathscache.setdefault(suc, []).append((current, mark))
                             toproceed.append(suc)
                             stackedset.add(suc)
                             break
@@ -195,4 +252,5 @@
                         seen.append(setversion)
                 final.reverse() # put small successors set first
                 cache[current] = final
-    return cache[initialnode]
+
+    return cache[initialnode], pathscache