use of com.searchcode.app.service.GitService in project searchcode-server by boyter.
the class IndexGitHistoryJob method getRevisionChanges.
public void getRevisionChanges(Repository localRepository, Git git, GitChangeSet oldRevison, GitChangeSet newRevision) throws IOException, GitAPIException {
ObjectId oldHead = localRepository.resolve(oldRevison.getRevision() + "^{tree}");
ObjectId newHead = localRepository.resolve(newRevision.getRevision() + "^{tree}");
ObjectReader reader = localRepository.newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, oldHead);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, newHead);
List<DiffEntry> entries = git.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call();
GitService gs = new GitService();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
for (DiffEntry entry : entries) {
if ("DELETE".equals(entry.getChangeType().name())) {
System.out.println("DEL " + entry.getOldPath());
String contents = gs.fetchFileRevision(localRepository.getWorkTree().toString() + "/.git", oldRevison.getRevision(), entry.getOldPath());
CodeIndexDocument cd = new CodeIndexDocument(entry.getNewPath(), "thumbor", entry.getOldPath(), entry.getOldPath(), entry.getOldPath(), "md5hash", "Java", contents.split("\\r?\\n").length, contents, "", oldRevison.getAuthor());
cd.setRevision(oldRevison.getRevision());
cd.setYearMonthDay(sdf.format(oldRevison.getExpiry()));
cd.setYearMonth(cd.getYearMonthDay().substring(0, 6));
cd.setYear(cd.getYearMonthDay().substring(0, 4));
cd.setMessage(oldRevison.getMessage());
cd.setDeleted("TRUE");
Singleton.getCodeIndexer().indexTimeDocument(cd);
} else {
System.out.println("ADD " + entry.getNewPath());
String contents = gs.fetchFileRevision(localRepository.getWorkTree().toString() + "/.git", newRevision.getRevision(), entry.getNewPath());
CodeIndexDocument cd = new CodeIndexDocument(entry.getNewPath(), "thumbor", entry.getNewPath(), entry.getNewPath(), entry.getNewPath(), "md5hash", "Java", contents.split("\\r?\\n").length, contents, "", newRevision.getAuthor());
cd.setRevision(newRevision.getRevision());
cd.setYearMonthDay(sdf.format(oldRevison.getExpiry()));
cd.setYearMonth(cd.getYearMonthDay().substring(0, 6));
cd.setYear(cd.getYearMonthDay().substring(0, 4));
cd.setMessage(newRevision.getMessage());
cd.setDeleted("FALSE");
Singleton.getCodeIndexer().indexTimeDocument(cd);
}
}
}
Aggregations