本文整理汇总了Java中org.eclipse.jgit.lib.CommitBuilder.addParentId方法的典型用法代码示例。如果您正苦于以下问题:Java CommitBuilder.addParentId方法的具体用法?Java CommitBuilder.addParentId怎么用?Java CommitBuilder.addParentId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.lib.CommitBuilder
的用法示例。
在下文中一共展示了CommitBuilder.addParentId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.eclipse.jgit.lib.CommitBuilder; //导入方法依赖的package包/类
protected void save(PersonIdent ident, String msg) throws IOException, ConfigInvalidException {
File path = getPath();
if (path == null) {
throw new IOException(project + " does not exist.");
}
try (Repository repo = new FileRepository(path);
ObjectInserter i = repo.newObjectInserter();
ObjectReader r = repo.newObjectReader();
RevWalk rw = new RevWalk(r)) {
inserter = i;
reader = r;
RevTree srcTree = revision != null ? rw.parseTree(revision) : null;
newTree = readTree(srcTree);
CommitBuilder commit = new CommitBuilder();
commit.setAuthor(ident);
commit.setCommitter(ident);
commit.setMessage(msg);
onSave(commit);
ObjectId res = newTree.writeTree(inserter);
if (res.equals(srcTree)) {
return;
}
commit.setTreeId(res);
if (revision != null) {
commit.addParentId(revision);
}
ObjectId newRevision = inserter.insert(commit);
updateRef(repo, ident, newRevision, "commit: " + msg);
revision = rw.parseCommit(newRevision);
} finally {
inserter = null;
reader = null;
}
}
示例2: writeSquashedCommit
import org.eclipse.jgit.lib.CommitBuilder; //导入方法依赖的package包/类
private static RevCommit writeSquashedCommit(
RevWalk rw, ObjectInserter inserter, RevCommit parent, RevCommit edit) throws IOException {
CommitBuilder mergeCommit = new CommitBuilder();
for (int i = 0; i < parent.getParentCount(); i++) {
mergeCommit.addParentId(parent.getParent(i));
}
mergeCommit.setAuthor(parent.getAuthorIdent());
mergeCommit.setMessage(edit.getFullMessage());
mergeCommit.setCommitter(edit.getCommitterIdent());
mergeCommit.setTreeId(edit.getTree());
return rw.parseCommit(commit(inserter, mergeCommit));
}
示例3: commit
import org.eclipse.jgit.lib.CommitBuilder; //导入方法依赖的package包/类
private RevCommit commit(
Repository repo,
RevWalk rw,
@Nullable InMemoryInserter tmpIns,
ObjectInserter ins,
String refName,
ObjectId tree,
RevCommit merge)
throws IOException {
rw.parseHeaders(merge);
// For maximum stability, choose a single ident using the committer time of
// the input commit, using the server name and timezone.
PersonIdent ident =
new PersonIdent(
gerritIdent, merge.getCommitterIdent().getWhen(), gerritIdent.getTimeZone());
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
cb.setTreeId(tree);
cb.setMessage("Auto-merge of " + merge.name() + '\n');
for (RevCommit p : merge.getParents()) {
cb.addParentId(p);
}
if (!save) {
checkArgument(tmpIns != null);
try (ObjectReader tmpReader = tmpIns.newReader();
RevWalk tmpRw = new RevWalk(tmpReader)) {
return tmpRw.parseCommit(tmpIns.insert(cb));
}
}
checkArgument(tmpIns == null);
checkArgument(!(ins instanceof InMemoryInserter));
ObjectId commitId = ins.insert(cb);
ins.flush();
RefUpdate ru = repo.updateRef(refName);
ru.setNewObjectId(commitId);
ru.disableRefLog();
ru.forceUpdate();
return rw.parseCommit(commitId);
}