Bug 574253 - PathSuffixFilter not worked with negate in jgit diff
Summary: PathSuffixFilter not worked with negate in jgit diff
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.12   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 5.13   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-17 03:53 EDT by Pallavi Agarwal CLA
Modified: 2021-06-21 09:48 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pallavi Agarwal CLA 2021-06-17 03:53:54 EDT
I am using difformatter.scan for git diff, Now I want to ignore diffs in pdf, png, gif , jar files.
I am using `NotTreeFilter.create(PathSuffixFilter.create(".png") OR PathSuffixFilter.create(".pdf") OR so on...))`
But Now, I am getting 0 file diffs for most of the commits having java files of any other valid files.
Comment 1 Thomas Wolf CLA 2021-06-17 04:16:02 EDT
Please show real code.
Comment 2 Pallavi Agarwal CLA 2021-06-17 06:50:30 EDT
```
 fun computeParentChildCommitDiff(repository: Repository, childCommit: RevCommit, parentCommit: RevCommit?): List<FileDiff> {
        logger.info { "Computing diff between $childCommit & $parentCommit for $repository" }

        DiffFormatter(DisabledOutputStream.INSTANCE).use { diffFormatter ->
            diffFormatter.setRepository(repository)
            diffFormatter.pathFilter = NotTreeFilter.create(OrTreeFilter.create(listOf(PathSuffixFilter.create(".png") ,
                    PathSuffixFilter.create(".pdf"))))
            val diffEntries = measureTimeOfFunc({ time -> logger.info { "diffFormatter scan for $childCommit parent $parentCommit for $repository took $time ms" } }) {
                diffFormatter.scan(parentCommit?.tree, childCommit.tree)
            }
            logger.info { "Found diff entries ${diffEntries.size} for child $childCommit, parent $parentCommit for $repository" }
            if (diffEntries.size > 10_000) {
                logger.warn { "Skipping diff for commit $childCommit & $parentCommit as they have more than 10K file changes for $repository" }
                return emptyList()
            }

            val fileDiffList = diffEntries.map { convertDiffEntry(diffFormatter, it) }

            logger.info { "Finished computing diff entries for child $childCommit, parent $parentCommit for $repository" }
            return fileDiffList
        }
    }
```

This method is computing diff between parent and child, and after adding path filter , I am not getting diffs from java file too, for the same commit if i remove path filter I get diffs from java files.
Comment 3 Pallavi Agarwal CLA 2021-06-17 06:50:49 EDT
```
 fun computeParentChildCommitDiff(repository: Repository, childCommit: RevCommit, parentCommit: RevCommit?): List<FileDiff> {
        logger.info { "Computing diff between $childCommit & $parentCommit for $repository" }

        DiffFormatter(DisabledOutputStream.INSTANCE).use { diffFormatter ->
            diffFormatter.setRepository(repository)
            diffFormatter.pathFilter = NotTreeFilter.create(OrTreeFilter.create(listOf(PathSuffixFilter.create(".png") ,
                    PathSuffixFilter.create(".pdf"))))
            val diffEntries = measureTimeOfFunc({ time -> logger.info { "diffFormatter scan for $childCommit parent $parentCommit for $repository took $time ms" } }) {
                diffFormatter.scan(parentCommit?.tree, childCommit.tree)
            }
            logger.info { "Found diff entries ${diffEntries.size} for child $childCommit, parent $parentCommit for $repository" }
            if (diffEntries.size > 10_000) {
                logger.warn { "Skipping diff for commit $childCommit & $parentCommit as they have more than 10K file changes for $repository" }
                return emptyList()
            }

            val fileDiffList = diffEntries.map { convertDiffEntry(diffFormatter, it) }

            logger.info { "Finished computing diff entries for child $childCommit, parent $parentCommit for $repository" }
            return fileDiffList
        }
    }
```

This method is computing diff between parent and child, and after adding path filter , I am not getting diffs from java file too, for the same commit if i remove path filter I get diffs from java files.
Comment 4 Thomas Wolf CLA 2021-06-17 11:56:29 EDT
Thanks, can reproduce. It's an old bug in PathSuffixFilter. A negated PathSuffixFilter, or a negation of a a logical disjunction of multiple PathSuffixFilters, skips all directories.
Comment 5 Eclipse Genie CLA 2021-06-17 11:57:18 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/182126
Comment 6 Pallavi Agarwal CLA 2021-06-18 00:33:23 EDT
When I can expect this in production?
Comment 7 Thomas Wolf CLA 2021-06-18 03:57:26 EDT
(In reply to Pallavi Agarwal from comment #6)
> When I can expect this in production?

The next regular release of JGit will be in September 2021.

If you need it before that, you can of course build JGit yourself once the fix is merged. Or copy the fixed PathSuffixFilter class into your own code and use that.