Make more fast and github-like repository viewer

This commit is contained in:
Tomofumi Tanaka
2013-07-30 03:26:36 +09:00
parent 1f2b6a0acc
commit 7079d50fdf

View File

@@ -348,51 +348,11 @@ object JGitUtil {
* @return the list of latest commit * @return the list of latest commit
*/ */
def getLatestCommitFromPaths(git: Git, paths: List[String], revision: String): Map[String, RevCommit] = { def getLatestCommitFromPaths(git: Git, paths: List[String], revision: String): Map[String, RevCommit] = {
val start = git.getRepository.resolve(revision)
val map = new scala.collection.mutable.HashMap[String, RevCommit] paths.map { path =>
val commit = git.log.add(start).addPath(path).setMaxCount(1).call.iterator.next
val revWalk = new RevWalk(git.getRepository) (path, commit)
revWalk.markStart(revWalk.parseCommit(git.getRepository.resolve(revision))) }.toMap
//revWalk.sort(RevSort.REVERSE);
val i = revWalk.iterator
while(i.hasNext && map.size != paths.length){
val commit = i.next
if(commit.getParentCount == 0){
// Initial commit
val treeWalk = new TreeWalk(git.getRepository)
treeWalk.reset()
treeWalk.setRecursive(true)
treeWalk.addTree(commit.getTree)
while (treeWalk.next) {
paths.foreach { path =>
if(treeWalk.getPathString.startsWith(path) && !map.contains(path)){
map.put(path, commit)
}
}
}
treeWalk.release
} else {
(0 to commit.getParentCount - 1).foreach { i =>
val parent = revWalk.parseCommit(commit.getParent(i).getId())
val df = new DiffFormatter(DisabledOutputStream.INSTANCE)
df.setRepository(git.getRepository)
df.setDiffComparator(RawTextComparator.DEFAULT)
df.setDetectRenames(true)
val diffs = df.scan(parent.getTree(), commit.getTree)
diffs.asScala.foreach { diff =>
paths.foreach { path =>
if(diff.getChangeType != ChangeType.DELETE && diff.getNewPath.startsWith(path) && !map.contains(path)){
map.put(path, commit)
}
}
}
}
}
revWalk.release
}
map.toMap
} }
/** /**