Mercurial > public > mercurial-scm > hg
comparison mercurial/logcmdutil.py @ 36002:f8ad57d24252
log: pass ctx to makefilematcher() and makehunksfilter() functions
This isn't important, but seems more consistent as changesetprinter.show()
takes a ctx, not a revision number.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 21 Jan 2018 13:40:31 +0900 |
parents | 0ff41ced4c12 |
children | fcde8946c553 |
comparison
equal
deleted
inserted
replaced
36000:91aac8e6604d | 36002:f8ad57d24252 |
---|---|
625 # to know which file of the revision must be diffed. With | 625 # to know which file of the revision must be diffed. With |
626 # --follow, we want the names of the ancestors of FILE in the | 626 # --follow, we want the names of the ancestors of FILE in the |
627 # revision, stored in "fcache". "fcache" is populated as a side effect | 627 # revision, stored in "fcache". "fcache" is populated as a side effect |
628 # of the graph traversal. | 628 # of the graph traversal. |
629 fcache = {} | 629 fcache = {} |
630 def filematcher(rev): | 630 def filematcher(ctx): |
631 return scmutil.matchfiles(repo, fcache.get(rev, [])) | 631 return scmutil.matchfiles(repo, fcache.get(ctx.rev(), [])) |
632 | 632 |
633 def revgen(): | 633 def revgen(): |
634 for rev, cs in dagop.filectxancestors(fctxs, followfirst=followfirst): | 634 for rev, cs in dagop.filectxancestors(fctxs, followfirst=followfirst): |
635 fcache[rev] = [c.path() for c in cs] | 635 fcache[rev] = [c.path() for c in cs] |
636 yield rev | 636 yield rev |
720 return revs | 720 return revs |
721 | 721 |
722 def getrevs(repo, pats, opts): | 722 def getrevs(repo, pats, opts): |
723 """Return (revs, filematcher) where revs is a smartset | 723 """Return (revs, filematcher) where revs is a smartset |
724 | 724 |
725 filematcher is a callable taking a revision number and returning a match | 725 filematcher is a callable taking a changectx and returning a match |
726 objects filtering the files to be detailed when displaying the revision. | 726 objects filtering the files to be detailed when displaying the revision. |
727 """ | 727 """ |
728 follow = opts.get('follow') or opts.get('follow_first') | 728 follow = opts.get('follow') or opts.get('follow_first') |
729 followfirst = opts.get('follow_first') | 729 followfirst = opts.get('follow_first') |
730 limit = getlimit(opts) | 730 limit = getlimit(opts) |
740 revs, filematcher = _fileancestors(repo, revs, match, followfirst) | 740 revs, filematcher = _fileancestors(repo, revs, match, followfirst) |
741 revs.reverse() | 741 revs.reverse() |
742 if filematcher is None: | 742 if filematcher is None: |
743 filematcher = _makenofollowfilematcher(repo, pats, opts) | 743 filematcher = _makenofollowfilematcher(repo, pats, opts) |
744 if filematcher is None: | 744 if filematcher is None: |
745 def filematcher(rev): | 745 def filematcher(ctx): |
746 return match | 746 return match |
747 | 747 |
748 expr = _makerevset(repo, match, pats, slowpath, opts) | 748 expr = _makerevset(repo, match, pats, slowpath, opts) |
749 if opts.get('graph') and opts.get('rev'): | 749 if opts.get('graph') and opts.get('rev'): |
750 # User-specified revs might be unsorted, but don't sort before | 750 # User-specified revs might be unsorted, but don't sort before |
782 """Return (revs, filematcher, hunksfilter). | 782 """Return (revs, filematcher, hunksfilter). |
783 | 783 |
784 "revs" are revisions obtained by processing "line-range" log options and | 784 "revs" are revisions obtained by processing "line-range" log options and |
785 walking block ancestors of each specified file/line-range. | 785 walking block ancestors of each specified file/line-range. |
786 | 786 |
787 "filematcher(rev) -> match" is a factory function returning a match object | 787 "filematcher(ctx) -> match" is a factory function returning a match object |
788 for a given revision for file patterns specified in --line-range option. | 788 for a given revision for file patterns specified in --line-range option. |
789 If neither --stat nor --patch options are passed, "filematcher" is None. | 789 If neither --stat nor --patch options are passed, "filematcher" is None. |
790 | 790 |
791 "hunksfilter(rev) -> filterfn(fctx, hunks)" is a factory function | 791 "hunksfilter(ctx) -> filterfn(fctx, hunks)" is a factory function |
792 returning a hunks filtering function. | 792 returning a hunks filtering function. |
793 If neither --stat nor --patch options are passed, "filterhunks" is None. | 793 If neither --stat nor --patch options are passed, "filterhunks" is None. |
794 """ | 794 """ |
795 wctx = repo[None] | 795 wctx = repo[None] |
796 | 796 |
814 if opts.get('patch') or opts.get('stat'): | 814 if opts.get('patch') or opts.get('stat'): |
815 | 815 |
816 def nofilterhunksfn(fctx, hunks): | 816 def nofilterhunksfn(fctx, hunks): |
817 return hunks | 817 return hunks |
818 | 818 |
819 def hunksfilter(rev): | 819 def hunksfilter(ctx): |
820 fctxlineranges = linerangesbyrev.get(rev) | 820 fctxlineranges = linerangesbyrev.get(ctx.rev()) |
821 if fctxlineranges is None: | 821 if fctxlineranges is None: |
822 return nofilterhunksfn | 822 return nofilterhunksfn |
823 | 823 |
824 def filterfn(fctx, hunks): | 824 def filterfn(fctx, hunks): |
825 lineranges = fctxlineranges.get(fctx.path()) | 825 lineranges = fctxlineranges.get(fctx.path()) |
835 for hunk in hunks: | 835 for hunk in hunks: |
836 yield hunk | 836 yield hunk |
837 | 837 |
838 return filterfn | 838 return filterfn |
839 | 839 |
840 def filematcher(rev): | 840 def filematcher(ctx): |
841 files = list(linerangesbyrev.get(rev, [])) | 841 files = list(linerangesbyrev.get(ctx.rev(), [])) |
842 return scmutil.matchfiles(repo, files) | 842 return scmutil.matchfiles(repo, files) |
843 | 843 |
844 revs = sorted(linerangesbyrev, reverse=True) | 844 revs = sorted(linerangesbyrev, reverse=True) |
845 | 845 |
846 return revs, filematcher, hunksfilter | 846 return revs, filematcher, hunksfilter |
897 rename = getrenamed(fn, ctx.rev()) | 897 rename = getrenamed(fn, ctx.rev()) |
898 if rename: | 898 if rename: |
899 copies.append((fn, rename[0])) | 899 copies.append((fn, rename[0])) |
900 revmatchfn = None | 900 revmatchfn = None |
901 if filematcher is not None: | 901 if filematcher is not None: |
902 revmatchfn = filematcher(ctx.rev()) | 902 revmatchfn = filematcher(ctx) |
903 edges = edgefn(type, char, state, rev, parents) | 903 edges = edgefn(type, char, state, rev, parents) |
904 firstedge = next(edges) | 904 firstedge = next(edges) |
905 width = firstedge[2] | 905 width = firstedge[2] |
906 displayer.show(ctx, copies=copies, matchfn=revmatchfn, | 906 displayer.show(ctx, copies=copies, matchfn=revmatchfn, |
907 _graphwidth=width, **pycompat.strkwargs(props)) | 907 _graphwidth=width, **pycompat.strkwargs(props)) |