use of org.eclipse.jgit.lib.RefUpdate.Result in project gitblit by gitblit.
the class BranchTicketService method getTicketsBranch.
/**
* Returns a RefModel for the refs/meta/gitblit/tickets branch in the repository.
* If the branch can not be found, null is returned.
*
* @return a refmodel for the gitblit tickets branch or null
*/
private RefModel getTicketsBranch(Repository db) {
List<RefModel> refs = JGitUtils.getRefs(db, "refs/");
Ref oldRef = null;
for (RefModel ref : refs) {
if (ref.reference.getName().equals(BRANCH)) {
return ref;
} else if (ref.reference.getName().equals("refs/gitblit/tickets")) {
oldRef = ref.reference;
}
}
if (oldRef != null) {
// rename old ref to refs/meta/gitblit/tickets
RefRename cmd;
try {
cmd = db.renameRef(oldRef.getName(), BRANCH);
cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost"));
cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + BRANCH);
Result res = cmd.rename();
switch(res) {
case RENAMED:
log.info(db.getDirectory() + " " + cmd.getRefLogMessage());
return getTicketsBranch(db);
default:
log.error("failed to rename " + oldRef.getName() + " => " + BRANCH + " (" + res.name() + ")");
}
} catch (IOException e) {
log.error("failed to rename tickets branch", e);
}
}
return null;
}
use of org.eclipse.jgit.lib.RefUpdate.Result in project gerrit by GerritCodeReview.
the class ProjectConfigTest method update.
private void update(RevCommit rev) throws Exception {
RefUpdate u = db.updateRef(RefNames.REFS_CONFIG);
u.disableRefLog();
u.setNewObjectId(rev);
Result result = u.forceUpdate();
assert_().withFailureMessage("Cannot update ref for test: " + result).that(result).isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
}
use of org.eclipse.jgit.lib.RefUpdate.Result in project gerrit by GerritCodeReview.
the class AccountsUpdate method createUserBranch.
public static void createUserBranch(Repository repo, ObjectInserter oi, PersonIdent committerIdent, PersonIdent authorIdent, Account account) throws IOException {
ObjectId id = createInitialEmptyCommit(oi, committerIdent, authorIdent, account.getRegisteredOn());
String refName = RefNames.refsUsers(account.getId());
RefUpdate ru = repo.updateRef(refName);
ru.setExpectedOldObjectId(ObjectId.zeroId());
ru.setNewObjectId(id);
ru.setForceUpdate(true);
ru.setRefLogIdent(committerIdent);
ru.setRefLogMessage("Create Account", true);
Result result = ru.update();
if (result != Result.NEW) {
throw new IOException(String.format("Failed to update ref %s: %s", refName, result.name()));
}
}
use of org.eclipse.jgit.lib.RefUpdate.Result in project gerrit by GerritCodeReview.
the class NotesBranchUtil method updateRef.
private void updateRef(String notesBranch) throws IOException, MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, ConcurrentRefUpdateException {
if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) {
// Avoid saving this commit as it has no new information.
return;
}
int remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
RefUpdate refUpdate = createRefUpdate(notesBranch, oursCommit, baseCommit);
for (; ; ) {
Result result = refUpdate.update();
if (result == Result.LOCK_FAILURE) {
if (--remainingLockFailureCalls > 0) {
try {
Thread.sleep(SLEEP_ON_LOCK_FAILURE_MS);
} catch (InterruptedException e) {
// ignore
}
} else {
throw new ConcurrentRefUpdateException("Failed to lock the ref: " + notesBranch, refUpdate.getRef(), result);
}
} else if (result == Result.REJECTED) {
RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId());
NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit);
NoteMapMerger merger = new NoteMapMerger(db, getNoteMerger(), MergeStrategy.RESOLVE);
NoteMap merged = merger.merge(base, ours, theirs);
RevCommit mergeCommit = createCommit(merged, gerritIdent, "Merged note commits\n", theirsCommit, oursCommit);
refUpdate = createRefUpdate(notesBranch, mergeCommit, theirsCommit);
remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
} else if (result == Result.IO_FAILURE) {
throw new IOException("Couldn't update " + notesBranch + ". " + result.name());
} else {
gitRefUpdated.fire(project, refUpdate, null);
break;
}
}
}
Aggregations