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


Java RefUpdate.getRef方法代码示例

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


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

示例1: forceUpdate

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void forceUpdate(final RefUpdate ru,
                         final ObjectId id) throws java.io.IOException, ConcurrentRefUpdateException {
    final RefUpdate.Result rc = ru.forceUpdate();
    switch (rc) {
        case NEW:
        case FORCED:
        case FAST_FORWARD:
            break;
        case REJECTED:
        case LOCK_FAILURE:
            throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD,
                                                   ru.getRef(),
                                                   rc);
        default:
            throw new JGitInternalException(MessageFormat.format(JGitText.get().updatingRefFailed,
                                                                 Constants.HEAD,
                                                                 id.toString(),
                                                                 rc));
    }
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:SimpleRefUpdateCommand.java

示例2: commitIndex

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private boolean commitIndex(Repository db, DirCache index, String author, String message) throws IOException, ConcurrentRefUpdateException {
	boolean success = false;

	ObjectId headId = db.resolve(BRANCH + "^{commit}");
	if (headId == null) {
		// create the branch
		createTicketsBranch(db);
		headId = db.resolve(BRANCH + "^{commit}");
	}
	try (ObjectInserter odi = db.newObjectInserter()) {
		// Create the in-memory index of the new/updated ticket
		ObjectId indexTreeId = index.writeTree(odi);

		// Create a commit object
		PersonIdent ident = new PersonIdent(author, "[email protected]");
		CommitBuilder commit = new CommitBuilder();
		commit.setAuthor(ident);
		commit.setCommitter(ident);
		commit.setEncoding(Constants.ENCODING);
		commit.setMessage(message);
		commit.setParentId(headId);
		commit.setTreeId(indexTreeId);

		// Insert the commit into the repository
		ObjectId commitId = odi.insert(commit);
		odi.flush();

		try (RevWalk revWalk = new RevWalk(db)) {
			RevCommit revCommit = revWalk.parseCommit(commitId);
			RefUpdate ru = db.updateRef(BRANCH);
			ru.setNewObjectId(commitId);
			ru.setExpectedOldObjectId(headId);
			ru.setRefLogMessage("commit: " + revCommit.getShortMessage(), false);
			Result rc = ru.forceUpdate();
			switch (rc) {
			case NEW:
			case FORCED:
			case FAST_FORWARD:
				success = true;
				break;
			case REJECTED:
			case LOCK_FAILURE:
				throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD, ru.getRef(), rc);
			default:
				throw new JGitInternalException(MessageFormat.format(JGitText.get().updatingRefFailed, BRANCH, commitId.toString(), rc));
			}
		}
	}
	return success;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:51,代码来源:BranchTicketService.java

示例3: updatePushLog

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Updates a push log.
 * 
 * @param user
 * @param repository
 * @param commands
 * @return true, if the update was successful
 */
public static boolean updatePushLog(UserModel user, Repository repository,
		Collection<ReceiveCommand> commands) {
	RefModel pushlogBranch = getPushLogBranch(repository);
	if (pushlogBranch == null) {
		JGitUtils.createOrphanBranch(repository, GB_PUSHES, null);
	}
	
	boolean success = false;
	String message = "push";
	
	try {
		ObjectId headId = repository.resolve(GB_PUSHES + "^{commit}");
		ObjectInserter odi = repository.newObjectInserter();
		try {
			// Create the in-memory index of the push log entry
			DirCache index = createIndex(repository, headId, commands);
			ObjectId indexTreeId = index.writeTree(odi);

			PersonIdent ident = new PersonIdent(user.getDisplayName(), 
					user.emailAddress == null ? user.username:user.emailAddress);

			// Create a commit object
			CommitBuilder commit = new CommitBuilder();
			commit.setAuthor(ident);
			commit.setCommitter(ident);
			commit.setEncoding(Constants.CHARACTER_ENCODING);
			commit.setMessage(message);
			commit.setParentId(headId);
			commit.setTreeId(indexTreeId);

			// Insert the commit into the repository
			ObjectId commitId = odi.insert(commit);
			odi.flush();

			RevWalk revWalk = new RevWalk(repository);
			try {
				RevCommit revCommit = revWalk.parseCommit(commitId);
				RefUpdate ru = repository.updateRef(GB_PUSHES);
				ru.setNewObjectId(commitId);
				ru.setExpectedOldObjectId(headId);
				ru.setRefLogMessage("commit: " + revCommit.getShortMessage(), false);
				Result rc = ru.forceUpdate();
				switch (rc) {
				case NEW:
				case FORCED:
				case FAST_FORWARD:
					success = true;
					break;
				case REJECTED:
				case LOCK_FAILURE:
					throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD,
							ru.getRef(), rc);
				default:
					throw new JGitInternalException(MessageFormat.format(
							JGitText.get().updatingRefFailed, GB_PUSHES, commitId.toString(),
							rc));
				}
			} finally {
				revWalk.release();
			}
		} finally {
			odi.release();
		}
	} catch (Throwable t) {
		error(t, repository, "Failed to commit pushlog entry to {0}");
	}
	return success;
}
 
开发者ID:BullShark,项目名称:IRCBlit,代码行数:77,代码来源:PushLogUtils.java


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