本文整理汇总了Java中org.eclipse.jgit.lib.RefUpdate.setExpectedOldObjectId方法的典型用法代码示例。如果您正苦于以下问题:Java RefUpdate.setExpectedOldObjectId方法的具体用法?Java RefUpdate.setExpectedOldObjectId怎么用?Java RefUpdate.setExpectedOldObjectId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.lib.RefUpdate
的用法示例。
在下文中一共展示了RefUpdate.setExpectedOldObjectId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteRef
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private static void deleteRef(Repository repo, ChangeEdit edit) throws IOException {
String refName = edit.getRefName();
RefUpdate ru = repo.updateRef(refName, true);
ru.setExpectedOldObjectId(edit.getEditCommit());
ru.setForceUpdate(true);
RefUpdate.Result result = ru.delete();
switch (result) {
case FORCED:
case NEW:
case NO_CHANGE:
break;
case FAST_FORWARD:
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:
throw new IOException(String.format("Failed to delete ref %s: %s", refName, result));
}
}
示例2: updateReference
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void updateReference(
Repository repository,
String refName,
ObjectId currentObjectId,
ObjectId targetObjectId,
Timestamp timestamp)
throws IOException {
RefUpdate ru = repository.updateRef(refName);
ru.setExpectedOldObjectId(currentObjectId);
ru.setNewObjectId(targetObjectId);
ru.setRefLogIdent(getRefLogIdent(timestamp));
ru.setRefLogMessage("inline edit (amend)", false);
ru.setForceUpdate(true);
try (RevWalk revWalk = new RevWalk(repository)) {
RefUpdate.Result res = ru.update(revWalk);
if (res != RefUpdate.Result.NEW && res != RefUpdate.Result.FORCED) {
throw new IOException(
"cannot update "
+ ru.getName()
+ " in "
+ repository.getDirectory()
+ ": "
+ ru.getResult());
}
}
}
示例3: store
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
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.disableRefLog();
ru.setNewObjectId(newId);
ru.setForceUpdate(true); // Required for non-commitish updates.
RefUpdate.Result result = ru.update(rw);
if (refUpdated(result)) {
gitRefUpdated.fire(projectName, ru, null);
}
return result;
}
示例4: deleteUserBranch
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public static void deleteUserBranch(
Repository repo,
Project.NameKey project,
GitReferenceUpdated gitRefUpdated,
@Nullable IdentifiedUser user,
PersonIdent refLogIdent,
Account.Id accountId)
throws IOException {
String refName = RefNames.refsUsers(accountId);
Ref ref = repo.exactRef(refName);
if (ref == null) {
return;
}
RefUpdate ru = repo.updateRef(refName);
ru.setExpectedOldObjectId(ref.getObjectId());
ru.setNewObjectId(ObjectId.zeroId());
ru.setForceUpdate(true);
ru.setRefLogIdent(refLogIdent);
ru.setRefLogMessage("Delete Account", true);
Result result = ru.delete();
if (result != Result.FORCED) {
throw new IOException(String.format("Failed to delete ref %s: %s", refName, result.name()));
}
gitRefUpdated.fire(project, ru, user != null ? user.getAccount() : null);
}
示例5: createUserBranch
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public void createUserBranch(
Repository repo,
ObjectInserter oi,
ObjectId emptyTree,
Account.Id accountId,
Timestamp registeredOn)
throws IOException {
ObjectId id = createInitialEmptyCommit(oi, emptyTree, registeredOn);
String refName = RefNames.refsUsers(accountId);
RefUpdate ru = repo.updateRef(refName);
ru.setExpectedOldObjectId(ObjectId.zeroId());
ru.setNewObjectId(id);
ru.setRefLogIdent(serverIdent);
ru.setRefLogMessage(CREATE_ACCOUNT_MSG, false);
Result result = ru.update();
if (result != Result.NEW) {
throw new IOException(String.format("Failed to update ref %s: %s", refName, result.name()));
}
}
示例6: createGroupBranch
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void createGroupBranch(Project.NameKey project, String ref) throws IOException {
try (Repository r = repoManager.openRepository(project);
ObjectInserter oi = r.newObjectInserter();
RevWalk rw = new RevWalk(r)) {
ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, new byte[] {});
PersonIdent ident = new PersonIdent(serverIdent.get(), TimeUtil.nowTs());
CommitBuilder cb = new CommitBuilder();
cb.setTreeId(emptyTree);
cb.setCommitter(ident);
cb.setAuthor(ident);
cb.setMessage("Create group");
ObjectId emptyCommit = oi.insert(cb);
oi.flush();
RefUpdate updateRef = r.updateRef(ref);
updateRef.setExpectedOldObjectId(ObjectId.zeroId());
updateRef.setNewObjectId(emptyCommit);
assertThat(updateRef.update(rw)).isEqualTo(RefUpdate.Result.NEW);
}
}
示例7: rebuildDeletesOldDraftRefs
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@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();
}
}
示例8: afterUpdateRepos
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Override
public void afterUpdateRepos() throws Exception {
// Reopen repo and update ref, to simulate a concurrent write in another
// thread. Only do this the first time the listener is called.
if (calledCount.getAndIncrement() > 0) {
return;
}
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo);
ObjectInserter ins = repo.newObjectInserter()) {
String master = "refs/heads/master";
ObjectId oldId = repo.exactRef(master).getObjectId();
ObjectId newId = newCommit(rw, ins, oldId, MSG_PREFIX + calledCount.get());
ins.flush();
RefUpdate ru = repo.updateRef(master);
ru.setExpectedOldObjectId(oldId);
ru.setNewObjectId(newId);
assertThat(ru.update(rw)).isEqualTo(RefUpdate.Result.FAST_FORWARD);
}
}
示例9: updateRef
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
protected void updateRef(String refName, String newValue, @Nullable String oldValue) {
try {
RefUpdate update = git.getRepository().updateRef(refName);
update.setNewObjectId(git.getRepository().resolve(newValue));
if (oldValue != null)
update.setExpectedOldObjectId(git.getRepository().resolve(oldValue));
update.setRefLogIdent(user);
update.setRefLogMessage("update ref", false);
GitUtils.updateRef(update);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: updateRef
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
* Updates the given ref to the new commit.
*/
public static RefUpdate updateRef(Repository repo, ObjectId newObjectId,
ObjectId expectedOldObjectId, String refName) throws IOException {
RefUpdate refUpdate = repo.updateRef(refName);
refUpdate.setNewObjectId(newObjectId);
if (expectedOldObjectId == null) {
refUpdate.setExpectedOldObjectId(ObjectId.zeroId());
} else {
refUpdate.setExpectedOldObjectId(expectedOldObjectId);
}
return refUpdate;
}
示例11: updateRef
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void updateRef(Repository repo, PersonIdent ident, ObjectId newRevision, String refLogMsg)
throws IOException {
RefUpdate ru = repo.updateRef(getRefName());
ru.setRefLogIdent(ident);
ru.setNewObjectId(newRevision);
ru.setExpectedOldObjectId(revision);
ru.setRefLogMessage(refLogMsg, false);
RefUpdate.Result r = ru.update();
switch (r) {
case FAST_FORWARD:
case NEW:
case NO_CHANGE:
break;
case FORCED:
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:
throw new IOException(
"Failed to update " + getRefName() + " of " + project + ": " + r.name());
}
}
示例12: updateLabels
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void updateLabels(
Repository repo, String refName, ObjectId oldObjectId, Collection<String> labels)
throws IOException, OrmException, InvalidLabelsException {
try (RevWalk rw = new RevWalk(repo)) {
RefUpdate u = repo.updateRef(refName);
u.setExpectedOldObjectId(oldObjectId);
u.setForceUpdate(true);
u.setNewObjectId(writeLabels(repo, labels));
u.setRefLogIdent(serverIdent);
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 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:
throw new OrmException(
String.format("Update star labels on ref %s failed: %s", refName, result.name()));
}
}
}
示例13: deleteRef
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void deleteRef(Repository repo, String refName, ObjectId oldObjectId)
throws IOException, OrmException {
RefUpdate u = repo.updateRef(refName);
u.setForceUpdate(true);
u.setExpectedOldObjectId(oldObjectId);
u.setRefLogIdent(serverIdent);
u.setRefLogMessage("Unstar change", true);
RefUpdate.Result result = u.delete();
switch (result) {
case FORCED:
gitRefUpdated.fire(allUsers, u, null);
return;
case NEW:
case NO_CHANGE:
case FAST_FORWARD:
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:
throw new OrmException(
String.format("Delete star ref %s failed: %s", refName, result.name()));
}
}
示例14: execute
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public void execute() throws IOException, ConcurrentRefUpdateException {
final ObjectId headId = git.getLastCommit(Constants.R_HEADS + name);
final RefUpdate ru = git.getRepository().updateRef(Constants.R_HEADS + name);
if (headId == null) {
ru.setExpectedOldObjectId(ObjectId.zeroId());
} else {
ru.setExpectedOldObjectId(headId);
}
ru.setNewObjectId(commit.getId());
ru.setRefLogMessage(commit.getShortMessage(),
false);
forceUpdate(ru,
commit.getId());
}
示例15: save
import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
* Save pending keys to the store.
*
* <p>One commit is created and the ref updated. The pending list is cleared if and only if the
* ref update succeeds, which allows for easy retries in case of lock failure.
*
* @param cb commit builder with at least author and identity populated; tree and parent are
* ignored.
* @return result of the ref update.
*/
public RefUpdate.Result save(CommitBuilder cb) throws PGPException, IOException {
if (toAdd.isEmpty() && toRemove.isEmpty()) {
return RefUpdate.Result.NO_CHANGE;
}
if (reader == null) {
load();
}
if (notes == null) {
notes = NoteMap.newEmptyMap();
}
ObjectId newTip;
try (ObjectInserter ins = repo.newObjectInserter()) {
for (PGPPublicKeyRing keyRing : toAdd.values()) {
saveToNotes(ins, keyRing);
}
for (Fingerprint fp : toRemove) {
deleteFromNotes(ins, fp);
}
cb.setTreeId(notes.writeTree(ins));
if (cb.getTreeId().equals(tip != null ? tip.getTree() : EMPTY_TREE)) {
return RefUpdate.Result.NO_CHANGE;
}
if (tip != null) {
cb.setParentId(tip);
}
if (cb.getMessage() == null) {
int n = toAdd.size() + toRemove.size();
cb.setMessage(String.format("Update %d public key%s", n, n != 1 ? "s" : ""));
}
newTip = ins.insert(cb);
ins.flush();
}
RefUpdate ru = repo.updateRef(PublicKeyStore.REFS_GPG_KEYS);
ru.setExpectedOldObjectId(tip);
ru.setNewObjectId(newTip);
ru.setRefLogIdent(cb.getCommitter());
ru.setRefLogMessage("Store public keys", true);
RefUpdate.Result result = ru.update();
reset();
switch (result) {
case FAST_FORWARD:
case NEW:
case NO_CHANGE:
toAdd.clear();
toRemove.clear();
break;
case FORCED:
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:
break;
}
return result;
}