@Override public boolean include(TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; final int m = walker.getRawMode(baseTree); for (int i = 1; i < n; i++) if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree)) return true; return false; }
TreeFilter[] markTreeFilters) throws IOException { if (walk.getTreeCount() != 2) throw new IllegalArgumentException( JGitText.get().treeWalkMustHaveExactlyTwoTrees);
for (int i = 0; i < treeWalk.getTreeCount(); i++) { recordFileMode(path, treeWalk.getFileMode(i));
/** {@inheritDoc} */ @Override public boolean include(TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; final int m = walker.getRawMode(baseTree); for (int i = 1; i < n; i++) { DirCacheIterator baseDirCache = walker.getTree(baseTree, DirCacheIterator.class); DirCacheIterator newDirCache = walker.getTree(i, DirCacheIterator.class); if (baseDirCache != null && newDirCache != null) { DirCacheEntry baseDci = baseDirCache.getDirCacheEntry(); DirCacheEntry newDci = newDirCache.getDirCacheEntry(); if (baseDci != null && newDci != null) { if (baseDci.isAssumeValid() != newDci.isAssumeValid()) return true; if (baseDci.isAssumeValid()) // && newDci.isAssumeValid() return false; } } if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree)) return true; } return false; }
public boolean include(TreeWalk tw) throws MissingObjectException, IncorrectObjectTypeException, IOException { final int cnt = tw.getTreeCount(); final int wm = tw.getRawMode(workingTree); WorkingTreeIterator wi = workingTree(tw);
private AbstractTreeIterator getSingleTreeIterator(TreeWalk treeWalk, String commitMessage) { AbstractTreeIterator result = null; int treeCount = treeWalk.getTreeCount(); for (int i = 0; i < treeCount; i++) { AbstractTreeIterator it = treeWalk.getTree(i, AbstractTreeIterator.class); if (it != null) { if (result != null) { String msg = "Trees of repositories overlap in path '" + it.getEntryPathString() + "'. " + "We can only merge non-overlapping trees, " + "so make sure the repositories have been prepared for that. " + "One possible way is to process each repository to move the root to a subdirectory first.\n" + "Current commit:\n" + commitMessage; throw new IllegalStateException(msg); } else { result = it; } } } return result; } }
@Override public boolean include(TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; final int m = walker.getRawMode(baseTree); for (int i = 1; i < n; i++) if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree)) return true; return false; }
@Override public boolean include(final TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; final int m = walker.getRawMode(baseTree); for (int i = 1; i < n; i++) if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree)) return true; return false; }
@Override public File get(String file) { try { if (repository == null) { initRepository(); } AnyObjectId id = repository.resolve(Constants.HEAD); RevCommit commit = new RevWalk(repository).parseCommit(id); LOGGER.debug("Looking up file {} in HEAD revision", file); TreeWalk treeWalk = TreeWalk.forPath(repository, file, new AnyObjectId[] { commit.getTree() }); if (treeWalk == null) { return null; } ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1); if (objectId == ObjectId.zeroId()) { LOGGER.debug("File {} couldn't be found in HEAD revision", file); return null; } String fileName = getFilename(file); LOGGER.debug("Creating file from saved repository content"); File tmp = File.createTempFile(fileName, null); tmp.deleteOnExit(); OutputStream os = new FileOutputStream(tmp); os.write(repository.open(objectId).getCachedBytes()); os.close(); return tmp; } catch (Exception e) { throw new ScmException(e); } }
@Override public List<FileData> apply(org.eclipse.jgit.lib.Repository repository, TreeWalk rootWalk, String baseFolder) throws IOException, GitAPIException { if (rootWalk != null) { if (rootWalk.getFilter() == TreeFilter.ALL) { return collectFolderData(rootWalk, baseFolder); } else { if (rootWalk.getTreeCount() > 0) { try (TreeWalk dirWalk = new TreeWalk(repository)) { dirWalk.addTree(rootWalk.getObjectId(0)); return collectFolderData(dirWalk, baseFolder); } } } } return Collections.emptyList(); }
if (rootWalk.getTreeCount() > 0) { try (TreeWalk dirWalk = new TreeWalk(repository)) { dirWalk.addTree(rootWalk.getObjectId(0));
@Override public File get(String file, CommitRef ref) { try { if (repository == null) { initRepository(); } AnyObjectId id = repository.resolve(ref.getStringRepresentation()); RevCommit commit = new RevWalk(repository).parseCommit(id); LOGGER.debug("Looking up file {} in revision {}", file, ref.getStringRepresentation()); TreeWalk treeWalk = TreeWalk.forPath(repository, file, new AnyObjectId[] { commit.getTree() }); if (treeWalk == null) { return null; } ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1); if (objectId == ObjectId.zeroId()) { return null; } String fileName = getFilename(file); LOGGER.debug("Creating file from saved repository content"); File tmp = File.createTempFile(fileName, null); tmp.deleteOnExit(); OutputStream os = new FileOutputStream(tmp); os.write(repository.open(objectId).getCachedBytes()); os.close(); return tmp; } catch (Exception e) { throw new ScmException(e); } }
@Override public boolean exists(String arg0) { try { AnyObjectId id = repository.resolve(Constants.HEAD); RevCommit commit = new RevWalk(repository).parseCommit(id); LOGGER.debug("Looking up file {} in HEAD revision", arg0); TreeWalk treeWalk = TreeWalk.forPath(repository, arg0, new AnyObjectId[] { commit.getTree() }); if (treeWalk == null) { return false; } ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1); LOGGER.debug("File {} received commit id {} at commit", arg0, objectId.name()); return !objectId.equals(ObjectId.zeroId()); } catch (Exception e) { throw new ScmException(e); } }
@Override public boolean exists(String arg0, CommitRef arg1) { try { AnyObjectId id = repository.resolve(arg1.getStringRepresentation()); RevCommit commit = new RevWalk(repository).parseCommit(id); LOGGER.debug("Looking up file {} in revision {}", arg0, arg1.getStringRepresentation()); TreeWalk treeWalk = TreeWalk.forPath(repository, arg0, new AnyObjectId[] { commit.getTree() }); if (treeWalk == null) { return false; } ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1); LOGGER.debug("File {} received commit id {} at commit", arg0, objectId.name()); return !objectId.equals(ObjectId.zeroId()); } catch (Exception e) { throw new ScmException(e); } }
public boolean include(final RevWalk walker, final RevCommit commit) throws IOException { final TreeWalk walk = TreeUtils.diffWithParents(walker, commit); final MutableObjectId id = new MutableObjectId(); final ObjectId zero = ObjectId.zeroId(); final DuplicateContainer dupes = new DuplicateContainer(commit); while (walk.next()) { if (!walk.isSubtree()) continue; final String path = walk.getPathString(); for (int i = 0; i < walk.getTreeCount(); i++) { walk.getObjectId(id, i); if (!zero.equals(id)) dupes.include(id.toObjectId(), path); } walk.enterSubtree(); } if (dupes.validate()) duplicates.put(commit, dupes); return true; }
@Override public boolean include(final TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; final int m = walker.getRawMode(baseTree); for (int i = 1; i < n; i++) { DirCacheIterator baseDirCache = walker.getTree(baseTree, DirCacheIterator.class); DirCacheIterator newDirCache = walker.getTree(i, DirCacheIterator.class); if (baseDirCache != null && newDirCache != null) { DirCacheEntry baseDci = baseDirCache.getDirCacheEntry(); DirCacheEntry newDci = newDirCache.getDirCacheEntry(); if (baseDci != null && newDci != null) { if (baseDci.isAssumeValid() != newDci.isAssumeValid()) return true; if (baseDci.isAssumeValid()) // && newDci.isAssumeValid() return false; } } if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree)) return true; } return false; }
/** {@inheritDoc} */ @Override public boolean include(TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; final int m = walker.getRawMode(baseTree); for (int i = 1; i < n; i++) { DirCacheIterator baseDirCache = walker.getTree(baseTree, DirCacheIterator.class); DirCacheIterator newDirCache = walker.getTree(i, DirCacheIterator.class); if (baseDirCache != null && newDirCache != null) { DirCacheEntry baseDci = baseDirCache.getDirCacheEntry(); DirCacheEntry newDci = newDirCache.getDirCacheEntry(); if (baseDci != null && newDci != null) { if (baseDci.isAssumeValid() != newDci.isAssumeValid()) return true; if (baseDci.isAssumeValid()) // && newDci.isAssumeValid() return false; } } if (walker.getRawMode(i) != m || !walker.idEqual(i, baseTree)) return true; } return false; }
protected List<DiffEntry> computeDifferences( RevCommit commit, RevWalk walker, Repository repository ) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { // Set up the tree walk to obtain the difference between the commit and it's parent(s) ... TreeWalk tw = new TreeWalk(repository); tw.setRecursive(true); tw.addTree(commit.getTree()); RevCommit[] parents = commit.getParents(); for (RevCommit parent : parents) { RevCommit parentCommit = walker.parseCommit(parent); tw.addTree(parentCommit.getTree()); //if there are multiple parents, we can't really have a multiple-way diff so we'll only look at the first parent if (parents.length > 1) { connector.getLogger().warn(GitI18n.commitWithMultipleParents, commit.getName(), parentCommit.getName()); break; } } if (tw.getTreeCount() == 1) { connector.getLogger().warn(GitI18n.commitWithSingleParent, commit.getName(), tw.getObjectId(0).name()); return Collections.emptyList(); } // Now process the diff of each file ... return DiffEntry.scan(tw); }
final TreeWalk walk = createTreeWalk(walker, commit); final List<DiffEntry> diffs; final int treeCount = walk.getTreeCount(); switch (treeCount) { case 0:
walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter)); final int nTree = walk.getTreeCount(); while (walk.next()) { for (int i = 1; i < nTree; i++)