java - How to define a "In between" JGit RevFilter? -


i trying implement revfilter used through revwalk#setrevfilter(). in following have tried:

private class inbetweenrevfilter extends revfilter {      private anyobjectid end;     private anyobjectid begin;      public inbetweenrevfilter(anyobjectid begin, anyobjectid end) {         this.begin = begin;         this.end = end;     }      @override     public revfilter clone() {         return this;     }      @override     public boolean include(revwalk walker, revcommit c)             throws stopwalkexception, missingobjectexception,             incorrectobjecttypeexception, ioexception {         revcommit = walker.parsecommit(begin);         revcommit = walker.parsecommit(end);         return (walker.ismergedinto(from, c) && walker.ismergedinto(c, to));     } } 

the result of filter should commit pushed after begin , before end. problem when set filter, commit marked start point revwalk.markstart(revcommit c) returned revwalk.next(). in following, show show how tried use filter:

    revwalk walk = new revwalk(getrepository());     revcommit begincommit = walk.parsecommit(getrepository().resolve(start));     revcommit endcommit = walk.parsecommit(getrepository().resolve(end));     walk.setrevfilter(new inbetweenrevfilter(begincommit.getid(), endcommit.getid()));     walk.markstart(endcommit);     (revcommit rev : walk) {         system.out.println(rev.getfullmessage());     }     walk.close(); 

in example, message endcommit printed in console. there other way this? or, missing or did wrong?

i published snippet @ jgit-cookbook shows 1 way this:

basically can start walk @ 1 commit , run walk until find second or commits on branch run out.

note go backwards in time here how git stores links between commits, i.e. start "to" newer commit , walk until reach "from".

        string = "3408efc41a51555d488d30d8a91ea560c5e13311";         string = "7228de6ebe2a3087118562414061af4e189624c0";          // revwalk allows walk on commits based on filtering defined         try (revwalk walk = new revwalk(repository)) {             revcommit commit = walk.parsecommit(repository.resolve(to));              system.out.println("walking commits starting @ " + + " until find " + from);             walk.markstart(commit);             int count = 0;             (revcommit rev : walk) {                 system.out.println("commit: " + rev);                 count++;                  if(rev.getid().getname().equals(from)) {                     system.out.println("found from, stopping walk");                     break;                 }             }             system.out.println(count);              walk.dispose();         } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -