本文整理了Java中org.eclipse.jgit.lib.Repository.parseCommit
方法的一些代码示例,展示了Repository.parseCommit
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.parseCommit
方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:parseCommit
[英]Locate a reference to a commit and immediately parse its content.
This method only returns successfully if the commit object exists, is verified to be a commit, and was parsed without error.
[中]找到对提交的引用并立即解析其内容。
只有当提交对象存在、被验证为提交并且被正确解析时,此方法才会成功返回。
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
@Override
public RemoteFile readFileWithMode(String uri, String ref, String path)
throws GitAPIException, IOException {
File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
.setURI(uri).call()) {
Repository repo = git.getRepository();
ObjectId refCommitId = sha1(uri, ref);
if (refCommitId == null) {
throw new InvalidRefNameException(MessageFormat
.format(JGitText.get().refNotResolved, ref));
}
RevCommit commit = repo.parseCommit(refCommitId);
TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree());
// TODO(ifrade): Cope better with big files (e.g. using
// InputStream instead of byte[])
return new RemoteFile(
tw.getObjectReader().open(tw.getObjectId(0))
.getCachedBytes(Integer.MAX_VALUE),
tw.getFileMode(0));
} finally {
FileUtils.delete(dir, FileUtils.RECURSIVE);
}
}
}
代码示例来源:origin: jgitver/jgitver
private Commit deepestReachableCommit(ObjectId headId, int maxDepth) throws IOException {
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit headCommit = repository.parseCommit(headId);
revWalk.markStart(headCommit);
int depth = 0;
RevCommit lastCommit = headCommit;
Iterator<RevCommit> iterator = revWalk.iterator();
while (iterator.hasNext() && depth <= maxDepth) {
lastCommit = iterator.next();
depth++;
}
int retainedDepth = depth - 1; // we do not count head
return new Commit(lastCommit.getId(), retainedDepth, Collections.emptyList(), Collections.emptyList());
}
}
代码示例来源:origin: koraktor/mavanagaiata
/**
* Returns a commit object for {@code HEAD}
*
* @return The commit object for {@code HEAD}
* @see RevCommit
* @throws GitRepositoryException if the commit object cannot be retrieved
*/
RevCommit getHeadRevCommit() throws GitRepositoryException {
if (headCommit != null) {
return headCommit;
}
try {
return headCommit = repository.parseCommit(getHeadObject());
} catch (IOException e) {
throw new GitRepositoryException(
String.format("Commit \"%s\" could not be loaded.",
getHeadObject().getName()), e);
}
}
代码示例来源:origin: org.lorislab.hugoup/hugoup
public static String getVersion() throws Exception {
Git git = Git.open(new File("."));
Repository repo = git.getRepository();
ObjectId lastCommitId = repo.resolve(Constants.HEAD);
RevCommit revc = repo.parseCommit(lastCommitId);
ObjectId commitId = revc.getId();
String shortId = commitId.abbreviate(7).name();
return shortId;
}
}
代码示例来源:origin: org.sonarsource.scm.git/sonar-scm-git-plugin
private static AbstractTreeIterator prepareNewTree(Repository repo) throws IOException {
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader objectReader = repo.newObjectReader()) {
treeParser.reset(objectReader, repo.parseCommit(getHead(repo).getObjectId()).getTree());
}
return treeParser;
}
代码示例来源:origin: org.wildfly.core/wildfly-server
@Override
public void flush(boolean success) {
if (success) {
try (Git git = gitRepository.getGit()) {
Status status = git.status().call();
if (!status.isClean()) {
String message = git.getRepository().parseCommit(git.getRepository().resolve(HEAD)).getFullMessage();
if(! status.getUntracked().isEmpty() || ! status.getUntrackedFolders().isEmpty()) {
AddCommand addCommand = git.add();
for(String untracked : status.getUntrackedFolders()) {
addCommand = addCommand.addFilepattern(untracked);
}
for(String untracked : status.getUntracked()) {
addCommand = addCommand.addFilepattern(untracked);
}
addCommand.call();
}
git.commit().setMessage(message).setAmend(true).setAll(true).setNoVerify(true).call();
}
} catch (RevisionSyntaxException | IOException | GitAPIException ex) {
throw new RuntimeException(ex);
}
}
}
代码示例来源:origin: wildfly/wildfly-core
@Override
public void flush(boolean success) {
if (success) {
try (Git git = gitRepository.getGit()) {
Status status = git.status().call();
if (!status.isClean()) {
String message = git.getRepository().parseCommit(git.getRepository().resolve(HEAD)).getFullMessage();
if(! status.getUntracked().isEmpty() || ! status.getUntrackedFolders().isEmpty()) {
AddCommand addCommand = git.add();
for(String untracked : status.getUntrackedFolders()) {
addCommand = addCommand.addFilepattern(untracked);
}
for(String untracked : status.getUntracked()) {
addCommand = addCommand.addFilepattern(untracked);
}
addCommand.call();
}
git.commit().setMessage(message).setAmend(true).setAll(true).setNoVerify(true).call();
}
} catch (RevisionSyntaxException | IOException | GitAPIException ex) {
throw new RuntimeException(ex);
}
}
}
代码示例来源:origin: berlam/github-bucket
@Override
public RemoteFile readFileWithMode(String uri, String ref, String path)
throws GitAPIException, IOException {
File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
.setURI(uri).call()) {
Repository repo = git.getRepository();
ObjectId refCommitId = sha1(uri, ref);
if (refCommitId == null) {
throw new InvalidRefNameException(MessageFormat
.format(JGitText.get().refNotResolved, ref));
}
RevCommit commit = repo.parseCommit(refCommitId);
TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree());
// TODO(ifrade): Cope better with big files (e.g. using
// InputStream instead of byte[])
return new RemoteFile(
tw.getObjectReader().open(tw.getObjectId(0))
.getCachedBytes(Integer.MAX_VALUE),
tw.getFileMode(0));
} finally {
FileUtils.delete(dir, FileUtils.RECURSIVE);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!