diff mercurial/obsutil.py @ 34847:e27f1f04c2cf

templatekw: introduce obsfate keyword Introduce an obsfate printer that uses all helpers functions defined in obsutil to get all the obsfate-related data and format a string according to the current format in test-obsmarker-template.t. Then, introduce an obsfate templatekw that uses the obsfateprinter to return a list of strings. The goal is not to replace existing obsfate template functions but to propose a default, good-enough and easily usable obsfate definition for end-users that don't want to customize it. Such output would ultimately get included in the default log output. Here are some output examples for a commit amended: rewritten using amend as 5:a9b1f8652753 by test (at 1970-01-01 00:00 +0000) Next patches will make the output dependent on the verbosity. Exemple of use-cases: For having the obsfate on a single-line between brackets: {if(obsfate, " [{join(obsfate, "; ")}]")} For having the obsfate in several lines: {if(obsfate, "{obsfate % " Obsfate: {fate}\n"}")}
author Boris Feld <boris.feld@octobus.net>
date Thu, 05 Oct 2017 17:42:56 +0200
parents 2fd06499dc8e
children 62a4ccf9784a
line wrap: on
line diff
--- a/mercurial/obsutil.py	Tue Oct 10 02:25:03 2017 +0530
+++ b/mercurial/obsutil.py	Thu Oct 05 17:42:56 2017 +0200
@@ -783,3 +783,44 @@
                      if meta.get('operation'))
 
     return sorted(operations)
+
+def obsfateprinter(successors, markers, ui):
+    """ Build a obsfate string for a single successorset using all obsfate
+    related function defined in obsutil
+    """
+    line = []
+
+    # Verb
+    line.append(successorsetverb(successors))
+
+    # Operations
+    operations = markersoperations(markers)
+    if operations:
+        line.append(" using %s" % ", ".join(operations))
+
+    # Successors
+    if successors:
+        fmtsuccessors = [successors.joinfmt(succ) for succ in successors]
+        line.append(" as %s" % ", ".join(fmtsuccessors))
+
+    # Users
+    users = markersusers(markers)
+
+    if users:
+        line.append(" by %s" % ", ".join(users))
+
+    # Date
+    dates = markersdates(markers)
+
+    min_date = min(dates)
+    max_date = max(dates)
+
+    if min_date == max_date:
+        fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2')
+        line.append(" (at %s)" % fmtmin_date)
+    else:
+        fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2')
+        fmtmax_date = util.datestr(max_date, '%Y-%m-%d %H:%M %1%2')
+        line.append(" (between %s and %s)" % (fmtmin_date, fmtmax_date))
+
+    return "".join(line)