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

Hey

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

        walk.reset();

        try {
            walk.setRevFilter(RevFilter.NO_MERGES);
            walk.sort(RevSort.COMMIT_TIME_DESC, true);
            walk.markStart(start);

            if (reference != null) {
                walk.markUninteresting(reference);
            }

            RevCommit walked;
            while ((walked = walk.next()) != null) {
                if (walked.getCommitTime() <= limit) {
                    break;
                }

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

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

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

                for (CommitBundle bundle : bundles) {
                    bundle.addToBundle(info);
                }

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

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

        if (!unknownBundle.getBundledCommits().isEmpty()) {
            bundles.add(unknownBundle);
        }

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