本文整理汇总了Java中org.eclipse.jgit.dircache.DirCacheIterator类的典型用法代码示例。如果您正苦于以下问题:Java DirCacheIterator类的具体用法?Java DirCacheIterator怎么用?Java DirCacheIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirCacheIterator类属于org.eclipse.jgit.dircache包,在下文中一共展示了DirCacheIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIterator
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private AbstractTreeIterator getIterator (String commit, ObjectReader or) throws IOException, GitException {
Repository repository = getRepository();
switch (commit) {
case Constants.HEAD:
return getHeadIterator(or);
case GitClient.INDEX:
return new DirCacheIterator(repository.readDirCache());
case GitClient.WORKING_TREE:
return new FileTreeIterator(repository);
default:
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(or, Utils.findCommit(repository, commit).getTree());
return p;
}
}
示例2: blockingPreviewDiff
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
requireNonNull(baseRevision, "baseRevision");
requireNonNull(changes, "changes");
baseRevision = blockingNormalize(baseRevision);
try (ObjectReader reader = jGitRepository.newObjectReader();
RevWalk revWalk = new RevWalk(reader);
DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
final ObjectId baseTreeId = toTreeId(revWalk, baseRevision);
final DirCache dirCache = DirCache.newInCore();
final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
if (numEdits == 0) {
return Collections.emptyMap();
}
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(reader, baseTreeId);
diffFormatter.setRepository(jGitRepository);
List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
return toChangeMap(result);
} catch (IOException e) {
throw new StorageException("failed to perform a dry-run diff", e);
}
}
示例3: getTreeIterator
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private AbstractTreeIterator getTreeIterator( String commitId ) throws Exception {
if ( commitId == null ) {
return new EmptyTreeIterator();
}
if ( commitId.equals( WORKINGTREE ) ) {
return new FileTreeIterator( git.getRepository() );
} else if ( commitId.equals( INDEX ) ) {
return new DirCacheIterator( git.getRepository().readDirCache() );
} else {
ObjectId id = git.getRepository().resolve( commitId );
if ( id == null ) { // commitId does not exist
return new EmptyTreeIterator();
} else {
CanonicalTreeParser treeIterator = new CanonicalTreeParser();
try ( RevWalk rw = new RevWalk( git.getRepository() ) ) {
RevTree tree = rw.parseTree( id );
try ( ObjectReader reader = git.getRepository().newObjectReader() ) {
treeIterator.reset( reader, tree.getId() );
}
}
return treeIterator;
}
}
}
示例4: prepareTreeParser
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException {
if ("~~staged~~".equals(ref)) {
return new DirCacheIterator(DirCache.read(repository));
} else if ("~~unstaged~~".equals(ref)) {
return new FileTreeIterator(repository);
}
try (RevWalk walk = new RevWalk(repository)) {
ObjectId commitObjectId = repository.resolve(ref);
if (commitObjectId == null) {
throw new GitInvalidRefException(format("invalid git ref %s", ref));
}
log.debug("ref: {}, commit id: {}", ref, commitObjectId.toString());
RevCommit commit = walk.parseCommit(commitObjectId);
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader objectReader = repository.newObjectReader()) {
treeParser.reset(objectReader, tree.getId());
}
return treeParser;
}
}
示例5: buildDirCache
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private void buildDirCache(TreeWalk walk, DirCacheBuilder builder)
throws MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException, IOException {
while (walk.next()) {
AbstractTreeIterator cIter = walk.getTree(0,
AbstractTreeIterator.class);
if (cIter == null) {
// Not in commit, don't add to new index
continue;
}
final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
entry.setFileMode(cIter.getEntryFileMode());
entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());
DirCacheIterator dcIter = walk.getTree(1, DirCacheIterator.class);
if (dcIter != null && dcIter.idEqual(cIter)) {
DirCacheEntry indexEntry = dcIter.getDirCacheEntry();
entry.setLastModified(indexEntry.getLastModified());
entry.setLength(indexEntry.getLength());
}
builder.add(entry);
}
}
示例6: addTree
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private int addTree(int mode, Shell shell, Repository rep, RevWalk rw, TreeWalk tw) throws Exception {
int index = -1;
switch (mode) {
case GitModeMenuMgr.MODE_STAGING:
tw.addTree(new DirCacheIterator(rep.readDirCache()));
break;
case GitModeMenuMgr.MODE_OTHERS://choose a GIT ref
CompareTargetSelectionDialog dialog = new CompareTargetSelectionDialog(shell, rep, null);
if (dialog.open() != CompareTargetSelectionDialog.OK) {
return -2;
}
ObjectId obId = rep.getRef(dialog.getRefName()).getObjectId();//"master"
tw.addTree(rw.parseCommit(obId).getTree());
break;
case GitModeMenuMgr.MODE_BRANCH_HEAD:
Ref head = rep.getRef(Constants.HEAD);
RevCommit rc = rw.parseCommit(head.getObjectId());
tw.addTree(rc.getTree());
break;
default://compare to working area
index = tw.addTree(new FileTreeIterator(rep));
break;
}
return index;
}
示例7: getTreeIterator
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private AbstractTreeIterator getTreeIterator(Repository repo, String commit) throws IOException {
if (commit.equals("dircache")) {
return new DirCacheIterator(repo.readDirCache());
}
if (commit.equals("filetree")) {
return new FileTreeIterator(repo);
}
ObjectId treeId = repo.resolve(commit + "^{tree}");
if (treeId == null) {
throw new NullPointerException();
}
CanonicalTreeParser treeIter = new CanonicalTreeParser();
ObjectReader reader = repo.newObjectReader();
treeIter.reset(reader, treeId);
return treeIter;
}
示例8: detectRenames
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private Map<String, DiffEntry> detectRenames (Repository repository, DirCache cache, ObjectId commitId) {
List<DiffEntry> entries;
TreeWalk treeWalk = new TreeWalk(repository);
try {
treeWalk.setRecursive(true);
treeWalk.reset();
if (commitId != null) {
treeWalk.addTree(new RevWalk(repository).parseTree(commitId));
} else {
treeWalk.addTree(new EmptyTreeIterator());
}
// Index
treeWalk.addTree(new DirCacheIterator(cache));
treeWalk.setFilter(TreeFilter.ANY_DIFF);
entries = DiffEntry.scan(treeWalk);
RenameDetector d = new RenameDetector(repository);
d.addAll(entries);
entries = d.compute();
} catch (IOException ex) {
entries = Collections.<DiffEntry>emptyList();
} finally {
treeWalk.release();
}
Map<String, DiffEntry> renames = new HashMap<String, DiffEntry>();
for (DiffEntry e : entries) {
if (e.getChangeType().equals(DiffEntry.ChangeType.COPY) || e.getChangeType().equals(DiffEntry.ChangeType.RENAME)) {
renames.put(e.getNewPath(), e);
}
}
return renames;
}
示例9: checkout
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
public void checkout () throws IOException, GitException {
TreeWalk treeWalk = new TreeWalk(repository);
Collection<String> relativePaths = Utils.getRelativePaths(repository.getWorkTree(), roots);
if (!relativePaths.isEmpty()) {
treeWalk.setFilter(PathFilterGroup.createFromStrings(relativePaths));
}
treeWalk.setRecursive(true);
treeWalk.reset();
treeWalk.addTree(new DirCacheIterator(cache));
treeWalk.addTree(new FileTreeIterator(repository));
String lastAddedPath = null;
ObjectReader od = repository.newObjectReader();
try {
while (treeWalk.next() && !monitor.isCanceled()) {
File path = new File(repository.getWorkTree(), treeWalk.getPathString());
if (treeWalk.getPathString().equals(lastAddedPath)) {
// skip conflicts
continue;
} else {
lastAddedPath = treeWalk.getPathString();
}
DirCacheIterator dit = treeWalk.getTree(0, DirCacheIterator.class);
FileTreeIterator fit = treeWalk.getTree(1, FileTreeIterator.class);
if (dit != null && (recursively || directChild(roots, repository.getWorkTree(), path)) && (fit == null || fit.isModified(dit.getDirCacheEntry(), checkContent, od))) {
// update entry
listener.notifyFile(path, treeWalk.getPathString());
checkoutEntry(repository, path, dit.getDirCacheEntry(), od);
}
}
} finally {
od.release();
treeWalk.release();
}
}
示例10: testDiffRenameDetectionProblem
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
public void testDiffRenameDetectionProblem () throws Exception {
File file = new File(workDir, "file");
File renamed = new File(workDir, "renamed");
File patchFile = new File(workDir.getParentFile(), "diff.patch");
write(file, "hey, i will be renamed\n");
add(file);
commit(file);
file.renameTo(renamed);
write(renamed, "hey, i will be renamed\nand now i am\n");
OutputStream out = new BufferedOutputStream(new FileOutputStream(patchFile));
DiffFormatter formatter = new DiffFormatter(out);
formatter.setRepository(repository);
ObjectReader or = null;
try {
formatter.setDetectRenames(true);
AbstractTreeIterator firstTree = new DirCacheIterator(repository.readDirCache());;
AbstractTreeIterator secondTree = new FileTreeIterator(repository);
formatter.format(firstTree, secondTree);
formatter.flush();
fail("Fixed in JGit, modify and simplify the sources in ExportDiff command");
} catch (IOException ex) {
assertEquals("Missing blob 7b34a309b8dbae2686c9e597efef28a612e48aff", ex.getMessage());
} finally {
if (or != null) {
or.release();
}
formatter.release();
}
}
示例11: isTracked
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
public boolean isTracked(String path) throws IOException {
ObjectId objectId = localRepo.resolve(Constants.HEAD);
RevTree tree;
RevWalk walk = null;
if (objectId != null) {
walk = new RevWalk(localRepo);
tree = walk.parseTree(objectId);
}
else {
tree = null;
}
try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
treeWalk.setRecursive(true);
if (tree != null)
treeWalk.addTree(tree);
else
treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(localRepo.readDirCache()));
treeWalk.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
return treeWalk.next();
}
finally {
if (walk != null)
walk.close();
}
}
示例12: resetIndex
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private void resetIndex(RevCommit revCommit, DirCache dirCache)
throws IOException {
TreeWalk walk = new TreeWalk(cachingObjectReader);
walk.setRecursive(true);
RevTree revTree = revCommit.getTree();
walk.addTree(revTree);
DirCacheBuilder builder = dirCache.builder();
walk.addTree(new DirCacheIterator(dirCache));
buildDirCache(walk, builder);
builder.finish();
}
示例13: indexToWorkingTree
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
/**
* Show changes between index and working tree.
*
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> indexToWorkingTree(DiffFormatter formatter) throws IOException {
DirCache dirCache = null;
ObjectReader reader = repository.newObjectReader();
List<DiffEntry> diff;
try {
dirCache = repository.lockDirCache();
DirCacheIterator iterA = new DirCacheIterator(dirCache);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader =
new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
} finally {
reader.close();
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}
示例14: commitToIndex
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
/**
* Show changes between specified revision and index. If <code>commitId == null</code> then view
* changes between HEAD and index.
*
* @param commitId id of commit, pass <code>null</code> is the same as pass HEAD
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> commitToIndex(String commitId, DiffFormatter formatter)
throws IOException {
if (commitId == null) {
commitId = Constants.HEAD;
}
ObjectId commitA = repository.resolve(commitId);
if (commitA == null) {
throw new IllegalArgumentException("Invalid commit id " + commitId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
DirCache dirCache = null;
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
dirCache = repository.lockDirCache();
CanonicalTreeParser iterA = new CanonicalTreeParser();
iterA.reset(reader, treeA);
DirCacheIterator iterB = new DirCacheIterator(dirCache);
if (!params.isNoRenames()) {
// Use embedded RenameDetector it works well with index and
// revision history.
formatter.setDetectRenames(true);
int renameLimit = params.getRenameLimit();
if (renameLimit > 0) {
formatter.getRenameDetector().setRenameLimit(renameLimit);
}
}
diff = formatter.scan(iterA, iterB);
} finally {
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}
示例15: mergeConflicts
import org.eclipse.jgit.dircache.DirCacheIterator; //导入依赖的package包/类
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException {
DirCacheBuilder builder = cache.builder();
DirCacheBuildIterator dci = new DirCacheBuildIterator(builder);
TreeWalk walk = new TreeWalk(getRepository());
ObjectDatabase od = null;
DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum(
ConfigConstants.CONFIG_DIFF_SECTION, null,
ConfigConstants.CONFIG_KEY_ALGORITHM,
DiffAlgorithm.SupportedAlgorithm.HISTOGRAM);
MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg));
try {
od = getRepository().getObjectDatabase();
walk.addTree(dci);
walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts)));
String lastPath = null;
DirCacheEntry[] entries = new DirCacheEntry[3];
walk.setRecursive(true);
while (walk.next()) {
DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry();
String path = e.getPathString();
if (lastPath != null && !lastPath.equals(path)) {
resolveEntries(merger, lastPath, entries, od, builder);
}
if (e.getStage() == 0) {
DirCacheIterator c = walk.getTree(0, DirCacheIterator.class);
builder.add(c.getDirCacheEntry());
} else {
entries[e.getStage() - 1] = e;
lastPath = path;
}
}
resolveEntries(merger, lastPath, entries, od, builder);
builder.commit();
} catch (IOException ex) {
throw new GitException(ex);
} finally {
walk.release();
if (od != null) {
od.close();
}
}
}