# HG changeset patch # User Yuya Nishihara <y...@tcha.org> # Date 1516511272 -32400 # Sun Jan 21 14:07:52 2018 +0900 # Node ID fa4427fe64617b5822c383f8dfdf6704d16fe01f # Parent ca578149cc821eb207e2a844c6cf74e6b66f860c logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
This merges self.matchfn and self.show(matchfn) into self._makefilematcher, and does the same for hunksfilter. Because changesetprinter seems to have too many optional arguments, makefilematcher() and makehunksfilter() will be packed into one object by later patch. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3450,7 +3450,10 @@ def log(ui, repo, *pats, **opts): getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) ui.pager('log') - displayer = logcmdutil.changesetdisplayer(ui, repo, opts, buffered=True) + displayer = logcmdutil.changesetdisplayer(ui, repo, opts, + makefilematcher=filematcher, + makehunksfilter=hunksfilter, + buffered=True) for rev in revs: ctx = repo[rev] copies = None @@ -3460,16 +3463,7 @@ def log(ui, repo, *pats, **opts): rename = getrenamed(fn, rev) if rename: copies.append((fn, rename[0])) - if filematcher: - revmatchfn = filematcher(ctx) - else: - revmatchfn = None - if hunksfilter: - revhunksfilter = hunksfilter(ctx) - else: - revhunksfilter = None - displayer.show(ctx, copies=copies, matchfn=revmatchfn, - hunksfilterfn=revhunksfilter) + displayer.show(ctx, copies=copies) displayer.flush(ctx) displayer.close() diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -886,7 +886,8 @@ def _incoming(displaychlist, subreporecu ui.status(_("no changes found\n")) return subreporecurse() ui.pager('incoming') - displayer = logcmdutil.changesetdisplayer(ui, other, opts, buffered) + displayer = logcmdutil.changesetdisplayer(ui, other, opts, + buffered=buffered) displaychlist(other, chlist, displayer) displayer.close() finally: diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py +++ b/mercurial/logcmdutil.py @@ -122,11 +122,13 @@ def changesetlabels(ctx): class changesetprinter(object): '''show changeset information when templating not requested.''' - def __init__(self, ui, repo, matchfn=None, diffopts=None, buffered=False): + def __init__(self, ui, repo, makefilematcher=None, makehunksfilter=None, + diffopts=None, buffered=False): self.ui = ui self.repo = repo self.buffered = buffered - self.matchfn = matchfn + self._makefilematcher = makefilematcher or (lambda ctx: None) + self._makehunksfilter = makehunksfilter or (lambda ctx: None) self.diffopts = diffopts or {} self.header = {} self.hunk = {} @@ -150,17 +152,16 @@ class changesetprinter(object): if self.footer: self.ui.write(self.footer) - def show(self, ctx, copies=None, matchfn=None, hunksfilterfn=None, - **props): + def show(self, ctx, copies=None, **props): props = pycompat.byteskwargs(props) if self.buffered: self.ui.pushbuffer(labeled=True) - self._show(ctx, copies, matchfn, hunksfilterfn, props) + self._show(ctx, copies, props) self.hunk[ctx.rev()] = self.ui.popbuffer() else: - self._show(ctx, copies, matchfn, hunksfilterfn, props) + self._show(ctx, copies, props) - def _show(self, ctx, copies, matchfn, hunksfilterfn, props): + def _show(self, ctx, copies, props): '''show a single changeset or file revision''' changenode = ctx.node() rev = ctx.rev() @@ -251,7 +252,7 @@ class changesetprinter(object): label='log.summary') self.ui.write("\n") - self._showpatch(ctx, matchfn, hunksfilterfn=hunksfilterfn) + self._showpatch(ctx) def _showobsfate(self, ctx): obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx, ui=self.ui) @@ -265,9 +266,9 @@ class changesetprinter(object): '''empty method used by extension as a hook point ''' - def _showpatch(self, ctx, matchfn, hunksfilterfn=None): - if not matchfn: - matchfn = self.matchfn + def _showpatch(self, ctx): + matchfn = self._makefilematcher(ctx) + hunksfilterfn = self._makehunksfilter(ctx) if matchfn: stat = self.diffopts.get('stat') diff = self.diffopts.get('patch') @@ -290,8 +291,10 @@ class changesetprinter(object): class jsonchangeset(changesetprinter): '''format changeset information.''' - def __init__(self, ui, repo, matchfn=None, diffopts=None, buffered=False): - changesetprinter.__init__(self, ui, repo, matchfn, diffopts, buffered) + def __init__(self, ui, repo, makefilematcher=None, makehunksfilter=None, + diffopts=None, buffered=False): + changesetprinter.__init__(self, ui, repo, makefilematcher, + makehunksfilter, diffopts, buffered) self.cache = {} self._first = True @@ -301,7 +304,7 @@ class jsonchangeset(changesetprinter): else: self.ui.write("[]\n") - def _show(self, ctx, copies, matchfn, hunksfilterfn, props): + def _show(self, ctx, copies, props): '''show a single changeset or file revision''' rev = ctx.rev() if rev is None: @@ -366,7 +369,7 @@ class jsonchangeset(changesetprinter): ", ".join('"%s": "%s"' % (j(k), j(v)) for k, v in copies)) - matchfn = self.matchfn + matchfn = self._makefilematcher(ctx) if matchfn: stat = self.diffopts.get('stat') diff = self.diffopts.get('patch') @@ -397,9 +400,10 @@ class changesettemplater(changesetprinte # Arguments before "buffered" used to be positional. Consider not # adding/removing arguments before "buffered" to not break callers. - def __init__(self, ui, repo, tmplspec, matchfn=None, diffopts=None, - buffered=False): - changesetprinter.__init__(self, ui, repo, matchfn, diffopts, buffered) + def __init__(self, ui, repo, tmplspec, makefilematcher=None, + makehunksfilter=None, diffopts=None, buffered=False): + changesetprinter.__init__(self, ui, repo, makefilematcher, + makehunksfilter, diffopts, buffered) tres = formatter.templateresources(ui, repo) self.t = formatter.loadtemplater(ui, tmplspec, defaults=templatekw.keywords, @@ -442,7 +446,7 @@ class changesettemplater(changesetprinte self.footer += templater.stringify(self.t(self._parts['docfooter'])) return super(changesettemplater, self).close() - def _show(self, ctx, copies, matchfn, hunksfilterfn, props): + def _show(self, ctx, copies, props): '''show a single changeset or file revision''' props = props.copy() props['ctx'] = ctx @@ -469,7 +473,7 @@ class changesettemplater(changesetprinte # write changeset metadata, then patch if requested key = self._parts[self._tref] self.ui.write(templater.stringify(self.t(key, **props))) - self._showpatch(ctx, matchfn, hunksfilterfn=hunksfilterfn) + self._showpatch(ctx) if self._parts['footer']: if not self.footer: @@ -516,7 +520,8 @@ def maketemplater(ui, repo, tmpl, buffer spec = templatespec(tmpl, None) return changesettemplater(ui, repo, spec, buffered=buffered) -def changesetdisplayer(ui, repo, opts, buffered=False): +def changesetdisplayer(ui, repo, opts, makefilematcher=None, + makehunksfilter=None, buffered=False): """show one changeset using template or regular display. Display format will be the first non-empty hit of: @@ -528,19 +533,20 @@ def changesetdisplayer(ui, repo, opts, b regular display via changesetprinter() is done. """ # options - match = None - if opts.get('patch') or opts.get('stat'): - match = scmutil.matchall(repo) + if not makefilematcher and (opts.get('patch') or opts.get('stat')): + def makefilematcher(ctx): + return scmutil.matchall(repo) + postargs = (makefilematcher, makehunksfilter, opts, buffered) if opts.get('template') == 'json': - return jsonchangeset(ui, repo, match, opts, buffered) + return jsonchangeset(ui, repo, *postargs) spec = _lookuptemplate(ui, opts.get('template'), opts.get('style')) if not spec.ref and not spec.tmpl and not spec.mapfile: - return changesetprinter(ui, repo, match, opts, buffered) + return changesetprinter(ui, repo, *postargs) - return changesettemplater(ui, repo, spec, match, opts, buffered) + return changesettemplater(ui, repo, spec, *postargs) def _makematcher(repo, revs, pats, opts): """Build matcher and expanded patterns from log options @@ -848,8 +854,7 @@ def _graphnodeformatter(ui, displayer): return templ.render(props) return formatnode -def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, - filematcher=None, props=None): +def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, props=None): props = props or {} formatnode = _graphnodeformatter(ui, displayer) state = graphmod.asciistate() @@ -884,13 +889,10 @@ def displaygraph(ui, repo, dag, displaye rename = getrenamed(fn, ctx.rev()) if rename: copies.append((fn, rename[0])) - revmatchfn = None - if filematcher is not None: - revmatchfn = filematcher(ctx) edges = edgefn(type, char, state, rev, parents) firstedge = next(edges) width = firstedge[2] - displayer.show(ctx, copies=copies, matchfn=revmatchfn, + displayer.show(ctx, copies=copies, _graphwidth=width, **pycompat.strkwargs(props)) lines = displayer.hunk.pop(rev).split('\n') if not lines[-1]: @@ -913,9 +915,9 @@ def graphlog(ui, repo, revs, filematcher getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) ui.pager('log') - displayer = changesetdisplayer(ui, repo, opts, buffered=True) - displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed, - filematcher) + displayer = changesetdisplayer(ui, repo, opts, makefilematcher=filematcher, + buffered=True) + displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed) def checkunsupportedgraphflags(pats, opts): for op in ["newest_first"]: _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel