Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] guru question about RevWalk - RevCommit buffer suddenly null


I have written some code that does some (company specific) branch analysis based on commit messages and such. I re-use the RevWalk instance on a second call. Since i added a call to markUninteresting(), things started to go bad: if i see a commit in a later call again that was uninteresting in a previous one, it's internal buffer seems to be null...

i think the relevant code is in the PendingGenerator, where it disposeBody()s the commits body if the commit is uninteresting. The RevWalk caches the commit, and won't parse it again, as it keeps it's parsed flag. Now every call to get*Message() for example will fail with a NPE, even though PARSED is there...

is there a way (apart from throwing away the RevWalk, which works ;)) to keep the caches, and still use uninteresting commits? currently i manually call walk.parseBody(walked) on all commits that the walk returns, just in case (that works, but somehow it feels wrong...).

here's what i do FYI:

     * Creates bundles for a pre-created set of commits.
    private synchronized List<CommitBundle> findBundles(RevCommit start, RevCommit reference,
            int limit) {
        Map<String, CommitBundle> bundleMap = new TreeMap<String, CommitBundle>();
        CommitBundle unknownBundle = new CommitBundle("(no request, no bug)", BundleType.Unknown);


        try {
            walk.sort(RevSort.COMMIT_TIME_DESC, true);

            if (reference != null) {

            RevCommit walked;
            while ((walked = != null) {
                if (walked.getCommitTime() <= limit) {

                // force body re-creation if the commit was uninteresting in a previous walk.
                // If you remove this line, getShortMessage() may die on NPE!

                System.out.println(walked.toString() + ": " + walked.getShortMessage());

                CommitInfo info = new CommitInfo(repository, walked);
                List<CommitBundle> bundles = findBundlesFor(walked, bundleMap);

                for (CommitBundle bundle : bundles) {

                if (bundles.isEmpty()) {
        } catch (Exception ex) {
            throw new RuntimeException(ex);

        List<CommitBundle> bundles = new ArrayList<CommitBundle>(bundleMap.values());

        if (!unknownBundle.getBundledCommits().isEmpty()) {

        Collections.sort(bundles, CommitBundleSortingComparator.INSTANCE);
        return bundles;

Back to the top