Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
34846:f05a6e015ecc | 34847:e27f1f04c2cf |
---|---|
781 markersmeta = [dict(m[3]) for m in markers] | 781 markersmeta = [dict(m[3]) for m in markers] |
782 operations = set(meta.get('operation') for meta in markersmeta | 782 operations = set(meta.get('operation') for meta in markersmeta |
783 if meta.get('operation')) | 783 if meta.get('operation')) |
784 | 784 |
785 return sorted(operations) | 785 return sorted(operations) |
786 | |
787 def obsfateprinter(successors, markers, ui): | |
788 """ Build a obsfate string for a single successorset using all obsfate | |
789 related function defined in obsutil | |
790 """ | |
791 line = [] | |
792 | |
793 # Verb | |
794 line.append(successorsetverb(successors)) | |
795 | |
796 # Operations | |
797 operations = markersoperations(markers) | |
798 if operations: | |
799 line.append(" using %s" % ", ".join(operations)) | |
800 | |
801 # Successors | |
802 if successors: | |
803 fmtsuccessors = [successors.joinfmt(succ) for succ in successors] | |
804 line.append(" as %s" % ", ".join(fmtsuccessors)) | |
805 | |
806 # Users | |
807 users = markersusers(markers) | |
808 | |
809 if users: | |
810 line.append(" by %s" % ", ".join(users)) | |
811 | |
812 # Date | |
813 dates = markersdates(markers) | |
814 | |
815 min_date = min(dates) | |
816 max_date = max(dates) | |
817 | |
818 if min_date == max_date: | |
819 fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2') | |
820 line.append(" (at %s)" % fmtmin_date) | |
821 else: | |
822 fmtmin_date = util.datestr(min_date, '%Y-%m-%d %H:%M %1%2') | |
823 fmtmax_date = util.datestr(max_date, '%Y-%m-%d %H:%M %1%2') | |
824 line.append(" (between %s and %s)" % (fmtmin_date, fmtmax_date)) | |
825 | |
826 return "".join(line) |