本文整理汇总了Java中org.eclipse.jgit.errors.AmbiguousObjectException类的典型用法代码示例。如果您正苦于以下问题:Java AmbiguousObjectException类的具体用法?Java AmbiguousObjectException怎么用?Java AmbiguousObjectException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmbiguousObjectException类属于org.eclipse.jgit.errors包,在下文中一共展示了AmbiguousObjectException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.eclipse.jgit.errors.AmbiguousObjectException; //导入依赖的package包/类
private byte[] open(ObjectReader reader, FileMode mode,
AbbreviatedObjectId id) throws IOException {
if (mode == FileMode.MISSING)
return new byte[] { };
if (mode.getObjectType() != Constants.OBJ_BLOB)
return new byte[] { };
if (!id.isComplete()) {
Collection<ObjectId> ids = reader.resolve(id);
if (ids.size() == 1)
id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
else if (ids.size() == 0)
throw new MissingObjectException(id, Constants.OBJ_BLOB);
else
throw new AmbiguousObjectException(id, ids);
}
ObjectLoader ldr = reader.open(id.toObjectId());
return ldr.getCachedBytes(bigFileThreshold);
}
示例2: getFileContentOfLastCommit
import org.eclipse.jgit.errors.AmbiguousObjectException; //导入依赖的package包/类
public static File getFileContentOfLastCommit(String filePath,Repository repository) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
// find the HEAD
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering that is
// defined
RevWalk revWalk = new RevWalk(repository);
RevCommit commit = revWalk.parseCommit(lastCommitId);
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now try to find a specific file
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setPostOrderTraversal(true);
treeWalk.setFilter(PathFilter.create(filePath));
if (!treeWalk.next()) {
//TODO the file is added to project
throw new IllegalStateException(
"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
return Utils.inputStreamToFile(loader.openStream());
}
示例3: getStringContentOfLastCommit
import org.eclipse.jgit.errors.AmbiguousObjectException; //导入依赖的package包/类
public static String getStringContentOfLastCommit(String filePath,Repository repository) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
// find the HEAD
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering that is
// defined
RevWalk revWalk = new RevWalk(repository);
RevCommit commit = revWalk.parseCommit(lastCommitId);
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now try to find a specific file
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setPostOrderTraversal(true);
treeWalk.setFilter(PathFilter.create(filePath));
if (!treeWalk.next()) {
//TODO the file is added to project
throw new IllegalStateException(
"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
return IOUtils.stringFromFile(Utils.inputStreamToFile(loader.openStream()).getAbsolutePath(), "utf-8");
}
示例4: getStringContentOfCommitID
import org.eclipse.jgit.errors.AmbiguousObjectException; //导入依赖的package包/类
public static String getStringContentOfCommitID(String filePath,Repository repository, String commitID) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
// find the HEAD
ObjectId lastCommitId = repository.resolve(commitID);
// a RevWalk allows to walk over commits based on some filtering that is
// defined
RevWalk revWalk = new RevWalk(repository);
RevCommit commit = revWalk.parseCommit(lastCommitId);
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now try to find a specific file
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setPostOrderTraversal(true);
treeWalk.setFilter(PathFilter.create(filePath.substring(filePath.indexOf("/") + 1)));
if (!treeWalk.next()) {
//TODO the file is added to project
throw new IllegalStateException(
"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
return IOUtils.stringFromFile(Utils.inputStreamToFile(loader.openStream()).getAbsolutePath(), "utf-8");
}
示例5: doHandle
import org.eclipse.jgit.errors.AmbiguousObjectException; //导入依赖的package包/类
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler,
MergeRequestObjectAttributesBuilder objectAttributes) throws GitAPIException, IOException, NoHeadException,
NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException,
AmbiguousObjectException, IncorrectObjectTypeException, MissingObjectException, InterruptedException {
Git.init().setDirectory(tmp.getRoot()).call();
tmp.newFile("test");
Git git = Git.open(tmp.getRoot());
git.add().addFilepattern("test");
RevCommit commit = git.commit().setMessage("test").call();
ObjectId head = git.getRepository().resolve(Constants.HEAD);
String repositoryUrl = tmp.getRoot().toURI().toString();
final OneShotEvent buildTriggered = new OneShotEvent();
FreeStyleProject project = jenkins.createFreeStyleProject();
project.setScm(new GitSCM(repositoryUrl));
project.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
buildTriggered.signal();
return true;
}
});
project.setQuietPeriod(0);
mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
.withObjectAttributes(objectAttributes
.withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
.withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
.build())
.withProject(project()
.withWebUrl("https://gitlab.org/test.git")
.build()
)
.build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
newMergeRequestLabelFilter(null));
buildTriggered.block(10000);
return buildTriggered;
}
示例6: loadCommits
import org.eclipse.jgit.errors.AmbiguousObjectException; //导入依赖的package包/类
protected List<GitInformationCommit> loadCommits(Repository repository, Git git, Ref branch) throws GitAPIException, NoHeadException, IOException, MissingObjectException, IncorrectObjectTypeException, AmbiguousObjectException {
RevWalk revwalk = new RevWalk(repository);
List<GitInformationCommit> result = new ArrayList<>();
for (Ref rbranch : git.branchList().call()) {
if (rbranch.getName().equals(branch.getName())) {
Iterable<RevCommit> commits = git.log().all().call();
for (RevCommit commit : commits) {
boolean foundInThisBranch = false;
RevCommit targetCommit = revwalk.parseCommit(repository.resolve(commit.getName()));
for (Map.Entry<String, Ref> e : repository.getAllRefs().entrySet()) {
if (e.getKey().startsWith(Constants.R_HEADS)) {
if (revwalk.isMergedInto(targetCommit, revwalk.parseCommit(e.getValue().getObjectId()))) {
String foundInBranch = e.getValue().getName();
if (branch.getName().equals(foundInBranch)) {
foundInThisBranch = true;
break;
}
}
}
}
if (foundInThisBranch) {
GitInformationCommit cmt = new GitInformationCommit();
cmt.Checksum = commit.getName();
cmt.Author = commit.getAuthorIdent().getName();
cmt.Mail = commit.getAuthorIdent().getEmailAddress();
cmt.Date = new Date(commit.getCommitTime());
cmt.Message = commit.getFullMessage();
result.add(cmt);
}
}
}
}
return result;
}