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):