use of org.eclipse.jgit.diff.DiffEntry 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);
}
}
}
use of org.eclipse.jgit.diff.DiffEntry in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method loadPatch.
@Override
public Patch loadPatch(PatchDetailsRequest request) throws PatchException {
File descriptor = new File(patchesDir, request.getPatchId() + ".patch");
try {
Patch patch = loadPatch(descriptor, true);
if (patch == null) {
return null;
}
Git repo = gitPatchRepository.findOrCreateMainGitRepository();
List<DiffEntry> diff = null;
if (request.isFiles() || request.isDiff()) {
// fetch the information from git
ObjectId commitId = repo.getRepository().resolve(patch.getManagedPatch().getCommitId());
RevCommit commit = new RevWalk(repo.getRepository()).parseCommit(commitId);
diff = gitPatchRepository.diff(repo, commit.getParent(0), commit);
}
if (request.isBundles()) {
// it's already in PatchData
}
if (request.isFiles() && diff != null) {
for (DiffEntry de : diff) {
DiffEntry.ChangeType ct = de.getChangeType();
String newPath = de.getNewPath();
String oldPath = de.getOldPath();
switch(ct) {
case ADD:
patch.getManagedPatch().getFilesAdded().add(newPath);
break;
case MODIFY:
patch.getManagedPatch().getFilesModified().add(newPath);
break;
case DELETE:
patch.getManagedPatch().getFilesRemoved().add(oldPath);
break;
}
}
}
if (request.isDiff() && diff != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DiffFormatter formatter = new DiffFormatter(baos);
formatter.setContext(4);
formatter.setRepository(repo.getRepository());
for (DiffEntry de : diff) {
formatter.format(de);
}
formatter.flush();
patch.getManagedPatch().setUnifiedDiff(new String(baos.toByteArray(), "UTF-8"));
}
return patch;
} catch (IOException | GitAPIException e) {
throw new PatchException(e.getMessage(), e);
}
}
use of org.eclipse.jgit.diff.DiffEntry in project incubator-gobblin by apache.
the class GitConfigMonitor method processGitConfigChanges.
/**
* Fetch the list of changes since the last refresh of the repository and apply the changes to the {@link FlowCatalog}
* @throws GitAPIException
* @throws IOException
*/
@VisibleForTesting
void processGitConfigChanges() throws GitAPIException, IOException {
// if not active or if the flow catalog is not up yet then can't process config changes
if (!isActive || !this.flowCatalog.isRunning()) {
log.info("GitConfigMonitor: skip poll since the JobCatalog is not yet running.");
return;
}
List<DiffEntry> changes = this.gitRepo.getChanges();
for (DiffEntry change : changes) {
switch(change.getChangeType()) {
case ADD:
case MODIFY:
addSpec(change);
break;
case DELETE:
removeSpec(change);
break;
case RENAME:
removeSpec(change);
addSpec(change);
break;
default:
throw new RuntimeException("Unsupported change type " + change.getChangeType());
}
}
// Done processing changes, so checkpoint
this.gitRepo.moveCheckpointAndHashesForward();
}
use of org.eclipse.jgit.diff.DiffEntry in project MGit by maks.
the class CommitDiffTask method doInBackground.
@Override
protected Boolean doInBackground(Void... params) {
boolean result = getCommitDiff();
if (!result) {
return false;
}
mDiffStrs = new ArrayList<String>(mDiffEntries.size());
for (DiffEntry diffEntry : mDiffEntries) {
try {
String diffStr = parseDiffEntry(diffEntry);
mDiffStrs.add(diffStr);
} catch (StopTaskException e) {
return false;
}
}
return true;
}
use of org.eclipse.jgit.diff.DiffEntry in project gitiles by GerritCodeReview.
the class LogSoyData method toEntrySoyData.
private Map<String, Object> toEntrySoyData(Paginator paginator, RevCommit c, DateFormatter df) throws IOException {
if (csd == null) {
csd = new CommitSoyData();
}
Map<String, Object> entry = csd.setRevWalk(paginator.getWalk()).toSoyData(req, c, fields, df);
DiffEntry rename = paginator.getRename(c);
if (rename != null) {
entry.put("rename", toRenameSoyData(rename));
}
return ImmutableMap.of("variant", variant, "entry", entry);
}
Aggregations