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


Java RefUpdate.update方法代码示例

本文整理汇总了Java中org.eclipse.jgit.lib.RefUpdate.update方法的典型用法代码示例。如果您正苦于以下问题:Java RefUpdate.update方法的具体用法?Java RefUpdate.update怎么用?Java RefUpdate.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jgit.lib.RefUpdate的用法示例。


在下文中一共展示了RefUpdate.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doRefUpdate

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@VisibleForTesting
static void doRefUpdate(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk revWalk,
                        String ref, ObjectId commitId) throws IOException {

    if (ref.startsWith(Constants.R_TAGS)) {
        final Ref oldRef = jGitRepository.exactRef(ref);
        if (oldRef != null) {
            throw new StorageException("tag ref exists already: " + ref);
        }
    }

    final RefUpdate refUpdate = jGitRepository.updateRef(ref);
    refUpdate.setNewObjectId(commitId);

    final Result res = refUpdate.update(revWalk);
    switch (res) {
        case NEW:
        case FAST_FORWARD:
            // Expected
            break;
        default:
            throw new StorageException("unexpected refUpdate state: " + res);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:25,代码来源:GitRepository.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: 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

示例5: push

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Override
public boolean push(@NotNull Repository repository, @NotNull ObjectId ReceiveId, @NotNull String branch, @NotNull User userInfo) throws SVNException, IOException {
  final RefUpdate refUpdate = repository.updateRef(branch);
  refUpdate.getOldObjectId();
  refUpdate.setNewObjectId(ReceiveId);
  runReceiveHook(repository, refUpdate, preReceive, userInfo);
  runUpdateHook(repository, refUpdate, update, userInfo);
  final RefUpdate.Result result = refUpdate.update();
  switch (result) {
    case REJECTED:
      return false;
    case NEW:
    case FAST_FORWARD:
      runReceiveHook(repository, refUpdate, postReceive, userInfo);
      return true;
    default:
      log.error("Unexpected push error: {}", result);
      throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_WRITE_ERROR, result.name()));
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:21,代码来源:GitPushEmbedded.java

示例6: update

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public void update(ObjectId newId) throws IOException {
	String refName = getName();
	Repository repository = gitRepository.getRepository();
	RefUpdate ru = repository.updateRef(refName);
	ru.setNewObjectId(newId);
	ru.setForceUpdate(true);
	ru.update();
}
 
开发者ID:link-intersystems,项目名称:GitDirStat,代码行数:9,代码来源:Ref.java

示例7: run

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public void run(IProgressMonitor monitor)
		throws InvocationTargetException, InterruptedException {
	String stableBranch = "refs/remotes/origin/" + settings.get(CreateChangeBranchDialog.PROP_STABLE_BRANCH);
	String simpleBranchName = "changes/" + settings.get(CreateChangeBranchDialog.PROP_STABLE_BRANCH)
			 + "/" + settings.get(CreateChangeBranchDialog.PROP_CHANGE_BRANCH_NAME);
	String changeBranch = "refs/heads/" + simpleBranchName;
	try {
		Ref stable = repository.getRef(stableBranch);
		AnyObjectId oid = stable.getLeaf().getObjectId();
		
		RefUpdate refUpdate = repository.updateRef(changeBranch);
		refUpdate.setNewObjectId(oid);
		
		Result res = refUpdate.update();
		switch (res) {
			case FAST_FORWARD: case NEW: case FORCED:
			case NO_CHANGE: case RENAMED:
				//we are fine;
				break;
			default:
				throw new RuntimeException("Cannot create change branch: " + res.toString());
		}
		
		//configure for pull
		StoredConfig config = repository.getConfig();
		config.setString("branch", simpleBranchName, "remote", "origin");  //$NON-NLS-1$//$NON-NLS-2$
		config.setString("branch", simpleBranchName, "merge", "refs/heads/" + settings.get(CreateChangeBranchDialog.PROP_STABLE_BRANCH));  //$NON-NLS-1$//$NON-NLS-2$
		config.setBoolean("branch", simpleBranchName, "rebase", true);  //$NON-NLS-1$//$NON-NLS-2$
		
		
		if ((Boolean)settings.get(CreateChangeBranchDialog.PROP_CHECKOUT)) {
			new SwitchToChangeBranchCommand().execute(event, repository, changeBranch);
		}
	} catch (Exception e) {
       	RepositoryUtils.handleException(e);
	}
}
 
开发者ID:Genuitec,项目名称:gerrit-tools,代码行数:38,代码来源:NewChangeBranchCommand.java

示例8: updateProjectRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public static void updateProjectRef(ObjectId treeId, ObjectInserter objectInserter, Repository repository, CurrentUser currentUser)
        throws IOException, NoFilepatternException, GitAPIException {
    // Create a branch
    Ref gerritCiRef = repository.getRef("refs/meta/gerrit-ci");
    CommitBuilder commitBuilder = new CommitBuilder();
    commitBuilder.setTreeId(treeId);
    logger.info("treeId: " + treeId);

    if (gerritCiRef != null) {
        ObjectId prevCommit = gerritCiRef.getObjectId();
        logger.info("prevCommit: " + prevCommit);
        commitBuilder.setParentId(prevCommit);
    }
    // build commit
    logger.info("Adding git tree : " + treeId);
    commitBuilder.setMessage("Modify project build rules.");
    final IdentifiedUser iUser = (IdentifiedUser) currentUser;
    PersonIdent user = new PersonIdent(currentUser.getUserName(), iUser.getEmailAddresses().iterator().next());
    commitBuilder.setAuthor(user);
    commitBuilder.setCommitter(user);
    ObjectId commitId = objectInserter.insert(commitBuilder);
    objectInserter.flush();
    logger.info(" Making new commit: " + commitId);
    RefUpdate newRef = repository.updateRef("refs/meta/gerrit-ci");
    newRef.setNewObjectId(commitId);
    newRef.update();
    repository.close();
}
 
开发者ID:palantir,项目名称:gerrit-ci,代码行数:29,代码来源:JobsServlet.java

示例9: updateRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void updateRef() throws IOException, InterruptedException, RuntimeException,
                                MissingObjectException, IncorrectObjectTypeException,
                                CorruptObjectException {
  if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) {
    // If the trees are identical, there is no change in the notes.
    // Avoid saving this commit as it has no new information.
    return;
  }

  int remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS;
  RefUpdate refUpdate = JgitUtils.updateRef(repo, oursCommit, baseCommit, ref);

  for (;;) {
    Result result = refUpdate.update();

    if (result == Result.LOCK_FAILURE) {
      if (--remainingLockFailureCalls > 0) {
        Thread.sleep(JgitUtils.SLEEP_ON_LOCK_FAILURE_MS);
      } else {
        throw new RuntimeException("Failed to lock the ref: " + ref);
      }

    } else if (result == Result.REJECTED) {
      RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId());
      NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit);
      NoteMapMerger merger = new NoteMapMerger(repo);
      NoteMap merged = merger.merge(base, ours, theirs);
      RevCommit mergeCommit =
          createCommit(merged, author, "Merged note records\n", theirsCommit, oursCommit);
      refUpdate = JgitUtils.updateRef(repo, mergeCommit, theirsCommit, ref);
      remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS;

    } else if (result == Result.IO_FAILURE) {
      throw new RuntimeException("Couldn't create notes because of IO_FAILURE");
    } else {
      break;
    }
  }
}
 
