Show More
@@ -3419,17 +3419,15 b' def log(ui, repo, *pats, **opts):' | |||
|
3419 | 3419 | ) |
|
3420 | 3420 | |
|
3421 | 3421 | repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn') |
|
3422 |
revs, |
|
|
3423 | hunksfilter = None | |
|
3422 | revs, differ = logcmdutil.getrevs(repo, pats, opts) | |
|
3424 | 3423 | |
|
3425 | 3424 | if opts.get('graph'): |
|
3426 | 3425 | if linerange: |
|
3427 | 3426 | raise error.Abort(_('graph not supported with line range patterns')) |
|
3428 |
return logcmdutil.graphlog(ui, repo, revs, |
|
|
3427 | return logcmdutil.graphlog(ui, repo, revs, differ, opts) | |
|
3429 | 3428 | |
|
3430 | 3429 | if linerange: |
|
3431 |
revs, |
|
|
3432 | repo, revs, opts) | |
|
3430 | revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts) | |
|
3433 | 3431 | |
|
3434 | 3432 | getrenamed = None |
|
3435 | 3433 | if opts.get('copies'): |
@@ -3439,9 +3437,7 b' def log(ui, repo, *pats, **opts):' | |||
|
3439 | 3437 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
3440 | 3438 | |
|
3441 | 3439 | ui.pager('log') |
|
3442 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, | |
|
3443 | makefilematcher=filematcher, | |
|
3444 | makehunksfilter=hunksfilter, | |
|
3440 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ, | |
|
3445 | 3441 | buffered=True) |
|
3446 | 3442 | for rev in revs: |
|
3447 | 3443 | ctx = repo[rev] |
@@ -122,6 +122,23 b' def diffordiffstat(ui, repo, diffopts, n' | |||
|
122 | 122 | sub.diff(ui, diffopts, tempnode2, submatch, changes=changes, |
|
123 | 123 | stat=stat, fp=fp, prefix=prefix) |
|
124 | 124 | |
|
125 | class changesetdiffer(object): | |
|
126 | """Generate diff of changeset with pre-configured filtering functions""" | |
|
127 | ||
|
128 | def _makefilematcher(self, ctx): | |
|
129 | return scmutil.matchall(ctx.repo()) | |
|
130 | ||
|
131 | def _makehunksfilter(self, ctx): | |
|
132 | return None | |
|
133 | ||
|
134 | def showdiff(self, ui, ctx, diffopts, stat=False): | |
|
135 | repo = ctx.repo() | |
|
136 | node = ctx.node() | |
|
137 | prev = ctx.p1().node() | |
|
138 | diffordiffstat(ui, repo, diffopts, prev, node, | |
|
139 | match=self._makefilematcher(ctx), stat=stat, | |
|
140 | hunksfilterfn=self._makehunksfilter(ctx)) | |
|
141 | ||
|
125 | 142 | def changesetlabels(ctx): |
|
126 | 143 | labels = ['log.changeset', 'changeset.%s' % ctx.phasestr()] |
|
127 | 144 | if ctx.obsolete(): |
@@ -135,13 +152,11 b' def changesetlabels(ctx):' | |||
|
135 | 152 | class changesetprinter(object): |
|
136 | 153 | '''show changeset information when templating not requested.''' |
|
137 | 154 | |
|
138 |
def __init__(self, ui, repo, |
|
|
139 | diffopts=None, buffered=False): | |
|
155 | def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False): | |
|
140 | 156 | self.ui = ui |
|
141 | 157 | self.repo = repo |
|
142 | 158 | self.buffered = buffered |
|
143 | self._makefilematcher = makefilematcher or (lambda ctx: None) | |
|
144 | self._makehunksfilter = makehunksfilter or (lambda ctx: None) | |
|
159 | self._differ = differ or changesetdiffer() | |
|
145 | 160 | self.diffopts = diffopts or {} |
|
146 | 161 | self.header = {} |
|
147 | 162 | self.hunk = {} |
@@ -280,35 +295,23 b' class changesetprinter(object):' | |||
|
280 | 295 | ''' |
|
281 | 296 | |
|
282 | 297 | def _showpatch(self, ctx): |
|
283 | matchfn = self._makefilematcher(ctx) | |
|
284 | hunksfilterfn = self._makehunksfilter(ctx) | |
|
285 | if not matchfn: | |
|
286 | return | |
|
287 | 298 | stat = self.diffopts.get('stat') |
|
288 | 299 | diff = self.diffopts.get('patch') |
|
289 | 300 | diffopts = patch.diffallopts(self.ui, self.diffopts) |
|
290 | node = ctx.node() | |
|
291 | prev = ctx.p1().node() | |
|
292 | 301 | if stat: |
|
293 |
|
|
|
294 | match=matchfn, stat=True, | |
|
295 | hunksfilterfn=hunksfilterfn) | |
|
302 | self._differ.showdiff(self.ui, ctx, diffopts, stat=True) | |
|
296 | 303 | if stat and diff: |
|
297 | 304 | self.ui.write("\n") |
|
298 | 305 | if diff: |
|
299 |
|
|
|
300 | match=matchfn, stat=False, | |
|
301 | hunksfilterfn=hunksfilterfn) | |
|
306 | self._differ.showdiff(self.ui, ctx, diffopts, stat=False) | |
|
302 | 307 | if stat or diff: |
|
303 | 308 | self.ui.write("\n") |
|
304 | 309 | |
|
305 | 310 | class jsonchangeset(changesetprinter): |
|
306 | 311 | '''format changeset information.''' |
|
307 | 312 | |
|
308 |
def __init__(self, ui, repo, |
|
|
309 | diffopts=None, buffered=False): | |
|
310 | changesetprinter.__init__(self, ui, repo, makefilematcher, | |
|
311 | makehunksfilter, diffopts, buffered) | |
|
313 | def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False): | |
|
314 | changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered) | |
|
312 | 315 | self.cache = {} |
|
313 | 316 | self._first = True |
|
314 | 317 | |
@@ -383,21 +386,17 b' class jsonchangeset(changesetprinter):' | |||
|
383 | 386 | ", ".join('"%s": "%s"' % (j(k), j(v)) |
|
384 | 387 | for k, v in copies)) |
|
385 | 388 | |
|
386 | matchfn = self._makefilematcher(ctx) | |
|
387 | 389 | stat = self.diffopts.get('stat') |
|
388 | 390 | diff = self.diffopts.get('patch') |
|
389 | 391 | diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) |
|
390 | node, prev = ctx.node(), ctx.p1().node() | |
|
391 | if matchfn and stat: | |
|
392 | if stat: | |
|
392 | 393 | self.ui.pushbuffer() |
|
393 |
|
|
|
394 | match=matchfn, stat=True) | |
|
394 | self._differ.showdiff(self.ui, ctx, diffopts, stat=True) | |
|
395 | 395 | self.ui.write((',\n "diffstat": "%s"') |
|
396 | 396 | % j(self.ui.popbuffer())) |
|
397 |
if |
|
|
397 | if diff: | |
|
398 | 398 | self.ui.pushbuffer() |
|
399 |
|
|
|
400 | match=matchfn, stat=False) | |
|
399 | self._differ.showdiff(self.ui, ctx, diffopts, stat=False) | |
|
401 | 400 | self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) |
|
402 | 401 | |
|
403 | 402 | self.ui.write("\n }") |
@@ -413,10 +412,9 b' class changesettemplater(changesetprinte' | |||
|
413 | 412 | |
|
414 | 413 | # Arguments before "buffered" used to be positional. Consider not |
|
415 | 414 | # adding/removing arguments before "buffered" to not break callers. |
|
416 |
def __init__(self, ui, repo, tmplspec, |
|
|
417 |
|
|
|
418 |
changesetprinter.__init__(self, ui, repo, |
|
|
419 | makehunksfilter, diffopts, buffered) | |
|
415 | def __init__(self, ui, repo, tmplspec, differ=None, diffopts=None, | |
|
416 | buffered=False): | |
|
417 | changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered) | |
|
420 | 418 | tres = formatter.templateresources(ui, repo) |
|
421 | 419 | self.t = formatter.loadtemplater(ui, tmplspec, |
|
422 | 420 | defaults=templatekw.keywords, |
@@ -533,8 +531,7 b' def maketemplater(ui, repo, tmpl, buffer' | |||
|
533 | 531 | spec = templatespec(tmpl, None) |
|
534 | 532 | return changesettemplater(ui, repo, spec, buffered=buffered) |
|
535 | 533 | |
|
536 |
def changesetdisplayer(ui, repo, opts, |
|
|
537 | makehunksfilter=None, buffered=False): | |
|
534 | def changesetdisplayer(ui, repo, opts, differ=None, buffered=False): | |
|
538 | 535 | """show one changeset using template or regular display. |
|
539 | 536 | |
|
540 | 537 | Display format will be the first non-empty hit of: |
@@ -545,12 +542,7 b' def changesetdisplayer(ui, repo, opts, m' | |||
|
545 | 542 | If all of these values are either the unset or the empty string, |
|
546 | 543 | regular display via changesetprinter() is done. |
|
547 | 544 | """ |
|
548 | # options | |
|
549 | if not makefilematcher and (opts.get('patch') or opts.get('stat')): | |
|
550 | def makefilematcher(ctx): | |
|
551 | return scmutil.matchall(repo) | |
|
552 | ||
|
553 | postargs = (makefilematcher, makehunksfilter, opts, buffered) | |
|
545 | postargs = (differ, opts, buffered) | |
|
554 | 546 | if opts.get('template') == 'json': |
|
555 | 547 | return jsonchangeset(ui, repo, *postargs) |
|
556 | 548 | |
@@ -726,10 +718,9 b' def _initialrevs(repo, opts):' | |||
|
726 | 718 | return revs |
|
727 | 719 | |
|
728 | 720 | def getrevs(repo, pats, opts): |
|
729 |
"""Return (revs, |
|
|
721 | """Return (revs, differ) where revs is a smartset | |
|
730 | 722 | |
|
731 | filematcher is a callable taking a changectx and returning a match | |
|
732 | objects filtering the files to be detailed when displaying the revision. | |
|
723 | differ is a changesetdiffer with pre-configured file matcher. | |
|
733 | 724 | """ |
|
734 | 725 | follow = opts.get('follow') or opts.get('follow_first') |
|
735 | 726 | followfirst = opts.get('follow_first') |
@@ -762,7 +753,10 b' def getrevs(repo, pats, opts):' | |||
|
762 | 753 | revs = matcher(repo, revs) |
|
763 | 754 | if limit is not None: |
|
764 | 755 | revs = revs.slice(0, limit) |
|
765 | return revs, filematcher | |
|
756 | ||
|
757 | differ = changesetdiffer() | |
|
758 | differ._makefilematcher = filematcher | |
|
759 | return revs, differ | |
|
766 | 760 | |
|
767 | 761 | def _parselinerangeopt(repo, opts): |
|
768 | 762 | """Parse --line-range log option and return a list of tuples (filename, |
@@ -785,16 +779,13 b' def _parselinerangeopt(repo, opts):' | |||
|
785 | 779 | return linerangebyfname |
|
786 | 780 | |
|
787 | 781 | def getlinerangerevs(repo, userrevs, opts): |
|
788 |
"""Return (revs, |
|
|
782 | """Return (revs, differ). | |
|
789 | 783 | |
|
790 | 784 | "revs" are revisions obtained by processing "line-range" log options and |
|
791 | 785 | walking block ancestors of each specified file/line-range. |
|
792 | 786 | |
|
793 | "filematcher(ctx) -> match" is a factory function returning a match object | |
|
794 | for a given revision for file patterns specified in --line-range option. | |
|
795 | ||
|
796 | "hunksfilter(ctx) -> filterfn(fctx, hunks)" is a factory function | |
|
797 | returning a hunks filtering function. | |
|
787 | "differ" is a changesetdiffer with pre-configured file matcher and hunks | |
|
788 | filter. | |
|
798 | 789 | """ |
|
799 | 790 | wctx = repo[None] |
|
800 | 791 | |
@@ -843,7 +834,10 b' def getlinerangerevs(repo, userrevs, opt' | |||
|
843 | 834 | |
|
844 | 835 | revs = sorted(linerangesbyrev, reverse=True) |
|
845 | 836 | |
|
846 | return revs, filematcher, hunksfilter | |
|
837 | differ = changesetdiffer() | |
|
838 | differ._makefilematcher = filematcher | |
|
839 | differ._makehunksfilter = hunksfilter | |
|
840 | return revs, differ | |
|
847 | 841 | |
|
848 | 842 | def _graphnodeformatter(ui, displayer): |
|
849 | 843 | spec = ui.config('ui', 'graphnodetemplate') |
@@ -910,7 +904,7 b' def displaygraph(ui, repo, dag, displaye' | |||
|
910 | 904 | lines = [] |
|
911 | 905 | displayer.close() |
|
912 | 906 | |
|
913 |
def graphlog(ui, repo, revs, |
|
|
907 | def graphlog(ui, repo, revs, differ, opts): | |
|
914 | 908 | # Parameters are identical to log command ones |
|
915 | 909 | revdag = graphmod.dagwalker(repo, revs) |
|
916 | 910 | |
@@ -922,8 +916,7 b' def graphlog(ui, repo, revs, filematcher' | |||
|
922 | 916 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
923 | 917 | |
|
924 | 918 | ui.pager('log') |
|
925 |
displayer = changesetdisplayer(ui, repo, opts, |
|
|
926 | buffered=True) | |
|
919 | displayer = changesetdisplayer(ui, repo, opts, differ, buffered=True) | |
|
927 | 920 | displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed) |
|
928 | 921 | |
|
929 | 922 | def checkunsupportedgraphflags(pats, opts): |
General Comments 0
You need to be logged in to leave comments.
Login now