Re: [PATCH 6 of 9 V3] template: compute user in obsfateusers
On Wed, 23 Aug 2017 16:31:21 +0200, Boris Feld wrote: > On Wed, 2017-08-23 at 00:02 +0900, Yuya Nishihara wrote: > > On Mon, 21 Aug 2017 10:43:58 +0200, Boris Feld wrote: > > > # HG changeset patch > > > # User Boris Feld > > > # Date 1499088840 -7200 > > > # Mon Jul 03 15:34:00 2017 +0200 > > > # Node ID 2fee3b06f7b09f35dcfa312b645cf94090c11fb9 > > > # Parent 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363 > > > # EXP-Topic obsfatetemplate > > > template: compute user in obsfateusers > > > +def _successorsetusers(successorset, markers): > > > +""" Returns a sorted list of markers users without duplicates > > > +""" > > > +if not markers: > > > +return {} > > > + > > > +# Check that user is present in meta > > > +markersmeta = [dict(m[3]) for m in markers] > > > +users = set(meta.get('user') for meta in markersmeta if > > > meta.get('user')) > > > + > > > +return {'users': sorted(users)} > > > > [...] > > > > > +@templatefunc('obsfateusers(successors, markers)') > > > +def obsfateusers(context, mapping, args): > > > +""" Compute obsfate related information based on successors > > > and markers > > > +""" > > > +successors = evalfuncarg(context, mapping, args[0]) > > > +markers = evalfuncarg(context, mapping, args[1]) > > > +data = obsutil._successorsetusers(successors, markers) > > > + > > > +_hybrid = templatekw._hybrid > > > + > > > +def makemap(x): > > > +return x > > > + > > > +def joinfmt(d): > > > +return d > > > + > > > +return _hybrid(None, [data], makemap, joinfmt) > > > > Why isn't this a list of users, but a list of dict of list of users? > > It was a artifact from the previous version of the series. It was meant > to permit this notation: > > obsfateusers(successors, markers) % "{if(users, " by {join(users, ", > ")}")}" > > I've tried cleaning it, code is cleaner and the template is slighty > less clean now: > > {if(obsfateusers(markers), " by {join(obsfateusers(markers), ", ")}")} obsfateusers(markers) could be a templatealias or a keyword in mapfile. # .hgrc [templatealias] x = obsfateusers(markers) # mapfile x = '{join(obsfateusers(markers), ", ")}' ... = '{if(x, " by {x}")}' I don't think it's good idea to design a template keyword/function for a specific use case. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 6 of 9 V3] template: compute user in obsfateusers
On Wed, 2017-08-23 at 00:02 +0900, Yuya Nishihara wrote: > On Mon, 21 Aug 2017 10:43:58 +0200, Boris Feld wrote: > > # HG changeset patch > > # User Boris Feld > > # Date 1499088840 -7200 > > # Mon Jul 03 15:34:00 2017 +0200 > > # Node ID 2fee3b06f7b09f35dcfa312b645cf94090c11fb9 > > # Parent 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363 > > # EXP-Topic obsfatetemplate > > template: compute user in obsfateusers > > +def _successorsetusers(successorset, markers): > > +""" Returns a sorted list of markers users without duplicates > > +""" > > +if not markers: > > +return {} > > + > > +# Check that user is present in meta > > +markersmeta = [dict(m[3]) for m in markers] > > +users = set(meta.get('user') for meta in markersmeta if > > meta.get('user')) > > + > > +return {'users': sorted(users)} > > [...] > > > +@templatefunc('obsfateusers(successors, markers)') > > +def obsfateusers(context, mapping, args): > > +""" Compute obsfate related information based on successors > > and markers > > +""" > > +successors = evalfuncarg(context, mapping, args[0]) > > +markers = evalfuncarg(context, mapping, args[1]) > > +data = obsutil._successorsetusers(successors, markers) > > + > > +_hybrid = templatekw._hybrid > > + > > +def makemap(x): > > +return x > > + > > +def joinfmt(d): > > +return d > > + > > +return _hybrid(None, [data], makemap, joinfmt) > > Why isn't this a list of users, but a list of dict of list of users? It was a artifact from the previous version of the series. It was meant to permit this notation: obsfateusers(successors, markers) % "{if(users, " by {join(users, ", ")}")}" I've tried cleaning it, code is cleaner and the template is slighty less clean now: {if(obsfateusers(markers), " by {join(obsfateusers(markers), ", ")}")} ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 6 of 9 V3] template: compute user in obsfateusers
On Mon, 21 Aug 2017 10:43:58 +0200, Boris Feld wrote: > # HG changeset patch > # User Boris Feld > # Date 1499088840 -7200 > # Mon Jul 03 15:34:00 2017 +0200 > # Node ID 2fee3b06f7b09f35dcfa312b645cf94090c11fb9 > # Parent 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363 > # EXP-Topic obsfatetemplate > template: compute user in obsfateusers > +def _successorsetusers(successorset, markers): > +""" Returns a sorted list of markers users without duplicates > +""" > +if not markers: > +return {} > + > +# Check that user is present in meta > +markersmeta = [dict(m[3]) for m in markers] > +users = set(meta.get('user') for meta in markersmeta if meta.get('user')) > + > +return {'users': sorted(users)} [...] > +@templatefunc('obsfateusers(successors, markers)') > +def obsfateusers(context, mapping, args): > +""" Compute obsfate related information based on successors and markers > +""" > +successors = evalfuncarg(context, mapping, args[0]) > +markers = evalfuncarg(context, mapping, args[1]) > +data = obsutil._successorsetusers(successors, markers) > + > +_hybrid = templatekw._hybrid > + > +def makemap(x): > +return x > + > +def joinfmt(d): > +return d > + > +return _hybrid(None, [data], makemap, joinfmt) Why isn't this a list of users, but a list of dict of list of users? ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 6 of 9 V3] template: compute user in obsfateusers
On Mon, 2017-08-21 at 12:55 +0200, Denis Laxalde wrote: > Boris Feld a écrit : > > # HG changeset patch > > # User Boris Feld > > # Date 1499088840 -7200 > > # Mon Jul 03 15:34:00 2017 +0200 > > # Node ID 2fee3b06f7b09f35dcfa312b645cf94090c11fb9 > > # Parent 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363 > > # EXP-Topic obsfatetemplate > > template: compute user in obsfateusers > > > > Extract, deduplicate users informations from obs markers in order > > to display > > them. > > > > Print all users for the moment, we might want to display users only > > in verbose > > mode later. > > > > diff -r 66a2b0407c8c -r 2fee3b06f7b0 mercurial/obsutil.py > > --- a/mercurial/obsutil.py Mon Jul 03 15:33:27 2017 +0200 > > +++ b/mercurial/obsutil.py Mon Jul 03 15:34:00 2017 +0200 > > @@ -579,6 +579,18 @@ > > verb = 'split' > > return {'verb': verb} > > > > +def _successorsetusers(successorset, markers): > > +""" Returns a sorted list of markers users without duplicates > > +""" > > +if not markers: > > +return {} > > + > > +# Check that user is present in meta > > +markersmeta = [dict(m[3]) for m in markers] > > +users = set(meta.get('user') for meta in markersmeta if > > meta.get('user')) > > + > > +return {'users': sorted(users)} > > "users" set might be empty, do we want an empty dict instead in this > case? I think we want to distinguish the case where we don't have any marker (empty dict) from the case markers are missing users information (empty 'users' list) which shouldn't be frequent. We could also returns directly the users, the dict is an artifact of the previous version of this series. > > > + > > def successorsandmarkers(repo, ctx): > > """compute the raw data needed for computing obsfate > > Returns a list of dict, one dict per successors set > > diff -r 66a2b0407c8c -r 2fee3b06f7b0 mercurial/templater.py > > --- a/mercurial/templater.pyMon Jul 03 15:33:27 2017 +0200 > > +++ b/mercurial/templater.pyMon Jul 03 15:34:00 2017 +0200 > > @@ -859,6 +859,24 @@ > > > > return obsutil._successorsetverb(successors, markers)['verb'] > > > > +@templatefunc('obsfateusers(successors, markers)') > > +def obsfateusers(context, mapping, args): > > +""" Compute obsfate related information based on successors > > and markers > > +""" > > +successors = evalfuncarg(context, mapping, args[0]) > > +markers = evalfuncarg(context, mapping, args[1]) > > +data = obsutil._successorsetusers(successors, markers) > > + > > +_hybrid = templatekw._hybrid > > + > > +def makemap(x): > > +return x > > + > > +def joinfmt(d): > > +return d > > + > > +return _hybrid(None, [data], makemap, joinfmt) > > + > > @templatefunc('relpath(path)') > > def relpath(context, mapping, args): > > """Convert a repository-absolute path into a filesystem path > > relative to ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 6 of 9 V3] template: compute user in obsfateusers
Boris Feld a écrit : # HG changeset patch # User Boris Feld # Date 1499088840 -7200 # Mon Jul 03 15:34:00 2017 +0200 # Node ID 2fee3b06f7b09f35dcfa312b645cf94090c11fb9 # Parent 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363 # EXP-Topic obsfatetemplate template: compute user in obsfateusers Extract, deduplicate users informations from obs markers in order to display them. Print all users for the moment, we might want to display users only in verbose mode later. diff -r 66a2b0407c8c -r 2fee3b06f7b0 mercurial/obsutil.py --- a/mercurial/obsutil.py Mon Jul 03 15:33:27 2017 +0200 +++ b/mercurial/obsutil.py Mon Jul 03 15:34:00 2017 +0200 @@ -579,6 +579,18 @@ verb = 'split' return {'verb': verb} +def _successorsetusers(successorset, markers): +""" Returns a sorted list of markers users without duplicates +""" +if not markers: +return {} + +# Check that user is present in meta +markersmeta = [dict(m[3]) for m in markers] +users = set(meta.get('user') for meta in markersmeta if meta.get('user')) + +return {'users': sorted(users)} "users" set might be empty, do we want an empty dict instead in this case? + def successorsandmarkers(repo, ctx): """compute the raw data needed for computing obsfate Returns a list of dict, one dict per successors set diff -r 66a2b0407c8c -r 2fee3b06f7b0 mercurial/templater.py --- a/mercurial/templater.pyMon Jul 03 15:33:27 2017 +0200 +++ b/mercurial/templater.pyMon Jul 03 15:34:00 2017 +0200 @@ -859,6 +859,24 @@ return obsutil._successorsetverb(successors, markers)['verb'] +@templatefunc('obsfateusers(successors, markers)') +def obsfateusers(context, mapping, args): +""" Compute obsfate related information based on successors and markers +""" +successors = evalfuncarg(context, mapping, args[0]) +markers = evalfuncarg(context, mapping, args[1]) +data = obsutil._successorsetusers(successors, markers) + +_hybrid = templatekw._hybrid + +def makemap(x): +return x + +def joinfmt(d): +return d + +return _hybrid(None, [data], makemap, joinfmt) + @templatefunc('relpath(path)') def relpath(context, mapping, args): """Convert a repository-absolute path into a filesystem path relative to ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel