Patchwork [5,of,5] log: add an assertion about fctx not being None in patch.diff()

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 19, 2017, 1:51 p.m.
Message ID <e2b8b1cb1eaf17739d7a.1508421110@marimba>
Download mbox | patch
Permalink /patch/25240/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 19, 2017, 1:51 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1508418393 -7200
#      Thu Oct 19 15:06:33 2017 +0200
# Node ID e2b8b1cb1eaf17739d7af35479b853214daad35d
# Parent  d07a2cce2a4826f69cf2a6db12cc6721d95002a2
# EXP-Topic followlines-cli
log: add an assertion about fctx not being None in patch.diff()

As noted in the comment, this should not happen as removed files (the cause of
fctx2 being None) are caught earlier.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2330,6 +2330,11 @@  def diff(repo, node1=None, node2=None, m
             losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy,
     ):
         if hunksfilterfn is not None:
+            # If the file has been removed, fctx2 is None; but this should
+            # not occur here since we catch removed files early in
+            # cmdutil.getloglinerangerevs() for 'hg log -L'.
+            assert fctx2 is not None, \
+                'fctx2 unexpectly None in diff hunks filtering'
             hunks = hunksfilterfn(fctx2, hunks)
         text = ''.join(sum((list(hlines) for hrange, hlines in hunks), []))
         if hdr and (text or len(hdr) > 1):