use of org.eclipse.jgit.lib.RefUpdate in project egit by eclipse.
the class GitRepositoriesViewTestBase method createStableBranch.
protected static void createStableBranch(Repository myRepository) throws IOException {
// let's create a stable branch temporarily so
// that we push two branches to remote
String newRefName = "refs/heads/stable";
RefUpdate updateRef = myRepository.updateRef(newRefName);
Ref sourceBranch = myRepository.exactRef("refs/heads/master");
ObjectId startAt = sourceBranch.getObjectId();
String startBranch = Repository.shortenRefName(sourceBranch.getName());
updateRef.setNewObjectId(startAt);
updateRef.setRefLogMessage("branch: Created from " + startBranch, // $NON-NLS-1$
false);
updateRef.update();
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class StarredChangesUtil method updateLabels.
private void updateLabels(Repository repo, String refName, ObjectId oldObjectId, Collection<String> labels) throws IOException, InvalidLabelsException {
try (TraceTimer traceTimer = TraceContext.newTimer("Update star labels", Metadata.builder().noteDbRefName(refName).resourceCount(labels.size()).build());
RevWalk rw = new RevWalk(repo)) {
RefUpdate u = repo.updateRef(refName);
u.setExpectedOldObjectId(oldObjectId);
u.setForceUpdate(true);
u.setNewObjectId(writeLabels(repo, labels));
u.setRefLogIdent(serverIdent.get());
u.setRefLogMessage("Update star labels", true);
RefUpdate.Result result = u.update(rw);
switch(result) {
case NEW:
case FORCED:
case NO_CHANGE:
case FAST_FORWARD:
gitRefUpdated.fire(allUsers, u, null);
return;
case LOCK_FAILURE:
throw new LockFailureException(String.format("Update star labels on ref %s failed", refName), u);
case IO_FAILURE:
case NOT_ATTEMPTED:
case REJECTED:
case REJECTED_CURRENT_BRANCH:
case RENAMED:
case REJECTED_MISSING_OBJECT:
case REJECTED_OTHER_REASON:
default:
throw new StorageException(String.format("Update star labels on ref %s failed: %s", refName, result.name()));
}
}
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class ConsistencyChecker method fixPatchSetRef.
private void fixPatchSetRef(ProblemInfo p, PatchSet ps) {
try {
RefUpdate ru = repo.updateRef(ps.id().toRefName());
ru.setForceUpdate(true);
ru.setNewObjectId(ps.commitId());
ru.setRefLogIdent(newRefLogIdent());
ru.setRefLogMessage("Repair patch set ref", true);
RefUpdate.Result result = ru.update();
switch(result) {
case NEW:
case FORCED:
case FAST_FORWARD:
case NO_CHANGE:
p.status = Status.FIXED;
p.outcome = "Repaired patch set ref";
return;
case IO_FAILURE:
case LOCK_FAILURE:
case NOT_ATTEMPTED:
case REJECTED:
case REJECTED_CURRENT_BRANCH:
case RENAMED:
case REJECTED_MISSING_OBJECT:
case REJECTED_OTHER_REASON:
default:
p.status = Status.FIX_FAILED;
p.outcome = "Failed to update patch set ref: " + result;
return;
}
} catch (IOException e) {
String msg = "Error fixing patch set ref";
logger.atWarning().withCause(e).log("%s %s", msg, ps.id().toRefName());
p.status = Status.FIX_FAILED;
p.outcome = msg;
}
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class IntBlob method tryStore.
public static RefUpdate tryStore(Repository repo, RevWalk rw, Project.NameKey projectName, String refName, @Nullable ObjectId oldId, int val, GitReferenceUpdated gitRefUpdated) throws IOException {
ObjectId newId;
try (ObjectInserter ins = repo.newObjectInserter()) {
logger.atFine().log("storing value %d on %s in %s (oldId: %s)", val, refName, projectName, oldId == null ? "null" : oldId.name());
newId = ins.insert(OBJ_BLOB, Integer.toString(val).getBytes(UTF_8));
ins.flush();
logger.atFine().log("successfully stored %d on %s as %s in %s", val, refName, newId.name(), projectName);
}
RefUpdate ru = repo.updateRef(refName);
if (oldId != null) {
ru.setExpectedOldObjectId(oldId);
}
ru.disableRefLog();
ru.setNewObjectId(newId);
// Required for non-commitish updates.
ru.setForceUpdate(true);
RefUpdate.Result result = ru.update(rw);
if (refUpdated(result)) {
gitRefUpdated.fire(projectName, ru, null);
}
return ru;
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class RepoSequence method acquire.
/**
* Updates the next available sequence number in NoteDb in order to have a batch of sequence
* numbers available that can be handed out. {@link #counter} stores the next sequence number that
* can be handed out. When {@link #limit} is reached a new batch of sequence numbers needs to be
* retrieved by calling this method.
*
* <p><strong>Note:</strong> Callers are required to acquire the {@link #counterLock} before
* calling this method.
*
* @param count the number of sequence numbers which should be retrieved
*/
private void acquire(int count) {
try (Repository repo = repoManager.openRepository(projectName);
RevWalk rw = new RevWalk(repo)) {
logger.atFine().log("acquire %d ids on %s in %s", count, refName, projectName);
Optional<IntBlob> blob = IntBlob.parse(repo, refName, rw);
afterReadRef.run();
ObjectId oldId;
int next;
if (!blob.isPresent()) {
oldId = ObjectId.zeroId();
next = seed.get();
} else {
oldId = blob.get().id();
next = blob.get().value();
}
next = Math.max(floor, next);
RefUpdate refUpdate = IntBlob.tryStore(repo, rw, projectName, refName, oldId, next + count, gitRefUpdated);
RefUpdateUtil.checkResult(refUpdate);
counter = next;
limit = counter + count;
acquireCount++;
} catch (IOException e) {
throw new StorageException(e);
}
}
Aggregations