diff mercurial/logcmdutil.py @ 43445:d1b9d2c6ec96 stable

log: map None rev to wdirrev when filtering revisions with --line-range When 'hg log -f --line-range <file>,<range>' is invoked with <range> containing uncommitted changes, the command crashes on Python 3 as follows: [...] File "/usr/lib/python3/dist-packages/mercurial/commands.py", line 4725, in log revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts) File "/usr/lib/python3/dist-packages/mercurial/logcmdutil.py", line 933, in getlinerangerevs if rev not in userrevs: File "/usr/lib/python3/dist-packages/mercurial/smartset.py", line 969, in __contains__ if l < x: TypeError: '<' not supported between instances of 'int' and 'NoneType' The None value is because requested line range has uncommitted changes, so 'rev' is the working directory revision. This only occurs in Python 3 as Python 2 allows comparing None with int. As suggested by Yuya Nishihara, mapping None to node.wdirrev resolves the issue and also make the '--line-range' option properly work with -r 'wdir()'. We add extra tests for non-regression and to illustrate handling of 'wdir()'.
author Denis Laxalde <denis@laxalde.org>
date Fri, 29 Nov 2019 21:43:13 +0100
parents 8ff1ecfadcd1
children 29adf0a087a1
line wrap: on
line diff
--- a/mercurial/logcmdutil.py	Fri Nov 29 21:34:54 2019 +0100
+++ b/mercurial/logcmdutil.py	Fri Nov 29 21:43:13 2019 +0100
@@ -930,6 +930,8 @@
         fctx = wctx.filectx(fname)
         for fctx, linerange in dagop.blockancestors(fctx, fromline, toline):
             rev = fctx.introrev()
+            if rev is None:
+                rev = wdirrev
             if rev not in userrevs:
                 continue
             linerangesbyrev.setdefault(rev, {}).setdefault(
@@ -940,7 +942,7 @@
         return hunks
 
     def hunksfilter(ctx):
-        fctxlineranges = linerangesbyrev.get(ctx.rev())
+        fctxlineranges = linerangesbyrev.get(scmutil.intrev(ctx))
         if fctxlineranges is None:
             return nofilterhunksfn
 
@@ -960,7 +962,7 @@
         return filterfn
 
     def filematcher(ctx):
-        files = list(linerangesbyrev.get(ctx.rev(), []))
+        files = list(linerangesbyrev.get(scmutil.intrev(ctx), []))
         return scmutil.matchfiles(repo, files)
 
     revs = sorted(linerangesbyrev, reverse=True)