本文整理了Java中org.eclipse.jgit.lib.Repository.resolve
方法的一些代码示例,展示了Repository.resolve
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.resolve
方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:resolve
[英]Parse a git revision string and return an object id. Combinations of these operators are supported:
The following operators are specified by Git conventions, but are not supported by this method:
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory resolve(String revstr) throws IOException {
return GitUtils.valueOf(getWrappedObject().getRepository().resolve(revstr));
}
代码示例来源:origin: apache/usergrid
/**
* @param gitConfigFolder e.g. /your/project/root/.git
*
* @return Returns last commit's UUID, "nocommit" if there are no commits and returns null if an exception occured
*/
public static String getLastCommitUuid( String gitConfigFolder ) throws MojoExecutionException {
try {
Repository repo =
new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir()
.build();
RevWalk walk = new RevWalk( repo );
ObjectId head = repo.resolve( "HEAD" );
if ( head != null ) {
RevCommit lastCommit = walk.parseCommit( head );
return lastCommit.getId().getName();
}
else {
return "nocommit";
}
}
catch ( Exception e ) {
throw new MojoExecutionException( "Error trying to get the last git commit uuid", e );
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory resolveCommit(String revstr) throws IOException, GitAPIException {
ObjectId objectId = getWrappedObject().getRepository().resolve(revstr);
if (objectId == null) {
return Memory.NULL;
}
LogCommand command = getWrappedObject()
.log()
.add(objectId)
.setMaxCount(1);
Iterable<RevCommit> call = command.call();
for (RevCommit revCommit : call) {
return GitUtils.valueOf(revCommit);
}
return Memory.NULL;
}
代码示例来源:origin: apache/incubator-gobblin
ObjectId oldHeadTree = git.getRepository().resolve(this.lastProcessedGitHash + "^{tree}");
ObjectId head = this.git.getRepository().resolve("HEAD");
ObjectId headTree = this.git.getRepository().resolve("HEAD^{tree}");
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// basic syntax is similar to getRef()
ObjectId id = repository.resolve("HEAD");
System.out.println("ObjectId of HEAD: " + id);
// however resolve() supports almost all of the git-syntax, where getRef() only works on names
id = repository.resolve("HEAD^1");
System.out.println("ObjectId of HEAD: " + id);
id = repository.resolve("b419522521af553ae2752fd1b609f2aa11062243");
System.out.println("ObjectId of specific commit: " + id);
id = repository.resolve("05d18a76875716fbdbd2c200091b40caa06c713d");
System.out.println("ObjectId of merged commit: " + id);
}
}
}
代码示例来源:origin: jphp-group/jphp
fId = repository.resolve("HEAD");
} else {
fId = repository.resolve(first.toString());
ObjectId sId = repository.resolve(second.toString());
代码示例来源:origin: checkstyle/checkstyle
private static RevCommitsPair resolveRevCommitsPair(Repository repo) {
RevCommitsPair revCommitIteratorPair;
try (RevWalk revWalk = new RevWalk(repo); Git git = new Git(repo)) {
final Iterator<RevCommit> first;
final Iterator<RevCommit> second;
final ObjectId headId = repo.resolve(Constants.HEAD);
final RevCommit headCommit = revWalk.parseCommit(headId);
if (isMergeCommit(headCommit)) {
final RevCommit firstParent = headCommit.getParent(0);
final RevCommit secondParent = headCommit.getParent(1);
first = git.log().add(firstParent).call().iterator();
second = git.log().add(secondParent).call().iterator();
}
else {
first = git.log().call().iterator();
second = Collections.emptyIterator();
}
revCommitIteratorPair =
new RevCommitsPair(new OmitMergeCommitsIterator(first),
new OmitMergeCommitsIterator(second));
}
catch (GitAPIException | IOException ignored) {
revCommitIteratorPair = new RevCommitsPair();
}
return revCommitIteratorPair;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private ObjectId getStartPointObjectId() throws AmbiguousObjectException,
RefNotFoundException, IOException {
if (startCommit != null)
return startCommit.getId();
String startPointOrHead = (startPoint != null) ? startPoint
: Constants.HEAD;
ObjectId result = repo.resolve(startPointOrHead);
if (result == null)
throw new RefNotFoundException(MessageFormat.format(
JGitText.get().refNotResolved, startPointOrHead));
return result;
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
List<String> paths = readElementsAt(repository, "6409ee1597a53c6fbee31edf9cde31dc3afbe20f", "src/main/java/org/dstadler/jgit/porcelain");
System.out.println("Had paths for commit: " + paths);
final ObjectId testbranch = repository.resolve("testbranch");
paths = readElementsAt(repository, testbranch.getName(), "src/main/java/org/dstadler/jgit/porcelain");
System.out.println("Had paths for tag: " + paths);
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static RevTree getTree(Repository repository) throws IOException {
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit commit = revWalk.parseCommit(lastCommitId);
System.out.println("Time of commit (seconds since epoch): " + commit.getCommitTime());
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
return tree;
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
List<String> paths = readElementsAt(repository, "6409ee1597a53c6fbee31edf9cde31dc3afbe20f", "src/main/java/org/dstadler/jgit/porcelain");
System.out.println("Had paths for commit: " + paths);
final ObjectId testbranch = repository.resolve("testbranch");
paths = readElementsAt(repository, testbranch.getName(), "src/main/java/org/dstadler/jgit/porcelain");
System.out.println("Had paths for tag: " + paths);
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static RevTree getTree(Repository repository) throws IOException {
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit commit = revWalk.parseCommit(lastCommitId);
System.out.println("Time of commit (seconds since epoch): " + commit.getCommitTime());
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
return tree;
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory merge(String[] refs, ArrayMemory settings) throws IOException, GitAPIException {
MergeCommand command = getWrappedObject().merge();
for (String ref : refs) {
Repository repository = getWrappedObject().getRepository();
ObjectId objectId = repository.resolve(ref);
command.include(objectId);
}
if (settings != null) {
command.setCommit(settings.valueOfIndex("commit").toBoolean());
command.setMessage(settings.valueOfIndex("message").toString());
command.setSquash(settings.valueOfIndex("squash").toBoolean());
Memory fastForward = settings.valueOfIndex("fastForward");
if (fastForward.isNumber()) {
command.setFastForward(MergeCommand.FastForwardMode.valueOf(fastForward.toString()));
}
Memory strategy = settings.valueOfIndex("strategy");
if (strategy.isNotNull()) {
command.setStrategy(MergeStrategy.get(strategy.toString()));
}
}
MergeResult call = command.call();
return GitUtils.valueOf(call);
}
代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin
protected RevCommit findEvalCommitObjectId(@Nonnull String evaluateOnCommit, @Nonnull Repository repo) throws RuntimeException {
try {
ObjectId evalCommitId = repo.resolve(evaluateOnCommit);
try (RevWalk walk = new RevWalk(repo)) {
RevCommit evalCommit = walk.parseCommit(evalCommitId);
walk.dispose();
log.info("evalCommit is [{}]", evalCommit.getName());
return evalCommit;
}
} catch (IOException ex) {
throw new RuntimeException("Unable to obtain " + evaluateOnCommit + " commit!", ex);
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private ObjectId getStashId() throws GitAPIException {
final String revision = stashRef != null ? stashRef : DEFAULT_REF;
final ObjectId stashId;
try {
stashId = repo.resolve(revision);
} catch (IOException e) {
throw new InvalidRefNameException(MessageFormat.format(
JGitText.get().stashResolveFailed, revision), e);
}
if (stashId == null)
throw new InvalidRefNameException(MessageFormat.format(
JGitText.get().stashResolveFailed, revision));
return stashId;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private ObjectId getStartPointObjectId() throws AmbiguousObjectException,
RefNotFoundException, IOException {
if (startCommit != null)
return startCommit.getId();
String startPointOrHead = getStartPointOrHead();
ObjectId result = repo.resolve(startPointOrHead);
if (result == null)
throw new RefNotFoundException(MessageFormat.format(
JGitText.get().refNotResolved, startPointOrHead));
return result;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private ObjectId resolveRefToCommitId() {
try {
return repo.resolve(getRefOrHEAD() + "^{commit}"); //$NON-NLS-1$
} catch (IOException e) {
throw new JGitInternalException(
MessageFormat.format(JGitText.get().cannotRead, getRefOrHEAD()),
e);
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private Collection<Ref> filterRefs(Collection<Ref> refs)
throws RefNotFoundException, IOException {
if (containsCommitish == null)
return refs;
try (RevWalk walk = new RevWalk(repo)) {
ObjectId resolved = repo.resolve(containsCommitish);
if (resolved == null)
throw new RefNotFoundException(MessageFormat.format(
JGitText.get().refNotResolved, containsCommitish));
RevCommit containsCommit = walk.parseCommit(resolved);
return RevWalkUtils.findBranchesReachableFrom(containsCommit, walk,
refs);
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
// from the commit we can build the tree which allows us to construct the TreeParser
//noinspection Duplicates
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(repository.resolve(objectId));
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader reader = repository.newObjectReader()) {
treeParser.reset(reader, tree.getId());
}
walk.dispose();
return treeParser;
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
// from the commit we can build the tree which allows us to construct the TreeParser
//noinspection Duplicates
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(repository.resolve(objectId));
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader reader = repository.newObjectReader()) {
treeParser.reset(reader, tree.getId());
}
walk.dispose();
return treeParser;
}
}
内容来源于网络,如有侵权,请联系作者删除!