mercurial/logcmdutil.py
changeset 36005 dd77e36eabb6
parent 36004 d4c210ee894f
child 36007 29b83c08afe0
equal deleted inserted replaced
36004:d4c210ee894f 36005:dd77e36eabb6
   790     "revs" are revisions obtained by processing "line-range" log options and
   790     "revs" are revisions obtained by processing "line-range" log options and
   791     walking block ancestors of each specified file/line-range.
   791     walking block ancestors of each specified file/line-range.
   792 
   792 
   793     "filematcher(ctx) -> match" is a factory function returning a match object
   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.
   794     for a given revision for file patterns specified in --line-range option.
   795     If neither --stat nor --patch options are passed, "filematcher" is None.
       
   796 
   795 
   797     "hunksfilter(ctx) -> filterfn(fctx, hunks)" is a factory function
   796     "hunksfilter(ctx) -> filterfn(fctx, hunks)" is a factory function
   798     returning a hunks filtering function.
   797     returning a hunks filtering function.
   799     If neither --stat nor --patch options are passed, "filterhunks" is None.
       
   800     """
   798     """
   801     wctx = repo[None]
   799     wctx = repo[None]
   802 
   800 
   803     # Two-levels map of "rev -> file ctx -> [line range]".
   801     # Two-levels map of "rev -> file ctx -> [line range]".
   804     linerangesbyrev = {}
   802     linerangesbyrev = {}
   813                 continue
   811                 continue
   814             linerangesbyrev.setdefault(
   812             linerangesbyrev.setdefault(
   815                 rev, {}).setdefault(
   813                 rev, {}).setdefault(
   816                     fctx.path(), []).append(linerange)
   814                     fctx.path(), []).append(linerange)
   817 
   815 
   818     filematcher = None
   816     def nofilterhunksfn(fctx, hunks):
   819     hunksfilter = None
   817         return hunks
   820     if opts.get('patch') or opts.get('stat'):
   818 
   821 
   819     def hunksfilter(ctx):
   822         def nofilterhunksfn(fctx, hunks):
   820         fctxlineranges = linerangesbyrev.get(ctx.rev())
   823             return hunks
   821         if fctxlineranges is None:
   824 
   822             return nofilterhunksfn
   825         def hunksfilter(ctx):
   823 
   826             fctxlineranges = linerangesbyrev.get(ctx.rev())
   824         def filterfn(fctx, hunks):
   827             if fctxlineranges is None:
   825             lineranges = fctxlineranges.get(fctx.path())
   828                 return nofilterhunksfn
   826             if lineranges is not None:
   829 
   827                 for hr, lines in hunks:
   830             def filterfn(fctx, hunks):
   828                     if hr is None: # binary
   831                 lineranges = fctxlineranges.get(fctx.path())
   829                         yield hr, lines
   832                 if lineranges is not None:
   830                         continue
   833                     for hr, lines in hunks:
   831                     if any(mdiff.hunkinrange(hr[2:], lr)
   834                         if hr is None: # binary
   832                            for lr in lineranges):
   835                             yield hr, lines
   833                         yield hr, lines
   836                             continue
   834             else:
   837                         if any(mdiff.hunkinrange(hr[2:], lr)
   835                 for hunk in hunks:
   838                                for lr in lineranges):
   836                     yield hunk
   839                             yield hr, lines
   837 
   840                 else:
   838         return filterfn
   841                     for hunk in hunks:
   839 
   842                         yield hunk
   840     def filematcher(ctx):
   843 
   841         files = list(linerangesbyrev.get(ctx.rev(), []))
   844             return filterfn
   842         return scmutil.matchfiles(repo, files)
   845 
       
   846         def filematcher(ctx):
       
   847             files = list(linerangesbyrev.get(ctx.rev(), []))
       
   848             return scmutil.matchfiles(repo, files)
       
   849 
   843 
   850     revs = sorted(linerangesbyrev, reverse=True)
   844     revs = sorted(linerangesbyrev, reverse=True)
   851 
   845 
   852     return revs, filematcher, hunksfilter
   846     return revs, filematcher, hunksfilter
   853 
   847