3

I'm having a issue where commits are being displayed out of order. The reason is not important, I just need to retrieve the commits and display them correctly in a changelog. I have done some research and the best solution I can find is using jGits RevSort.TOPO to sort a RevWalk topologically using jGit.
This is what i have so far but it does not work, commits are being returned as before unsorted. Other sorting methods are working fine e.g. RevSort.REVERSE but TOPO is not having any effect

    RevWalk walk = new RevWalk(repo);
    ObjectId head = repo.resolve("HEAD");
    RevCommit recentCommit = walk.parseCommit(head);
    walk.sort(RevSort.TOPO);
    walk.sort(RevSort.COMMIT_TIME_DESC, true);
    walk.markStart(mostRecentCommit);

    List<String> messages = new ArrayList<String>();
    for (Iterator<RevCommit> iterator = walk.iterator(); iterator.hasNext();) {
        RevCommit commit = iterator.next();
        messages.add(commit.getFullMessage());
    }

Using git log it gives the below. Commit a867b4a - Added new functionality should be in the next version 1.12.

$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date:   Thu Nov 4 18:59:41 2010 -0400
      - prepare release version 1.12

commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date:   Thu Nov 4 05:13:39 2010 -0400
      - More stuff

commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date:   Thu Nov 4 00:55:06 2010 -0400
         prepare release version **1.11**

commit **a867b4af366350be2e7c21b8de9cc6504678a61b`**
Author: Me <me@me.com>
Date:   Thu Nov 4 18:59:41 2010 -0400
      - Added new functionality

git log --topo-order works Commit a867b4a - Added new functionality is in the correct tag 1.12

$ git log --topo-order
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date:   Thu Nov 4 18:59:41 2010 -0400
      - prepare release version 1.12

commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date:   Thu Nov 4 05:13:39 2010 -0400
      - More stuff

commit **a867b4af366350be2e7c21b8de9cc6504678a61b`**
Author: Me <me@me.com>
Date:   Thu Nov 4 18:59:41 2010 -0400
      - Added new functionality

commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date:   Thu Nov 4 00:55:06 2010 -0400
         prepare release version 1.11
ciffieM
  • 41
  • 5

0 Answers0