This is an archive of the discontinued Mercurial Phabricator instance.

hgweb: extract entries() to standalone function
ClosedPublic

Authored by indygreg on Mar 12 2018, 5:16 PM.

Details

Summary

There was some real wonkiness going on here. Essentially, the
inline function was being executed with default arguments because
a function reference was passed as-is into the templater. That
seemed odd. So now we pass an explicit generator of the function
result.

Moving this code out of makeindex() makes makeindex() small enough
to reason about. This makes it easier to see weird things, like the
fact that we're calling self.refresh() twice. Why, I'm not sure.
I'm also not sure why we need to call updatereqenv() to possibly
update the SERVER_NAME, SERVER_PORT, and SCRIPT_NAME variables as
part of rendering an index. I'll dig into these things in subsequent
commits.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Mar 12 2018, 5:16 PM
durin42 accepted this revision.Mar 12 2018, 5:25 PM
This revision is now accepted and ready to land.Mar 12 2018, 5:25 PM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Mar 17 2018, 11:41 AM

Essentially, the inline function was being executed with default arguments
because a function reference was passed as-is into the templater. That
seemed odd. So now we pass an explicit generator of the function
result.

This move is wrong because a template keyword may be evaluated more
than once. If it's a generator, the first {entries} consumes the entire data
and the second {entries} would be empty.

Can you send a follow up? entries can be a list or a function returning
a generator.

yuja added a comment.Mar 19 2018, 10:01 AM

entries can be a list or a function returning a generator.

I'm going to add a wrapper class for a generator of mappings, so this can be
addressed later.