本文整理汇总了Java中org.eclipse.jgit.lib.CommitBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CommitBuilder类的具体用法?Java CommitBuilder怎么用?Java CommitBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommitBuilder类属于org.eclipse.jgit.lib包,在下文中一共展示了CommitBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
/**
*
* @param lastCommitId
* @param treeId
* @param repo
* @param lastTreeId
* @return
* @throws IOException
*/
public static ObjectId processCommit(ObjectId lastCommitId, ObjectId treeId, Repository repo, ObjectId lastTreeId) throws IOException {
CommitBuilder commitBuilder = new CommitBuilder();
ObjectId commitId = null;
if (lastCommitId == null) {
commitId = Commands.commit(commitBuilder, treeId, repo);
System.out.println("Initial Commit: " + commitId);
} else {
if (lastTreeId.equals(treeId)) {
// Do nothing, because there is no changes in the tree
System.out.println("Did nothing, because there is no changes in the commited tree!\n");
} else {
commitBuilder.setParentId(lastCommitId);
commitId = Commands.commit(commitBuilder, treeId, repo);
System.out.println("Current Commit: " + commitId);
}
}
return commitId;
}
示例2: commit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
/**
*
* @param commitBuilder
* @param treeId
* @param repo
* @return
* @throws UnsupportedEncodingException
* @throws IOException
*/
public static ObjectId commit(CommitBuilder commitBuilder, ObjectId treeId, Repository repo) throws UnsupportedEncodingException, IOException {
commitBuilder.setTreeId(treeId);
commitBuilder.setMessage(System.currentTimeMillis() + ": My commit!\n");
PersonIdent person = new PersonIdent("Alex", "[email protected]");
commitBuilder.setAuthor(person);
commitBuilder.setCommitter(person);
commitBuilder.build();
ObjectInserter commitInserter = repo.newObjectInserter();
ObjectId commitId = commitInserter.insert(commitBuilder);
commitInserter.flush();
updateMasterRecord(repo, commitId);
System.out.println("Commit Object ID: " + commitId.getName());
return commitId;
}
示例3: execute
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
@Override
public void execute() throws SVNException {
DAVResource resource = getRequestedDAVResource(false, false);
FSRepository repos = (FSRepository) resource.getRepository();
myGitFS = (GitFS) repos.getFSFS();
readInput(true);
if (commitBuilders.containsKey(resource.getActivityID())) {
throw new DAVException("<DAV:resource-must-be-null/>", HttpServletResponse.SC_CONFLICT, SVNLogType.NETWORK);
}
// FIXME: I don't know what it is
if (!resource.canBeActivity()) {
throw new DAVException("<DAV:activity-location-ok/>", HttpServletResponse.SC_FORBIDDEN, SVNLogType.NETWORK);
}
CommitBuilder builder = new CommitBuilder();
commitBuilders.put(resource.getActivityID(), builder);
setResponseHeader(CACHE_CONTROL_HEADER, CACHE_CONTROL_VALUE);
handleDAVCreated(resource.getResourceURI().getURI(), "Activity", false);
}
示例4: createCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private ObjectId createCommit(
Repository repository,
RevCommit basePatchSetCommit,
ObjectId tree,
String commitMessage,
Timestamp timestamp)
throws IOException {
try (ObjectInserter objectInserter = repository.newObjectInserter()) {
CommitBuilder builder = new CommitBuilder();
builder.setTreeId(tree);
builder.setParentIds(basePatchSetCommit.getParents());
builder.setAuthor(basePatchSetCommit.getAuthorIdent());
builder.setCommitter(getCommitterIdent(timestamp));
builder.setMessage(commitMessage);
ObjectId newCommitId = objectInserter.insert(builder);
objectInserter.flush();
return newCommitId;
}
}
示例5: onSave
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
@Override
protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
checkLoaded();
if (revision != null) {
commit.setMessage("Update account\n");
} else if (account != null) {
commit.setMessage("Create account\n");
commit.setAuthor(new PersonIdent(commit.getAuthor(), registeredOn));
commit.setCommitter(new PersonIdent(commit.getCommitter(), registeredOn));
}
Config cfg = readConfig(ACCOUNT_CONFIG);
writeToConfig(account, cfg);
saveConfig(ACCOUNT_CONFIG, cfg);
return true;
}
示例6: newCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private static RevCommit newCommit(
ObjectInserter oi,
RevWalk rw,
PersonIdent authorIdent,
RevCommit mergeTip,
String commitMessage)
throws IOException {
CommitBuilder commit = new CommitBuilder();
if (mergeTip == null) {
commit.setTreeId(emptyTreeId(oi));
} else {
commit.setTreeId(mergeTip.getTree().getId());
commit.setParentId(mergeTip);
}
commit.setAuthor(authorIdent);
commit.setCommitter(authorIdent);
commit.setMessage(commitMessage);
return rw.parseCommit(insert(oi, commit));
}
示例7: createCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private ObjectId createCommit(
ObjectInserter objectInserter,
RevCommit basePatchSetCommit,
String commitMessage,
Timestamp timestamp)
throws IOException {
CommitBuilder builder = new CommitBuilder();
builder.setTreeId(basePatchSetCommit.getTree());
builder.setParentIds(basePatchSetCommit.getParents());
builder.setAuthor(basePatchSetCommit.getAuthorIdent());
builder.setCommitter(
currentUserProvider.get().asIdentifiedUser().newCommitterIdent(timestamp, tz));
builder.setMessage(commitMessage);
ObjectId newCommitId = objectInserter.insert(builder);
objectInserter.flush();
return newCommitId;
}
示例8: save
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private void save() throws Exception {
PersonIdent ident = new PersonIdent("A U Thor", "[email protected]");
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
RefUpdate.Result result = store.save(cb);
switch (result) {
case NEW:
case FAST_FORWARD:
case FORCED:
break;
case IO_FAILURE:
case LOCK_FAILURE:
case NOT_ATTEMPTED:
case NO_CHANGE:
case REJECTED:
case REJECTED_CURRENT_BRANCH:
case RENAMED:
case REJECTED_MISSING_OBJECT:
case REJECTED_OTHER_REASON:
default:
throw new AssertionError(result);
}
}
示例9: setUp
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
TestKey key1 = validKeyWithoutExpiration();
TestKey key3 = expiredKey();
repo = new InMemoryRepository(new DfsRepositoryDescription("repo"));
store = new PublicKeyStore(repo);
store.add(key1.getPublicKeyRing());
store.add(key3.getPublicKeyRing());
PersonIdent ident = new PersonIdent("A U Thor", "[email protected]");
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
assertEquals(RefUpdate.Result.NEW, store.save(cb));
signedPushConfig = new SignedPushConfig();
signedPushConfig.setCertNonceSeed("sekret");
signedPushConfig.setCertNonceSlopLimit(60 * 24);
checker = newChecker(true);
}
示例10: add
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private void add(PGPPublicKeyRing kr, IdentifiedUser user) throws Exception {
Account.Id id = user.getAccountId();
List<ExternalId> newExtIds = new ArrayList<>(2);
newExtIds.add(ExternalId.create(toExtIdKey(kr.getPublicKey()), id));
String userId = Iterators.getOnlyElement(kr.getPublicKey().getUserIDs(), null);
if (userId != null) {
String email = PushCertificateIdent.parse(userId).getEmailAddress();
assertThat(email).contains("@");
newExtIds.add(ExternalId.createEmail(id, email));
}
store.add(kr);
PersonIdent ident = new PersonIdent("A U Thor", "aut[email protected]");
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
assertThat(store.save(cb)).isAnyOf(NEW, FAST_FORWARD, FORCED);
externalIdsUpdateFactory.create().insert(newExtIds);
}
示例11: createGroupBranch
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的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);
}
}
示例12: writeCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private RevCommit writeCommit(String body, PersonIdent author, boolean initWorkInProgress)
throws Exception {
Change change = newChange(initWorkInProgress);
ChangeNotes notes = newNotes(change).load();
try (ObjectInserter ins = testRepo.getRepository().newObjectInserter()) {
CommitBuilder cb = new CommitBuilder();
cb.setParentId(notes.getRevision());
cb.setAuthor(author);
cb.setCommitter(new PersonIdent(serverIdent, author.getWhen()));
cb.setTreeId(testRepo.tree());
cb.setMessage(body);
ObjectId id = ins.insert(cb);
ins.flush();
RevCommit commit = walk.parseCommit(id);
walk.parseBody(commit);
return commit;
}
}
示例13: setHEAD
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
private void setHEAD() throws Exception {
try (ObjectInserter oi = repository.newObjectInserter()) {
final CommitBuilder commit = new CommitBuilder();
commit.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {}));
commit.setAuthor(author);
commit.setCommitter(committer);
commit.setMessage("test\n");
ObjectId commitId = oi.insert(commit);
final RefUpdate ref = repository.updateRef(Constants.HEAD);
ref.setNewObjectId(commitId);
Result result = ref.forceUpdate();
assertWithMessage(Constants.HEAD + " did not change: " + ref.getResult())
.that(result)
.isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
}
}
示例14: createMergeCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
public ObjectId createMergeCommit(Map<SubtreeConfig, RevCommit> parentCommits, String message)
throws IOException {
PersonIdent latestIdent = getLatestPersonIdent(parentCommits.values());
DirCache treeDirCache = createTreeDirCache(parentCommits, message);
List<? extends ObjectId> parentIds = new ArrayList<>(parentCommits.values());
try (ObjectInserter inserter = repository.newObjectInserter()) {
ObjectId treeId = treeDirCache.writeTree(inserter);
PersonIdent repositoryUser = new PersonIdent(repository);
PersonIdent ident = new PersonIdent(repositoryUser, latestIdent.getWhen().getTime(),
latestIdent.getTimeZoneOffset());
CommitBuilder commitBuilder = new CommitBuilder();
commitBuilder.setTreeId(treeId);
commitBuilder.setAuthor(ident);
commitBuilder.setCommitter(ident);
commitBuilder.setMessage(message);
commitBuilder.setParentIds(parentIds);
ObjectId mergeCommit = inserter.insert(commitBuilder);
inserter.flush();
return mergeCommit;
}
}
示例15: rebase
import org.eclipse.jgit.lib.CommitBuilder; //导入依赖的package包/类
@Nullable
public static ObjectId rebase(Repository repository, ObjectId source, ObjectId target, PersonIdent committer) {
try ( RevWalk revWalk = new RevWalk(repository);
ObjectInserter inserter = repository.newObjectInserter();) {
RevCommit sourceCommit = revWalk.parseCommit(source);
RevCommit targetCommit = revWalk.parseCommit(target);
revWalk.setRevFilter(RevFilter.NO_MERGES);
List<RevCommit> commits = RevWalkUtils.find(revWalk, sourceCommit, targetCommit);
Collections.reverse(commits);
RevCommit headCommit = targetCommit;
for (RevCommit commit: commits) {
ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE.newMerger(repository, true);
merger.setBase(commit.getParent(0));
if (merger.merge(headCommit, commit)) {
if (!headCommit.getTree().getId().equals(merger.getResultTreeId())) {
CommitBuilder newCommit = new CommitBuilder();
newCommit.setAuthor(commit.getAuthorIdent());
newCommit.setCommitter(committer);
newCommit.setParentId(headCommit);
newCommit.setMessage(commit.getFullMessage());
newCommit.setTreeId(merger.getResultTreeId());
headCommit = revWalk.parseCommit(inserter.insert(newCommit));
}
} else {
return null;
}
}
inserter.flush();
return headCommit.copy();
} catch (IOException e) {
throw new RuntimeException(e);
}
}