use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method rebuildDeletesOldDraftRefs.
@Test
public void rebuildDeletesOldDraftRefs() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
putDraft(user, id, 1, "comment", null);
Account.Id otherAccountId = new Account.Id(user.getId().get() + 1234);
String otherDraftRef = refsDraftComments(id, otherAccountId);
try (Repository repo = repoManager.openRepository(allUsers);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId sha = ins.insert(OBJ_BLOB, "garbage data".getBytes(UTF_8));
ins.flush();
RefUpdate ru = repo.updateRef(otherDraftRef);
ru.setExpectedOldObjectId(ObjectId.zeroId());
ru.setNewObjectId(sha);
assertThat(ru.update()).isEqualTo(RefUpdate.Result.NEW);
}
checker.rebuildAndCheckChanges(id);
try (Repository repo = repoManager.openRepository(allUsers)) {
assertThat(repo.exactRef(otherDraftRef)).isNull();
}
}
use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class StarredChangesUtil method writeLabels.
public static ObjectId writeLabels(Repository repo, Collection<String> labels) throws IOException {
validateLabels(labels);
try (ObjectInserter oi = repo.newObjectInserter()) {
ObjectId id = oi.insert(Constants.OBJ_BLOB, labels.stream().sorted().distinct().collect(joining("\n")).getBytes(UTF_8));
oi.flush();
return id;
}
}
use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class Rebase method applyImpl.
@Override
protected ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, RevisionResource rsrc, RebaseInput input) throws EmailException, OrmException, UpdateException, RestApiException, IOException, NoSuchChangeException, PermissionBackendException {
rsrc.permissions().database(dbProvider).check(ChangePermission.REBASE);
ChangeControl control = rsrc.getControl();
Change change = rsrc.getChange();
try (Repository repo = repoManager.openRepository(change.getProject());
ObjectInserter oi = repo.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader);
BatchUpdate bu = updateFactory.create(dbProvider.get(), change.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
if (!change.getStatus().isOpen()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!hasOneParent(rw, rsrc.getPatchSet())) {
throw new ResourceConflictException("cannot rebase merge commits or commit with no ancestor");
}
bu.setRepository(repo, rw, oi);
bu.addOp(change.getId(), rebaseFactory.create(control, rsrc.getPatchSet(), findBaseRev(repo, rw, rsrc, input)).setForceContentMerge(true).setFireRevisionCreated(true));
bu.execute();
}
return json.create(OPTIONS).format(change.getProject(), change.getId());
}
use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class AllProjectsCreator method initSequences.
private void initSequences(Repository git, BatchRefUpdate bru) throws IOException {
if (notesMigration.readChangeSequence() && git.exactRef(REFS_SEQUENCES + Sequences.CHANGES) == null) {
// initialization unduly.
try (ObjectInserter ins = git.newObjectInserter()) {
bru.addCommand(RepoSequence.storeNew(ins, Sequences.CHANGES, firstChangeId));
ins.flush();
}
}
}
use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.
the class RepoSequenceTest method writeBlob.
private ObjectId writeBlob(String sequenceName, String value) {
String refName = RefNames.REFS_SEQUENCES + sequenceName;
try (Repository repo = repoManager.openRepository(project);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId newId = ins.insert(OBJ_BLOB, value.getBytes(UTF_8));
ins.flush();
RefUpdate ru = repo.updateRef(refName);
ru.setNewObjectId(newId);
assertThat(ru.forceUpdate()).isAnyOf(RefUpdate.Result.NEW, RefUpdate.Result.FORCED);
return newId;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations