D3573: hgweb: extract code for emitting multiple changelist records
This revision was automatically updated to reflect the committed changes. Closed by commit rHG5989261a8356: hgweb: extract code for emitting multiple changelist records (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D3573?vs=8727&id=8736 REVISION DETAIL https://phab.mercurial-scm.org/D3573 AFFECTED FILES mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py CHANGE DETAILS diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -457,6 +457,22 @@ ) return entry +def changelistentries(web, revs, maxcount, parityfn): +"""Emit up to N records for an iterable of revisions.""" +repo = web.repo + +count = 0 +for rev in revs: +if count >= maxcount: +break + +count += 1 + +entry = changelistentry(web, repo[rev]) +entry['parity'] = next(parityfn) + +yield entry + def symrevorshortnode(req, ctx): if 'node' in req.qsparams: return templatefilters.revescape(req.qsparams['node']) diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -398,14 +398,8 @@ revs = [] if pos != -1: revs = web.repo.changelog.revs(pos, 0) -curcount = 0 -for rev in revs: -curcount += 1 -if curcount > revcount + 1: -break -entry = webutil.changelistentry(web, web.repo[rev]) -entry['parity'] = next(parity) +for entry in webutil.changelistentries(web, revs, revcount, parity): yield entry if shortlog: To: indygreg, #hg-reviewers, pulkit Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D3573: hgweb: extract code for emitting multiple changelist records
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY changelistentry() exists so extensions can easily monkeypatch the function to add additional metadata. In at least one case at Mozilla, we have an extension doing this where performance would greatly benefit if we were able to "batch fetch" metadata for all revisions that will eventually have their data set. By extracting the logic for "obtain records for N revisions" into a standalone function, we make it possible for a monkeypatched function to more efficiently bulk fetch data for N revisions. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D3573 AFFECTED FILES mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py CHANGE DETAILS diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -457,6 +457,22 @@ ) return entry +def changelistentries(web, revs, maxcount, parityfn): +"""Emit up to N records for an iterable of revisions.""" +repo = web.repo + +count = 0 +for rev in revs: +if count >= maxcount: +break + +count += 1 + +entry = changelistentry(web, repo[rev]) +entry['parity'] = next(parityfn) + +yield entry + def symrevorshortnode(req, ctx): if 'node' in req.qsparams: return templatefilters.revescape(req.qsparams['node']) diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -398,14 +398,8 @@ revs = [] if pos != -1: revs = web.repo.changelog.revs(pos, 0) -curcount = 0 -for rev in revs: -curcount += 1 -if curcount > revcount + 1: -break -entry = webutil.changelistentry(web, web.repo[rev]) -entry['parity'] = next(parity) +for entry in webutil.changelistentries(web, revs, revcount, parity): yield entry if shortlog: To: indygreg, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel