本文整理汇总了Java中org.eclipse.jgit.lib.Repository.newObjectReader方法的典型用法代码示例。如果您正苦于以下问题:Java Repository.newObjectReader方法的具体用法?Java Repository.newObjectReader怎么用?Java Repository.newObjectReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.lib.Repository
的用法示例。
在下文中一共展示了Repository.newObjectReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: diff
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
public static List<DiffEntry> diff(Repository repository, AnyObjectId oldRevId, AnyObjectId newRevId) {
List<DiffEntry> diffs = new ArrayList<>();
try ( DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE);
RevWalk revWalk = new RevWalk(repository);
ObjectReader reader = repository.newObjectReader();) {
diffFormatter.setRepository(repository);
diffFormatter.setDetectRenames(true);
diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
if (!oldRevId.equals(ObjectId.zeroId()))
oldTreeParser.reset(reader, revWalk.parseCommit(oldRevId).getTree());
CanonicalTreeParser newTreeParser = new CanonicalTreeParser();
if (!newRevId.equals(ObjectId.zeroId()))
newTreeParser.reset(reader, revWalk.parseCommit(newRevId).getTree());
for (DiffEntry entry: diffFormatter.scan(oldTreeParser, newTreeParser)) {
if (!Objects.equal(entry.getOldPath(), entry.getNewPath())
|| !Objects.equal(entry.getOldMode(), entry.getNewMode())
|| entry.getOldId()==null || !entry.getOldId().isComplete()
|| entry.getNewId()== null || !entry.getNewId().isComplete()
|| !entry.getOldId().equals(entry.getNewId())) {
diffs.add(entry);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return diffs;
}
示例2: getLastCommitTreeId
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
/**
*
* @param repo
* @param lastCommitId
* @return
* @throws LargeObjectException
* @throws IOException
*/
public static ObjectId getLastCommitTreeId(Repository repo, ObjectId lastCommitId) throws LargeObjectException, IOException {
if (lastCommitId == null) {
return null;
} else {
ObjectReader objectReader = repo.newObjectReader();
ObjectLoader objectLoader = objectReader.open(lastCommitId);
RevCommit oldCommit = RevCommit.parse(objectLoader.getBytes());
return oldCommit.getTree().getId();
}
}
示例3: getObjectFromRepo
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
/**
*
* @param repo
* @param blobId
* @return
* @throws LargeObjectException
* @throws IOException
*/
public static byte[] getObjectFromRepo(Repository repo, ObjectId blobId) throws LargeObjectException, IOException {
ObjectReader objectReader = repo.newObjectReader();
ObjectLoader objectLoader = objectReader.open(blobId);
// int type = objectLoader.getType(); // Constants.OBJ_BLOB
byte[] bytes = objectLoader.getBytes();
return bytes;
}
示例4: run
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
@Override
protected void run() throws GitException {
Repository repository = getRepository();
DiffFormatter formatter = new DiffFormatter(out);
formatter.setRepository(repository);
ObjectReader or = null;
String workTreePath = repository.getWorkTree().getAbsolutePath();
try {
Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
if (!pathFilters.isEmpty()) {
formatter.setPathFilter(PathFilterGroup.create(pathFilters));
}
if (repository.getConfig().get(WorkingTreeOptions.KEY).getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
// work-around for autocrlf
formatter.setDiffComparator(new AutoCRLFComparator());
}
or = repository.newObjectReader();
AbstractTreeIterator firstTree = getIterator(firstCommit, or);
AbstractTreeIterator secondTree = getIterator(secondCommit, or);
List<DiffEntry> diffEntries;
if (secondTree instanceof WorkingTreeIterator) {
// remote when fixed in JGit, see ExportDiffTest.testDiffRenameDetectionProblem
formatter.setDetectRenames(false);
diffEntries = formatter.scan(firstTree, secondTree);
formatter.setDetectRenames(true);
RenameDetector detector = formatter.getRenameDetector();
detector.reset();
detector.addAll(diffEntries);
diffEntries = detector.compute(new ContentSource.Pair(ContentSource.create(or), ContentSource.create((WorkingTreeIterator) secondTree)), NullProgressMonitor.INSTANCE);
} else {
formatter.setDetectRenames(true);
diffEntries = formatter.scan(firstTree, secondTree);
}
for (DiffEntry ent : diffEntries) {
if (monitor.isCanceled()) {
break;
}
listener.notifyFile(new File(workTreePath + File.separator + ent.getNewPath()), ent.getNewPath());
formatter.format(ent);
}
formatter.flush();
} catch (IOException ex) {
throw new GitException(ex);
} finally {
if (or != null) {
or.release();
}
formatter.release();
}
}
示例5: applySteps
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
private void applySteps (List<RebaseTodoLine> steps, boolean skipFirstStep) throws GitAPIException, IOException {
Repository repository = getRepository();
ObjectReader or = repository.newObjectReader();
CherryPickResult res = null;
boolean skipped = false;
List<Ref> cherryPickedRefs = new ArrayList<>();
for (Iterator<RebaseTodoLine> it = steps.iterator(); it.hasNext();) {
RebaseTodoLine step = it.next();
if (step.getAction() == RebaseTodoLine.Action.PICK) {
if (skipFirstStep && !skipped) {
it.remove();
writeTodoFile(repository, steps);
skipped = true;
continue;
}
Collection<ObjectId> ids = or.resolve(step.getCommit());
if (ids.size() != 1) {
throw new JGitInternalException("Could not resolve uniquely the abbreviated object ID");
}
org.eclipse.jgit.api.CherryPickCommand command = new Git(repository).cherryPick();
command.include(ids.iterator().next());
if (workAroundStrategyIssue) {
command.setStrategy(new FailuresDetectRecurciveStrategy());
}
res = command.call();
if (res.getStatus() == CherryPickResult.CherryPickStatus.OK) {
it.remove();
writeTodoFile(repository, steps);
cherryPickedRefs.addAll(res.getCherryPickedRefs());
} else {
break;
}
} else {
it.remove();
}
}
if (res == null) {
result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK, cherryPickedRefs);
} else {
result = createResult(res, cherryPickedRefs);
}
if (steps.isEmpty()) {
// sequencer no longer needed
Utils.deleteRecursively(getSequencerFolder());
}
}
示例6: RevWalk
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
/**
* Create a new revision walker for a given repository.
*
* @param repo
* the repository the walker will obtain data from. An
* ObjectReader will be created by the walker, and will be closed
* when the walker is closed.
*/
public RevWalk(final Repository repo) {
this(repo.newObjectReader(), true);
}
示例7: ObjectWalk
import org.eclipse.jgit.lib.Repository; //导入方法依赖的package包/类
/**
* Create a new revision and object walker for a given repository.
*
* @param repo
* the repository the walker will obtain data from.
*/
public ObjectWalk(final Repository repo) {
this(repo.newObjectReader());
}