comparison tests/printrevset.py @ 45565:c1d0f83d62c4

log: introduce struct that carries log traversal options I tried to refactor logcmdutil.getrevs() without using an options struct, but none of these attempts didn't work out. Since every stage of getrevs() needs various log command options (e.g. both matcher and revset query need file patterns), it isn't possible to cleanly split getrevs() into a command layer and a core logic. So, this patch introduces a named struct to carry command options in slightly abstracted way, which will be later used by "hg grep" and "hg churn". More fields will be added to the walkopt struct. Type hints aren't verified. I couldn't figure out how to teach pytype to load its own attr type stubs in place of our .thirdparty.attr. Conditional import didn't work. s/^from \.thirdparty // is the only way I found pytype could parse the @attr.ib decorator.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Sep 2020 21:06:16 +0900
parents a717de1cb624
children 6000f5b25c9b
comparison
equal deleted inserted replaced
45564:a717de1cb624 45565:c1d0f83d62c4
1 from __future__ import absolute_import 1 from __future__ import absolute_import
2 from mercurial.thirdparty import attr
2 from mercurial import ( 3 from mercurial import (
3 cmdutil, 4 cmdutil,
4 commands, 5 commands,
5 extensions, 6 extensions,
6 logcmdutil, 7 logcmdutil,
9 ) 10 )
10 11
11 from mercurial.utils import stringutil 12 from mercurial.utils import stringutil
12 13
13 14
14 def logrevset(repo, pats, opts): 15 def logrevset(repo, wopts):
15 revs = logcmdutil._initialrevs(repo, opts) 16 revs = logcmdutil._initialrevs(repo, wopts)
16 if not revs: 17 if not revs:
17 return None 18 return None
18 match, pats, slowpath = logcmdutil._makematcher(repo, revs, pats, opts) 19 match, pats, slowpath = logcmdutil._makematcher(repo, revs, wopts)
19 return logcmdutil._makerevset(repo, pats, slowpath, opts) 20 wopts = attr.evolve(wopts, pats=pats)
21 return logcmdutil._makerevset(repo, wopts, slowpath)
20 22
21 23
22 def uisetup(ui): 24 def uisetup(ui):
23 def printrevset(orig, repo, pats, opts): 25 def printrevset(orig, repo, wopts):
24 revs, filematcher = orig(repo, pats, opts) 26 revs, filematcher = orig(repo, wopts)
25 if opts.get(b'print_revset'): 27 if wopts.opts.get(b'print_revset'):
26 expr = logrevset(repo, pats, opts) 28 expr = logrevset(repo, wopts)
27 if expr: 29 if expr:
28 tree = revsetlang.parse(expr) 30 tree = revsetlang.parse(expr)
29 tree = revsetlang.analyze(tree) 31 tree = revsetlang.analyze(tree)
30 else: 32 else:
31 tree = [] 33 tree = []
32 ui = repo.ui 34 ui = repo.ui
33 ui.write(b'%s\n' % stringutil.pprint(opts.get(b'rev', []))) 35 ui.write(b'%s\n' % stringutil.pprint(wopts.opts.get(b'rev', [])))
34 ui.write(revsetlang.prettyformat(tree) + b'\n') 36 ui.write(revsetlang.prettyformat(tree) + b'\n')
35 ui.write(stringutil.prettyrepr(revs) + b'\n') 37 ui.write(stringutil.prettyrepr(revs) + b'\n')
36 revs = smartset.baseset() # display no revisions 38 revs = smartset.baseset() # display no revisions
37 return revs, filematcher 39 return revs, filematcher
38 40