use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class MergeUtil method canCherryPick.
public boolean canCherryPick(MergeSorter mergeSorter, Repository repo, CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge) throws IntegrationException {
if (mergeTip == null) {
//
return true;
}
if (toMerge.getParentCount() == 0) {
//
return false;
}
if (toMerge.getParentCount() == 1) {
//
try (ObjectInserter ins = new InMemoryInserter(repo)) {
ThreeWayMerger m = newThreeWayMerger(ins, repo.getConfig());
m.setBase(toMerge.getParent(0));
return m.merge(mergeTip, toMerge);
} catch (IOException e) {
throw new IntegrationException(String.format("Cannot merge commit %s with mergetip %s", toMerge.name(), mergeTip.name()), e);
}
}
//
return canFastForward(mergeSorter, mergeTip, rw, toMerge) || canMerge(mergeSorter, repo, mergeTip, toMerge);
}
use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class NoteDbUpdateManager method openRepo.
private OpenRepo openRepo(Project.NameKey p) throws IOException {
// Closed by OpenRepo#close.
Repository repo = repoManager.openRepository(p);
// Closed by OpenRepo#close.
ObjectInserter ins = repo.newObjectInserter();
// Not closed by OpenRepo#close.
ObjectReader reader = ins.newReader();
try (RevWalk rw = new RevWalk(reader)) {
// Doesn't escape OpenRepo constructor.
return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true) {
@Override
public void close() {
reader.close();
super.close();
}
};
}
}
use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class RepoSequence method store.
private RefUpdate.Result store(Repository repo, RevWalk rw, @Nullable ObjectId oldId, int val) throws IOException {
ObjectId newId;
try (ObjectInserter ins = repo.newObjectInserter()) {
newId = ins.insert(OBJ_BLOB, Integer.toString(val).getBytes(UTF_8));
ins.flush();
}
RefUpdate ru = repo.updateRef(refName);
if (oldId != null) {
ru.setExpectedOldObjectId(oldId);
}
ru.setNewObjectId(newId);
// Required for non-commitish updates.
ru.setForceUpdate(true);
return ru.update(rw);
}
use of org.eclipse.jgit.lib.ObjectInserter in project gitiles by GerritCodeReview.
the class TimeCacheTest method tagMissingTime.
@Test
public void tagMissingTime() throws Exception {
RevCommit commit = repo.commit().create();
TagBuilder builder = new TagBuilder();
builder.setObjectId(commit);
builder.setTag("tag");
builder.setMessage("");
ObjectId id;
try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
id = ins.insert(builder);
ins.flush();
}
assertThat(getTime(commit)).isEqualTo(start + 1);
assertThat(getTime(id)).isEqualTo(start + 1);
}
use of org.eclipse.jgit.lib.ObjectInserter in project gitiles by GerritCodeReview.
the class TimeCacheTest method firstTagMissingTime.
@Test
public void firstTagMissingTime() throws Exception {
RevCommit commit = repo.commit().create();
repo.tick(1);
RevTag tag = repo.tag("tag", commit);
repo.tick(1);
TagBuilder builder = new TagBuilder();
builder.setObjectId(tag);
builder.setTag("tagtag");
builder.setMessage("");
ObjectId tagTagId;
try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
tagTagId = ins.insert(builder);
ins.flush();
}
assertThat(getTime(commit)).isEqualTo(start + 1);
assertThat(getTime(tag)).isEqualTo(start + 2);
assertThat(getTime(tagTagId)).isEqualTo(start + 2);
}
Aggregations