[PATCH 9 of 9] template: use template-engine for obsfate

Yuya Nishihara yuya at tcha.org
Tue Jul 11 11:06:13 EDT 2017


On Tue, 11 Jul 2017 11:16:03 +0200, Boris Feld wrote:
> Obsfate has a difficult task: summarize the obsolescence history
> (potentially spanning multiple obs-markers), aggregating the different
> values and all of this in multiple dimensions when there's a
> divergence.
> 
> This template seems quite complex, it felt complex during
> implementation using templates. I tried finding an existing template
> that was close to this complexity, successorssets was close but obsfate
> adds one more layer of nesting, so I didn't find a good example to
> mimic.
> 
> I'm pretty sure that implementing obsfate cleanly with the template
> engine can be done, but after spending several days, I'm afraid I won't
> be able to do it on my own. For example, I wasn't able to successfully
> format the users list using templates, I tried doing this:
>     
>     hg log -G -T '{obsfate % "obsolete: {get(obsfate, "verb")} by
> {join(get(obsfate, "users"), ', ')}\n"}'
> 
> Lately, I was thinking about sending a V2 that, instead of returning
> the formatted string, would returns an _hybrid object:
>     
> -    return _obsfateprinter(values, repo, repo.ui)
> +    gen = _obsfateprinter(values, repo, repo.ui)
> +    return _hybrid(gen, values, None, None)
> 
> This way people would be able to start customizing it (with template
> function "get") and we would be able to improve the implementation with
> potential syntactic sugar addition in the template engine.

Well, I don't have expertise in the obsolete thingy, though I'm (unfortunately)
a template expert.

Guessing from the PATCH 4, which has the following functions,

  obsfatedata: ctx => [succs, ...] => [(succs, markers), ...]

maybe we'll want a template function which converts 'succs' to 'markers' ?
Let's call it 'relatedmarkers' here.

  relatedmarkers: succs => [marker, ...]  (where marker is a _hybrid dict)

Then, a part of {obsfate} could probably be written as:

  {successorsets % "{relatedmarkers(successorset)
                     % "{get(marker, "verb")} ..."}"}

I think that's similar to what Jun suggested.


More information about the Mercurial-devel mailing list