4

So what i am trying to do is to detect rename/copy activities on a source code file since it is added to the repository. I am using following code -

/**
 * 
 * @param path source code file to retrieve complete history
 * @param start latest commit made for "path" to mark as start (tested with HEAD also)
 * @return
 */
private RevCommitList<RevCommit> getList(String path, RevCommit start) throws Exception {

        Config config = new Config(git.getRepository().getConfig());
        config.setString("diff", null, "renames", "copies");
        config.setInt("diff", null, "renameLimit", Integer.MAX_VALUE);
        DiffConfig diffConfig = config.get(DiffConfig.KEY);

        final RevWalk revWalk = new RevWalk(git.getRepository());
        //revWalk.reset();
        revWalk.setTreeFilter(FollowFilter.create(path, diffConfig));
        revWalk.markStart(revWalk.parseCommit(start));

        final RevCommitList<RevCommit> list = new RevCommitList<RevCommit>();
        list.source(revWalk);
        list.fillTo(Integer.MAX_VALUE);

        return list;
    }

There are 2 problems with this code -

  1. Though JGit is able to detect "RENAMES" it is failing to detect "COPY" activities. Wherever any Copy activity is encountered, it just stops and doesn't fetch further activities. Can someone please help in identifying what could possibly be wrong with the code?

  2. I have cloned wildfly (https://www.github.com/wildfly) repository for my testing. I am retrieving file history using git's command line tool and using above mentioned code to make sure that both are giving same results atleast until "Copy" activity. But there seems to be considerable difference in the results given by git's command line tool and above mentioned code. E.g. When i run git log command -

    git log --follow --name-status -- build/src/main/resources/modules/org/jboss/as/clustering/common/main/module.xml
    

it gives following result

  1. 659621a4ccfa9b45416537aebb14cda0419bb82d
  2. b1d3bf705461754307237dd9ca2a2211f3ef4022
  3. c1d1a77fd4beb956c1a353c02da972c58f5a3643

  4. d218ab3cdd086501d5d4bf585971b9358d303a60

  5. 601ecd1a4c8dfc4d2ad63e91b212abf36a049e74
  6. 0f15dc8a1330ee24816ac7f64d63afb0cd1ee725
  7. f4bfb891a9da0f052235299ad33d43bdf9ec7493

...

but my Java code is giving following results -

  1. 659621a4ccfa9b45416537aebb14cda0419bb82d
  2. b1d3bf705461754307237dd9ca2a2211f3ef4022
  3. c1d1a77fd4beb956c1a353c02da972c58f5a3643

  4. 67dce2a276a410805b064e962b6950c6d07cf436

  5. 60537d19617a81e9505240f1dc5ad0567978fd96
  6. 4f1dff9ee4d79487d898c4917ca9bc3d842dc6cf
  7. 53cd538018a2bf57998c65202d27d6423a6f02f3

As you can see from 4th commit onwards all commit names are wrong. Any idea what could possibly be wrong?

(BTW, that Java code gives correct result for our repository which we migrated from SVN to GIT.)

RĂ¼diger Herrmann
  • 20,512
  • 11
  • 62
  • 79
ajay.gour
  • 106
  • 1
  • 7

1 Answers1

1

Going by this link, it looks like there's a bug in JGit's copy detection - https://groups.google.com/forum/#!topic/repo-discuss/g96GClhlsh4.

ajay.gour
  • 106
  • 1
  • 7