开发者ID:google,项目名称:git-appraise-eclipse,代码行数:40,代码来源:GitNoteWriter.java

示例10: 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

示例11: 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

示例12: fixPatchSetRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void fixPatchSetRef(ProblemInfo p, PatchSet ps) {
  try {
    RefUpdate ru = repo.updateRef(ps.getId().toRefName());
    ru.setForceUpdate(true);
    ru.setNewObjectId(ObjectId.fromString(ps.getRevision().get()));
    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";
    log.warn(msg + ' ' + ps.getId().toRefName(), e);
    p.status = Status.FIX_FAILED;
    p.outcome = msg;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:37,代码来源:ConsistencyChecker.java

示例13: mergeBranch

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private MergedRef mergeBranch(String branch) throws IOException {

		Map<SubtreeConfig, ObjectId> resolvedRefs = resolveRefs(
				"refs/heads/original/", branch);

		Map<SubtreeConfig, RevCommit> parentCommits = new LinkedHashMap<>();
		try (RevWalk revWalk = new RevWalk(repository)) {
			for (SubtreeConfig config : subtreeConfigs) {
				ObjectId objectId = resolvedRefs.get(config);
				if (objectId != null) {
					RevCommit commit = revWalk.parseCommit(objectId);
					parentCommits.put(config, commit);
				}
			}
		}

		MergedRef mergedRef = getMergedRef("branch", branch, parentCommits.keySet());

		ObjectId mergeCommit = new SubtreeMerger(repository).createMergeCommit(parentCommits,
				mergedRef.getMessage());

		RefUpdate refUpdate = repository.updateRef("refs/heads/" + branch);
		refUpdate.setNewObjectId(mergeCommit);
		refUpdate.update();

		return mergedRef;
	}
 
开发者ID:robinst,项目名称:git-merge-repos,代码行数:28,代码来源:RepoMerger.java

示例14: 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

示例15: insert

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public void insert(Account account) throws IOException {
  File path = getPath();
  if (path != null) {
    try (Repository repo = new FileRepository(path);
        ObjectInserter oi = repo.newObjectInserter()) {
      PersonIdent ident =
          new PersonIdent(
              new GerritPersonIdentProvider(flags.cfg).get(), account.getRegisteredOn());

      Config accountConfig = new Config();
      AccountConfig.writeToConfig(account, accountConfig);

      DirCache newTree = DirCache.newInCore();
      DirCacheEditor editor = newTree.editor();
      final ObjectId blobId =
          oi.insert(Constants.OBJ_BLOB, accountConfig.toText().getBytes(UTF_8));
      editor.add(
          new PathEdit(AccountConfig.ACCOUNT_CONFIG) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.setFileMode(FileMode.REGULAR_FILE);
              ent.setObjectId(blobId);
            }
          });
      editor.finish();

      ObjectId treeId = newTree.writeTree(oi);

      CommitBuilder cb = new CommitBuilder();
      cb.setTreeId(treeId);
      cb.setCommitter(ident);
      cb.setAuthor(ident);
      cb.setMessage("Create Account");
      ObjectId id = oi.insert(cb);
      oi.flush();

      String refName = RefNames.refsUsers(account.getId());
      RefUpdate ru = repo.updateRef(refName);
      ru.setExpectedOldObjectId(ObjectId.zeroId());
      ru.setNewObjectId(id);
      ru.setRefLogIdent(ident);
      ru.setRefLogMessage("Create Account", false);
      Result result = ru.update();
      if (result != Result.NEW) {
        throw new IOException(
            String.format("Failed to update ref %s: %s", refName, result.name()));
      }
      account.setMetaId(id.name());
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:52,代码来源:AccountsOnInit.java


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