本文整理汇总了Java中org.eclipse.jgit.dircache.DirCache.writeTree方法的典型用法代码示例。如果您正苦于以下问题:Java DirCache.writeTree方法的具体用法?Java DirCache.writeTree怎么用?Java DirCache.writeTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.dircache.DirCache
的用法示例。
在下文中一共展示了DirCache.writeTree方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMergeCommit
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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;
}
}
示例2: writeAndGetId
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private static ObjectId writeAndGetId(Repository repository, DirCache tree) throws IOException {
try (ObjectInserter objectInserter = repository.newObjectInserter()) {
ObjectId treeId = tree.writeTree(objectInserter);
objectInserter.flush();
return treeId;
}
}
示例3: insert
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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());
}
}
}
示例4: composeGitlinksCommit
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
/** Create a separate gitlink commit */
public CodeReviewCommit composeGitlinksCommit(Branch.NameKey subscriber)
throws IOException, SubmoduleException {
OpenRepo or;
try {
or = orm.getRepo(subscriber.getParentKey());
} catch (NoSuchProjectException | IOException e) {
throw new SubmoduleException("Cannot access superproject", e);
}
CodeReviewCommit currentCommit;
if (branchTips.containsKey(subscriber)) {
currentCommit = branchTips.get(subscriber);
} else {
Ref r = or.repo.exactRef(subscriber.get());
if (r == null) {
throw new SubmoduleException(
"The branch was probably deleted from the subscriber repository");
}
currentCommit = or.rw.parseCommit(r.getObjectId());
addBranchTip(subscriber, currentCommit);
}
StringBuilder msgbuf = new StringBuilder("");
PersonIdent author = null;
DirCache dc = readTree(or.rw, currentCommit);
DirCacheEditor ed = dc.editor();
for (SubmoduleSubscription s : targets.get(subscriber)) {
RevCommit newCommit = updateSubmodule(dc, ed, msgbuf, s);
if (newCommit != null) {
if (author == null) {
author = newCommit.getAuthorIdent();
} else if (!author.equals(newCommit.getAuthorIdent())) {
author = myIdent;
}
}
}
ed.finish();
ObjectId newTreeId = dc.writeTree(or.ins);
// Gitlinks are already in the branch, return null
if (newTreeId.equals(currentCommit.getTree())) {
return null;
}
CommitBuilder commit = new CommitBuilder();
commit.setTreeId(newTreeId);
commit.setParentId(currentCommit);
StringBuilder commitMsg = new StringBuilder("Update git submodules\n\n");
if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
commitMsg.append(msgbuf);
}
commit.setMessage(commitMsg.toString());
commit.setAuthor(author);
commit.setCommitter(myIdent);
ObjectId id = or.ins.insert(commit);
return or.rw.parseCommit(id);
}
示例5: commitIndex
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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;
}
示例6: updatePushLog
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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;
}