Re: [PATCH 1 of 7 V3] templatekw: introduce obsfate keyword
On Wed, 2017-10-18 at 22:12 +0900, Yuya Nishihara wrote: > On Tue, 17 Oct 2017 17:14:02 +0200, Boris Feld wrote: > > # HG changeset patch > > # User Boris Feld> > # Date 1507218176 -7200 > > # Thu Oct 05 17:42:56 2017 +0200 > > # Node ID fc6e8b2484a3eaedd9e4b8ec10f3728b57bfbebe > > # Parent 68e0bcb903572cb3641c1b1ac11bdcf47d4ff5ac > > # EXP-Topic obsfatekeyword > > # Available At https://bitbucket.org/octobus/mercurial-devel/ > > # hg pull https://bitbucket.org/octobus/mercurial-deve > > l/ -r fc6e8b2484a3 > > templatekw: introduce obsfate keyword > > Queued the series, thanks. Thank you, I will send the required follow-up right now and prepare the others for after the release. > > > +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] > > We'll make it not depend on templater stuff because this function > will be > called by changeset_printer. Please send a follow up after the > release. > > > +line.append(" as %s" % ", ".join(fmtsuccessors)) > > + > > +# Users > > +users = markersusers(markers) > > + > > +if users: > > +line.append(" by %s" % ", ".join(users)) > > These "using" "as" "by" will need to be translated at once. Please > send a > follow up after the release. > > > +# Date > > +dates = markersdates(markers) > > + > > +min_date = min(dates) > > +max_date = max(dates) > > If dates is empty, ValueError will be raised. Please send a follow > up. > > And our coding style still discourage the use of underscore. > https://www.mercurial-scm.org/wiki/CodingStyle#Naming_conventions > > > +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) > > diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py > > --- a/mercurial/templatekw.py > > +++ b/mercurial/templatekw.py > > @@ -600,6 +600,24 @@ > > # rev and node are completely different from changeset's. > > return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': > > mhex}) > > > > +@templatekeyword('obsfate') > > +def showobsfate(**args): > > +""" this function returns a list containing pre-formatted > > obsfate strings. > > + > > +This function will be replaced by templates fragments when we > > will have > > +the verbosity templatekw available. > > +""" > > Changed this to a comment to hide {ofsfate} in help. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 1 of 7 V3] templatekw: introduce obsfate keyword
On Tue, 17 Oct 2017 17:14:02 +0200, Boris Feld wrote: > # HG changeset patch > # User Boris Feld> # Date 1507218176 -7200 > # Thu Oct 05 17:42:56 2017 +0200 > # Node ID fc6e8b2484a3eaedd9e4b8ec10f3728b57bfbebe > # Parent 68e0bcb903572cb3641c1b1ac11bdcf47d4ff5ac > # EXP-Topic obsfatekeyword > # Available At https://bitbucket.org/octobus/mercurial-devel/ > # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r > fc6e8b2484a3 > templatekw: introduce obsfate keyword Queued the series, thanks. > +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] We'll make it not depend on templater stuff because this function will be called by changeset_printer. Please send a follow up after the release. > +line.append(" as %s" % ", ".join(fmtsuccessors)) > + > +# Users > +users = markersusers(markers) > + > +if users: > +line.append(" by %s" % ", ".join(users)) These "using" "as" "by" will need to be translated at once. Please send a follow up after the release. > +# Date > +dates = markersdates(markers) > + > +min_date = min(dates) > +max_date = max(dates) If dates is empty, ValueError will be raised. Please send a follow up. And our coding style still discourage the use of underscore. https://www.mercurial-scm.org/wiki/CodingStyle#Naming_conventions > +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) > diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py > --- a/mercurial/templatekw.py > +++ b/mercurial/templatekw.py > @@ -600,6 +600,24 @@ > # rev and node are completely different from changeset's. > return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex}) > > +@templatekeyword('obsfate') > +def showobsfate(**args): > +""" this function returns a list containing pre-formatted obsfate > strings. > + > +This function will be replaced by templates fragments when we will have > +the verbosity templatekw available. > +""" Changed this to a comment to hide {ofsfate} in help. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
[PATCH 1 of 7 V3] templatekw: introduce obsfate keyword
# HG changeset patch # User Boris Feld# Date 1507218176 -7200 # Thu Oct 05 17:42:56 2017 +0200 # Node ID fc6e8b2484a3eaedd9e4b8ec10f3728b57bfbebe # Parent 68e0bcb903572cb3641c1b1ac11bdcf47d4ff5ac # EXP-Topic obsfatekeyword # Available At https://bitbucket.org/octobus/mercurial-devel/ # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fc6e8b2484a3 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 +) 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"}")} diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py --- a/mercurial/obsutil.py +++ b/mercurial/obsutil.py @@ -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) diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -600,6 +600,24 @@ # rev and node are completely different from changeset's. return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex}) +@templatekeyword('obsfate') +def showobsfate(**args): +""" this function returns a list containing pre-formatted obsfate strings. + +This function will be replaced by templates fragments when we will have +the verbosity templatekw available. +""" +succsandmarkers = showsuccsandmarkers(**args) + +ui = args['ui'] + +values = [] + +for x in succsandmarkers: +values.append(obsutil.obsfateprinter(x['successors'], x['markers'], ui)) + +return showlist("fate", values, args) + def shownames(namespace, **args): """helper method to generate a template keyword for a namespace""" args = pycompat.byteskwargs(args) diff --git a/tests/test-obsolete-distributed.t b/tests/test-obsolete-distributed.t --- a/tests/test-obsolete-distributed.t +++ b/tests/test-obsolete-distributed.t @@ -16,15 +16,8 @@ > evolution = all > [phases] > publish = False - > [templates] - > obsfatesuccessors = "{if(successors, " as ")}{join(successors, ", ")}" - > obsfateverb = "{obsfateverb(successors)}" - > obsfateoperations = "{if(obsfateoperations(markers), " using {join(obsfateoperations(markers), ", ")}")}" - > obsfateusers = "{if(obsfateusers(markers), " by {join(obsfateusers(markers), ", ")}")}" - > obsfatedate = "{if(obsfatedate(markers), "{ifeq(min(obsfatedate(markers)), max(obsfatedate(markers)), " (at {min(obsfatedate(markers))|isodate})", " (between {min(obsfatedate(markers))|isodate} and {max(obsfatedate(markers))|isodate})")}")}" - > obsfate = "{obsfateverb}{obsfateoperations}{obsfatesuccessors}{obsfateusers}{obsfatedate}; " > [ui] - > logtemplate= {rev}:{node|short} {desc} {if(succsandmarkers, "[{succsandmarkers % "{obsfate}"}]")}\n + > logtemplate= {rev}:{node|short} {desc}{if(obsfate, " [{join(obsfate, "; ")}]")}\n > EOF Check distributed chain building @@ -63,7 +56,7 @@ | | o 2:7f6b0a6f5c25 c_A1 |/