当前位置: 首页>>代码示例>>Java>>正文


Java RefUpdate.setExpectedOldObjectId方法代码示例

本文整理汇总了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));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:ChangeEditUtil.java

示例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());
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:ChangeEditModifier.java

示例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;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:RepoSequence.java

示例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);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:AccountsUpdate.java

示例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()));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:Schema_146.java

示例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);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:GroupsIT.java

示例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();
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:ChangeRebuilderIT.java

示例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);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:NoteDbOnlyIT.java

示例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);
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:14,代码来源:AbstractGitTest.java

示例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;
}
 
开发者ID:google,项目名称:git-appraise-eclipse,代码行数:15,代码来源:JgitUtils.java

示例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());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:28,代码来源:VersionedMetaDataOnInit.java

示例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()));
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:33,代码来源:StarredChangesUtil.java

示例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()));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:29,代码来源:StarredChangesUtil.java

示例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());
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:15,代码来源:SimpleRefUpdateCommand.java

示例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;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:73,代码来源:PublicKeyStore.java


注:本文中的org.eclipse.jgit.lib.RefUpdate.setExpectedOldObjectId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。