Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] 回复:[Internet]Re: A bug in the 'RevWalkUtils.findBranchesReachableFrom' method

I have pushed a new patch[1] to fix this problem.

Hope some one can review it :) .




在 2021年8月4日 23:01,Nasser Grainawi<quic_nasserg@xxxxxxxxxxx> 写道:

On Aug 4, 2021, at 8:33 AM, Malyshkin, Denis via jgit-dev <jgit-dev@xxxxxxxxxxx> wrote:


Our developers found a bug in the 'RevWalkUtils.findBranchesReachableFrom' method in JGit 5.12. On the second call, this method returns no commits even if commits exist in a repository.

Thanks for reporting this!

@Adithya, could this be related to the optimization done in 176854: Optimize RevWalkUtils.findBranchesReachableFrom() | ?

Below is a test example to reproduce the bug:
public class App
    private static final String REMOTE_URL = "";
    private static final String[] COMMIT_IDS = new String[] {

    public static void main( String[] args ) throws IOException, GitAPIException {
        // prepare a new folder for the cloned repository
        File localPath = File.createTempFile("TestGitRepository", "");
        if(!localPath.delete()) {
            throw new IOException("Could not delete temporary file " + localPath);

        try {
            // then clone
            System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
            try (Git result = Git.cloneRepository()
                    .call()) {
                System.out.println("Having repository: " + result.getRepository().getDirectory());

            try (Repository repository = FileRepositoryBuilder.create(localPath);
                 RevWalk revWalk = new RevWalk(repository)) {
                Collection<Ref> allRefs = repository.getAllRefs().values();
                for (String commitId : COMMIT_IDS) {
                    RevCommit revCommit = revWalk.parseCommit(ObjectId.fromString(commitId));
                    Collection<Ref> refs = RevWalkUtils.findBranchesReachableFrom(revCommit, revWalk, allRefs);
                    System.out.printf("refs.size() = %d for commit <%s> %n", refs.size(), commitId);
        } finally {
            // clean up here to not keep using more and more disk-space for these samples

And we got the following results:

refs.size() = 4 for commit <edabfa50d9ec3be8026a2f77f94c5b1e074e70bf>
refs.size() = 0 for commit <a0ab326927445608ee446de30ad076e075634e9f>

v. and lower
refs.size() = 4 for commit <edabfa50d9ec3be8026a2f77f94c5b1e074e70bf>
refs.size() = 1 for commit <a0ab326927445608ee446de30ad076e075634e9f>  

This issue is reproduced for v.5.12 only. Should the client code be changed to work with v.5.12 or it is a bug?

We also tested on the latest builds '5.13.0-SNAPSHOT' and '5.12.1-SNAPSHOT'. The bug is reproduced on them either.

Thank you for the help.

Best regards,
  Denis Malyshkin,
Senior C++ Developer
of ISS Art, Ltd., Omsk, Russia.
Mobile Phone: +7 913 669 2896
Office tel/fax +7 3812 396959
Yahoo Messenger: dmalyshkin

E-mail: dmalyshkin@xxxxxxxxxx
jgit-dev mailing list
To unsubscribe from this list, visit

Back to the top