forked from andymeneely/developer-activity-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d5ebfc
commit c6dba9a
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
src/main/java/org/chaoticbits/devactivity/churn/git/CodeChurn.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.chaoticbits.devactivity.churn.git; | ||
|
||
import java.io.IOException; | ||
|
||
import org.eclipse.jgit.api.DiffCommand; | ||
import org.eclipse.jgit.api.Git; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.eclipse.jgit.api.errors.JGitInternalException; | ||
import org.eclipse.jgit.api.errors.NoHeadException; | ||
import org.eclipse.jgit.blame.BlameResult; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.eclipse.jgit.revwalk.RevCommit; | ||
import org.eclipse.jgit.treewalk.AbstractTreeIterator; | ||
import org.eclipse.jgit.treewalk.CanonicalTreeParser; | ||
|
||
public class CodeChurn { | ||
|
||
private final Repository repo; | ||
|
||
public CodeChurn(Repository gitRepo) { | ||
this.repo = gitRepo; | ||
} | ||
|
||
public int compute(String path) { | ||
Git git = new Git(repo); | ||
BlameResult call = git.blame().setFilePath(path).setFollowFileRenames(true).call(); | ||
|
||
try { | ||
Iterable<RevCommit> commits = git.log().addPath(path).call(); | ||
|
||
for (RevCommit revCommit : commits) { | ||
String fullMessage = revCommit.getFullMessage(); | ||
DiffCommand diff = git.diff(); | ||
AbstractTreeIterator newTree = new CanonicalTreeParser(); | ||
|
||
AbstractTreeIterator oldTree = new CanonicalTreeParser(); | ||
diff.setNewTree(newTree).setOldTree(oldTree).call(); | ||
} | ||
} catch (NoHeadException e) { | ||
e.printStackTrace(); | ||
} catch (JGitInternalException e) { | ||
e.printStackTrace(); | ||
} catch (GitAPIException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
throw new IllegalStateException("unimplemented!"); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/org/chaoticbits/devactivity/churn/git/GitCodeChurnTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.chaoticbits.devactivity.churn.git; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.File; | ||
|
||
import org.chaoticbits.devactivity.churn.git.CodeChurn; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.eclipse.jgit.storage.file.FileRepository; | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||
import org.junit.Test; | ||
|
||
public class GitCodeChurnTest { | ||
|
||
public static final File repoDir = new File("testdata/testgitrepo/.git"); | ||
|
||
@Test | ||
public void simpleCodeChurn() throws Exception { | ||
Repository gitRepo = new FileRepositoryBuilder().setGitDir(repoDir) | ||
.readEnvironment().findGitDir().build(); | ||
int churn = new CodeChurn(gitRepo) | ||
.compute("mancala/player/GreedyPlayer.java"); | ||
assertEquals(4, churn); | ||
} | ||
} |