Last active
October 1, 2015 12:02
-
-
Save stefanproell/b38e496a1259472c75f0 to your computer and use it in GitHub Desktop.
Get all commits from repository, which have been commited before a given date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get all commits of a file which have been issued before a specified date | |
* @param commitMap | |
* @param execDate | |
* @return | |
*/ | |
private TreeMap<DateTime,RevCommit> getAllCommitsBefore(Date execDate, String path){ | |
RevWalk walk = new RevWalk( this.repo ); | |
TreeMap<DateTime, RevCommit> commitsByDate = new TreeMap<DateTime, RevCommit>(); | |
try { | |
walk.markStart( walk.parseCommit( this.repo.resolve( Constants.HEAD ) ) ); | |
walk.sort( RevSort.COMMIT_TIME_DESC); | |
walk.setTreeFilter(PathFilter.create(path)); | |
for( RevCommit commit : walk ) { | |
if ( commit.getCommitterIdent().getWhen().before(execDate) ) { | |
DateTime commitTime = new DateTime(commit.getCommitterIdent().getWhen()); | |
commitsByDate.put(commitTime, commit); | |
} | |
} | |
walk.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
if(commitsByDate.size()==0){ | |
Logger.error("No commits before specified date"); | |
} | |
return commitsByDate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment