use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.
the class ChangeEditModifier method rebase.
private void rebase(Repository repository, ChangeEdit changeEdit, PatchSet currentPatchSet) throws IOException, MergeConflictException, InvalidChangeOperationException, OrmException {
RevCommit currentEditCommit = changeEdit.getEditCommit();
if (currentEditCommit.getParentCount() == 0) {
throw new InvalidChangeOperationException("Rebase change edit against root commit not supported");
}
Change change = changeEdit.getChange();
RevCommit basePatchSetCommit = lookupCommit(repository, currentPatchSet);
RevTree basePatchSetTree = basePatchSetCommit.getTree();
ObjectId newTreeId = merge(repository, changeEdit, basePatchSetTree);
Timestamp nowTimestamp = TimeUtil.nowTs();
String commitMessage = currentEditCommit.getFullMessage();
ObjectId newEditCommitId = createCommit(repository, basePatchSetCommit, newTreeId, commitMessage, nowTimestamp);
String newEditRefName = getEditRefName(change, currentPatchSet);
updateReferenceWithNameChange(repository, changeEdit.getRefName(), currentEditCommit, newEditRefName, newEditCommitId, nowTimestamp);
reindex(change);
}
use of org.eclipse.jgit.revwalk.RevTree in project gitiles by GerritCodeReview.
the class TimeCacheTest method taggedTreeAndBlobTime.
@Test
public void taggedTreeAndBlobTime() throws Exception {
RevBlob blob = repo.blob("contents");
RevTree tree = repo.tree(repo.file("foo", blob));
repo.tick(1);
RevTag blobTag = repo.tag("blob", blob);
repo.tick(1);
RevTag treeTag = repo.tag("tree", tree);
assertThat(getTime(blobTag)).isEqualTo(start + 1);
assertThat(getTime(treeTag)).isEqualTo(start + 2);
}
use of org.eclipse.jgit.revwalk.RevTree in project gitiles by GerritCodeReview.
the class TimeCacheTest method treeAndBlobTime.
@Test
public void treeAndBlobTime() throws Exception {
RevBlob blob = repo.blob("contents");
RevTree tree = repo.tree(repo.file("foo", blob));
assertThat(getTime(blob)).isEqualTo(Long.MIN_VALUE);
assertThat(getTime(tree)).isEqualTo(Long.MIN_VALUE);
}
use of org.eclipse.jgit.revwalk.RevTree in project indy by Commonjava.
the class GitManager method verifyChangesExist.
private boolean verifyChangesExist(final Collection<String> paths) throws GitSubsystemException {
return lockAnd(me -> {
try {
final DiffFormatter formatter = new DiffFormatter(System.out);
formatter.setRepository(repo);
final ObjectId oid = repo.resolve(Constants.HEAD);
if (oid == null) {
return true;
}
final RevWalk walk = new RevWalk(repo);
final RevCommit commit = walk.parseCommit(oid);
final RevTree treeWalk = walk.parseTree(commit);
final List<TreeFilter> filters = new ArrayList<>();
for (final String path : paths) {
filters.add(PathFilter.create(path));
}
filters.add(TreeFilter.ANY_DIFF);
walk.setTreeFilter(AndTreeFilter.create(filters));
final CanonicalTreeParser tree = new CanonicalTreeParser();
final ObjectReader oldReader = repo.newObjectReader();
try {
tree.reset(oldReader, treeWalk.getId());
} finally {
oldReader.release();
}
walk.dispose();
final FileTreeIterator files = new FileTreeIterator(repo);
final List<DiffEntry> entries = formatter.scan(tree, files);
return entries != null && !entries.isEmpty();
} catch (final IOException e) {
throw new GitSubsystemException("Failed to scan for actual changes among: %s. Reason: %s", e, paths, e.getMessage());
}
});
}
use of org.eclipse.jgit.revwalk.RevTree in project searchcode-server by boyter.
the class GitService method fetchFileRevision.
/**
* Given a repository location, revision and file path will retrieve that files contents. N.B. it returns the whole
* file so you MAY end up running into serious memory issues, and should be aware of this
*/
public String fetchFileRevision(String repoLocation, String revision, String filePath) throws MissingObjectException, IncorrectObjectTypeException, IOException {
Repository localRepository = new FileRepository(new File(repoLocation));
ObjectId id = localRepository.resolve(revision);
ObjectReader reader = localRepository.newObjectReader();
try {
RevWalk walk = new RevWalk(reader);
RevCommit commit = walk.parseCommit(id);
RevTree tree = commit.getTree();
TreeWalk treewalk = TreeWalk.forPath(reader, filePath, tree);
if (treewalk != null) {
byte[] data = reader.open(treewalk.getObjectId(0)).getBytes();
return new String(data, "utf-8");
} else {
return "";
}
} finally {
reader.close();
}
}
Aggregations