本文整理汇总了Java中org.eclipse.jgit.errors.RevisionSyntaxException类的典型用法代码示例。如果您正苦于以下问题:Java RevisionSyntaxException类的具体用法?Java RevisionSyntaxException怎么用?Java RevisionSyntaxException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RevisionSyntaxException类属于org.eclipse.jgit.errors包,在下文中一共展示了RevisionSyntaxException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConfiguration
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的package包/类
/**
* Export the git tag identified by the entry id
*
* @param config
* @param e
* @param exportDirectory
* @throws Exception
*/
public void getConfiguration(Configuration config, Entry e, File exportDirectory) throws Exception {
Preconditions.checkNotNull(config, "Configuration must be supplied.");
Preconditions.checkNotNull(e, "Entry must be supplied.");
Preconditions.checkNotNull(exportDirectory, "Directory must be supplied.");
File zip = new File(exportDirectory, e.getUUID().toString()+".zip");
ArchiveCommand.registerFormat("zip", new ZipFormat());
try (FileOutputStream out = new FileOutputStream(zip);){
LOG.debug("Exporting tag {} to {}", e.getUUID(), zip);
git.archive().setTree(git.getRepository().resolve(e.getUUID().toString()))
.setFormat("zip")
.setOutputStream(out)
.call();
unzip(zip);
} catch (IOException | RevisionSyntaxException | GitAPIException ioe) {
zip.delete();
LOG.error("Error creating archive from tag: " + e.getUUID().toString(), ioe);
throw ioe;
} finally {
ArchiveCommand.unregisterFormat("zip");
}
}
示例2: diff
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的package包/类
/**
* wrapper of git diff ref1..ref2
*/
protected List<DiffInfo> diff(RepositoryPK repositoryPK, String ref1, String ref2) {
try (RepositoryReader reader = new RepositoryReader(repositoryPK)) {
Git git = reader.getGit();
Repository repository = reader.getRepository();
List<DiffEntry> entries = diff(git, ref1, ref2);
List<DiffInfo> diffInfos = new ArrayList<>();
for (DiffEntry entry : entries) {
Optional<FileContent> oldContent = getFileContent(git, entry.getOldPath(), entry.getOldId());
Optional<FileContent> newContent = getFileContent(git, entry.getNewPath(), entry.getNewId());
CustomDiffFormatter diffFormatter = new CustomDiffFormatter(repository);
List<DiffBlock> diffLineList = diffFormatter.diffFormat(entry);
DiffInfo diffInfo = DiffInfo.ofDiff(entry, oldContent.orElse(null), newContent.orElse(null), diffLineList);
diffInfos.add(diffInfo);
}
return diffInfos;
} catch (RevisionSyntaxException | IOException e) {
throw new RuntimeException(e);
}
}
示例3: populateHEADGeneralData
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的package包/类
private void populateHEADGeneralData(RepositoryRevision head,Git git) {
try {
ObjectId headObject = git.getRepository().resolve(Constants.HEAD);
head.setLastCommit(git.log().add(headObject).call().iterator()
.next().getId().getName());
head.setLastCommitMessage(git.log().add(headObject).call()
.iterator().next().getShortMessage());
head.setLastCommitAuthor(git.log().add(headObject).call()
.iterator().next().getAuthorIdent().getName());
} catch (RevisionSyntaxException | IOException | GitAPIException
| NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: resolve
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的package包/类
@Override
public Commit resolve(String reference) {
RevWalk revWalk = null;
try {
ObjectId ref = git.getRepository().resolve(reference);
revWalk = new RevWalk(git.getRepository());
RevCommit revCommit = revWalk.parseCommit(ref);
return new Commit(revCommit.getName(), revCommit.getCommitterIdent().getWhen());
} catch (RevisionSyntaxException | IOException e) {
throw new RepositoryMinerException("Error getting the commit from " + reference + ".", e);
} finally {
if (revWalk != null) {
revWalk.close();
}
}
}
示例5: getFileContentOfLastCommit
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的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());
}
示例6: getStringContentOfLastCommit
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的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");
}
示例7: getStringContentOfCommitID
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的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");
}
示例8: getCommitsFromBranch
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的package包/类
private Iterable<RevCommit> getCommitsFromBranch(String refName) {
try {
return git.log().add(git.getRepository().resolve(refName)).call();
} catch (RevisionSyntaxException | GitAPIException | IOException e) {
close();
throw new RepositoryMinerException(e);
}
}
示例9: merge
import org.eclipse.jgit.errors.RevisionSyntaxException; //导入依赖的package包/类
public boolean merge(String baseBranchName, IssuePK issuePK, String message, LoginContext loginContext) {
String mergeMessage = PullRequest.getMergeMessage(issuePK, new PullRequestEndpoint(issuePK.getRepositoryPK(), baseBranchName))
+ "\n\n" + message;
try (RepositoryReader reader = new RepositoryReader(issuePK.getRepositoryPK())) {
Repository repository = reader.getRepository();
String pullBranch = Constants.R_REFS + "pull/" + issuePK.getIssueId() + "/head";
String baseBranchRefName = Constants.R_HEADS + baseBranchName;
ThreeWayMerger merger = MergeStrategy.RECURSIVE.newMerger(repository, true);
ObjectInserter inserter = repository.newObjectInserter();
try {
ObjectId baseObjectId = repository.resolve(baseBranchRefName);
ObjectId pullBranchObjectId = repository.resolve(pullBranch);
boolean noError = merger.merge(baseObjectId, pullBranchObjectId);
if (!noError) {
throw new RuntimeException("cannot merge!!");
}
ObjectId resultTreeId = merger.getResultTreeId();
PersonIdent personIdent = new PersonIdent(loginContext.getName(), loginContext.getEmail());
CommitBuilder commit = new CommitBuilder();
commit.setCommitter(personIdent);
commit.setAuthor(personIdent);
commit.setMessage(mergeMessage);
commit.setParentIds(baseObjectId, pullBranchObjectId);
commit.setTreeId(resultTreeId);
ObjectId mergedCommitId = inserter.insert(commit);
inserter.flush();
RefUpdate refUpdate = repository.updateRef(baseBranchRefName);
refUpdate.setNewObjectId(mergedCommitId);
refUpdate.setForceUpdate(false);
refUpdate.setRefLogIdent(personIdent);
refUpdate.setRefLogMessage("merged", false);
refUpdate.update();
return true;
} catch (RevisionSyntaxException | IOException e) {
return false;
} finally {
inserter.release();
}
}
}