List of usage examples for org.eclipse.jgit.lib Repository readDirCache
@NonNull public DirCache readDirCache() throws NoWorkTreeException, CorruptObjectException, IOException
From source file:org.eclipse.egit.core.synchronize.WorkingTreeChangeCache.java
License:Open Source License
/** * @param repo// www . j av a 2 s.c o m * with should be scanned * @return list of changes in working tree */ public static Map<String, Change> build(Repository repo) { TreeWalk tw = new TreeWalk(repo); try { int fileNth = tw.addTree(new FileTreeIterator(repo)); int cacheNth = tw.addTree(new DirCacheIterator(repo.readDirCache())); tw.setFilter(new IndexDiffFilter(cacheNth, fileNth)); tw.setRecursive(true); Map<String, Change> result = new HashMap<String, Change>(); MutableObjectId idBuf = new MutableObjectId(); while (tw.next()) { Change change = new Change(); change.name = tw.getNameString(); tw.getObjectId(idBuf, 0); change.objectId = AbbreviatedObjectId.fromObjectId(idBuf); tw.getObjectId(idBuf, 1); change.remoteObjectId = AbbreviatedObjectId.fromObjectId(idBuf); calculateAndSetChangeKind(RIGHT, change); result.put(tw.getPathString(), change); } tw.release(); return result; } catch (IOException e) { Activator.error(e.getMessage(), e); return new HashMap<String, GitCommitsModelCache.Change>(0); } }
From source file:org.eclipse.egit.ui.internal.dialogs.CompareTreeView.java
License:Open Source License
private void buildMaps(Repository repository, RevCommit baseCommit, RevCommit compareCommit, IProgressMonitor monitor) throws InterruptedException, IOException { monitor.beginTask(UIText.CompareTreeView_AnalyzingRepositoryTaskText, IProgressMonitor.UNKNOWN); boolean useIndex = compareVersion.equals(INDEX_VERSION); deletedPaths.clear();/*from w w w . java 2s. c o m*/ equalContentPaths.clear(); baseVersionMap.clear(); compareVersionMap.clear(); compareVersionPathsWithChildren.clear(); addedPaths.clear(); baseVersionPathsWithChildren.clear(); boolean checkIgnored = false; TreeWalk tw = new TreeWalk(repository); try { int baseTreeIndex; if (baseCommit == null) { checkIgnored = true; baseTreeIndex = tw.addTree( new AdaptableFileTreeIterator(repository, ResourcesPlugin.getWorkspace().getRoot())); } else baseTreeIndex = tw .addTree(new CanonicalTreeParser(null, repository.newObjectReader(), baseCommit.getTree())); int compareTreeIndex; if (!useIndex) compareTreeIndex = tw.addTree( new CanonicalTreeParser(null, repository.newObjectReader(), compareCommit.getTree())); else compareTreeIndex = tw.addTree(new DirCacheIterator(repository.readDirCache())); if (input instanceof IResource[]) { IResource[] resources = (IResource[]) input; List<TreeFilter> orFilters = new ArrayList<TreeFilter>(resources.length); for (IResource resource : resources) { String relPath = repositoryMapping.getRepoRelativePath(resource); if (relPath.length() > 0) orFilters.add(PathFilter.create(relPath)); } if (checkIgnored) { if (orFilters.size() > 1) { TreeFilter andFilter = AndTreeFilter.create(new NotIgnoredFilter(baseTreeIndex), OrTreeFilter.create(orFilters)); tw.setFilter(andFilter); } else if (orFilters.size() == 1) { TreeFilter andFilter = AndTreeFilter.create(new NotIgnoredFilter(baseTreeIndex), orFilters.get(0)); tw.setFilter(andFilter); } else tw.setFilter(new NotIgnoredFilter(baseTreeIndex)); } else if (orFilters.size() > 1) tw.setFilter(OrTreeFilter.create(orFilters)); else if (orFilters.size() == 1) tw.setFilter(orFilters.get(0)); } tw.setRecursive(true); if (monitor.isCanceled()) throw new InterruptedException(); while (tw.next()) { if (monitor.isCanceled()) throw new InterruptedException(); AbstractTreeIterator compareVersionIterator = tw.getTree(compareTreeIndex, AbstractTreeIterator.class); AbstractTreeIterator baseVersionIterator = tw.getTree(baseTreeIndex, AbstractTreeIterator.class); if (compareVersionIterator != null && baseVersionIterator != null) { monitor.setTaskName(baseVersionIterator.getEntryPathString()); IPath currentPath = new Path(baseVersionIterator.getEntryPathString()); if (!useIndex) compareVersionMap.put(currentPath, GitFileRevision.inCommit(repository, compareCommit, baseVersionIterator.getEntryPathString(), tw.getObjectId(compareTreeIndex))); else compareVersionMap.put(currentPath, GitFileRevision.inIndex(repository, baseVersionIterator.getEntryPathString())); if (baseCommit != null) baseVersionMap.put(currentPath, GitFileRevision.inCommit(repository, baseCommit, baseVersionIterator.getEntryPathString(), tw.getObjectId(baseTreeIndex))); boolean equalContent = compareVersionIterator.getEntryObjectId() .equals(baseVersionIterator.getEntryObjectId()); if (equalContent) equalContentPaths.add(currentPath); if (equalContent && !showEquals) continue; while (currentPath.segmentCount() > 0) { currentPath = currentPath.removeLastSegments(1); if (!baseVersionPathsWithChildren.add(currentPath)) break; } } else if (baseVersionIterator != null && compareVersionIterator == null) { monitor.setTaskName(baseVersionIterator.getEntryPathString()); // only on base side IPath currentPath = new Path(baseVersionIterator.getEntryPathString()); addedPaths.add(currentPath); if (baseCommit != null) baseVersionMap.put(currentPath, GitFileRevision.inCommit(repository, baseCommit, baseVersionIterator.getEntryPathString(), tw.getObjectId(baseTreeIndex))); while (currentPath.segmentCount() > 0) { currentPath = currentPath.removeLastSegments(1); if (!baseVersionPathsWithChildren.add(currentPath)) break; } } else if (compareVersionIterator != null && baseVersionIterator == null) { monitor.setTaskName(compareVersionIterator.getEntryPathString()); // only on compare side IPath currentPath = new Path(compareVersionIterator.getEntryPathString()); deletedPaths.add(currentPath); List<PathNodeAdapter> children = compareVersionPathsWithChildren .get(currentPath.removeLastSegments(1)); if (children == null) { children = new ArrayList<PathNodeAdapter>(1); compareVersionPathsWithChildren.put(currentPath.removeLastSegments(1), children); } children.add(new PathNodeAdapter(new PathNode(currentPath, Type.FILE_DELETED))); if (!useIndex) compareVersionMap.put(currentPath, GitFileRevision.inCommit(repository, compareCommit, compareVersionIterator.getEntryPathString(), tw.getObjectId(compareTreeIndex))); else compareVersionMap.put(currentPath, GitFileRevision.inIndex(repository, compareVersionIterator.getEntryPathString())); } } } finally { tw.release(); monitor.done(); } }
From source file:org.eclipse.egit.ui.internal.synchronize.model.GitModelCache.java
License:Open Source License
/** * Creates and configures {@link TreeWalk} instance for * {@link GitModelCache#getChildrenImpl()} method. It is IMPORTANT to add * tree that will be used as a base as first, remote tree should be added as * second; {@link GitModelCache#dirCacheIteratorNth} should be set with * value of NTH that corresponds with {@link DirCacheIterator}. * * @return configured instance of TreeW/* w w w .j a v a2 s .co m*/ * @throws IOException */ protected TreeWalk createAndConfigureTreeWalk() throws IOException { TreeWalk tw = createTreeWalk(); tw.setRecursive(true); Repository repo = getRepository(); DirCache index = repo.readDirCache(); ObjectId headId = repo.getRef(Constants.HEAD).getObjectId(); tw.addTree(new RevWalk(repo).parseTree(headId)); tw.addTree(new DirCacheIterator(index)); dirCacheIteratorNth = 1; return tw; }
From source file:org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree.java
License:Open Source License
@Override protected TreeWalk createAndConfigureTreeWalk() throws IOException { TreeWalk tw = createTreeWalk();/*from ww w .j ava2 s .c o m*/ tw.setRecursive(true); Repository repo = getRepository(); tw.addTree(new DirCacheIterator(repo.readDirCache())); tw.addTree(new FileTreeIterator(repo)); dirCacheIteratorNth = 0; NotIgnoredFilter notIgnoredFilter = new NotIgnoredFilter(1); tw.setFilter(AndTreeFilter.create(ANY_DIFF, notIgnoredFilter)); return tw; }
From source file:org.eclipse.emf.compare.egit.internal.merge.DirCacheResourceVariantTreeProvider.java
License:Open Source License
/** * Constructs the resource variant trees by iterating over the given repository's DirCache entries. * * @param repository/* w w w . ja v a 2 s . c om*/ * The repository which DirCache info we need to cache as IResourceVariantTrees. * @param useWorkspace * Whether we should use local data instead of what's in the index for our side. * @throws IOException * if we somehow cannot read the DirCache. */ public DirCacheResourceVariantTreeProvider(Repository repository, boolean useWorkspace) throws IOException { final DirCache cache = repository.readDirCache(); final GitResourceVariantCache baseCache = new GitResourceVariantCache(); final GitResourceVariantCache sourceCache = new GitResourceVariantCache(); final GitResourceVariantCache remoteCache = new GitResourceVariantCache(); for (int i = 0; i < cache.getEntryCount(); i++) { final DirCacheEntry entry = cache.getEntry(i); final IResource resource = ModelEGitResourceUtil.getResourceHandleForLocation(repository, entry.getPathString(), FileMode.fromBits(entry.getRawMode()) == FileMode.TREE); // Resource variants only make sense for IResources. Do not consider // files outside of the workspace or otherwise non accessible. if (resource == null || resource.getProject() == null || !resource.getProject().isAccessible()) { continue; } switch (entry.getStage()) { case DirCacheEntry.STAGE_0: if (useWorkspace) { sourceCache.setVariant(resource, new GitLocalResourceVariant(resource)); } else { sourceCache.setVariant(resource, IndexResourceVariant.create(repository, entry)); } baseCache.setVariant(resource, IndexResourceVariant.create(repository, entry)); remoteCache.setVariant(resource, IndexResourceVariant.create(repository, entry)); break; case DirCacheEntry.STAGE_1: baseCache.setVariant(resource, IndexResourceVariant.create(repository, entry)); break; case DirCacheEntry.STAGE_2: if (useWorkspace) { sourceCache.setVariant(resource, new GitLocalResourceVariant(resource)); } else { sourceCache.setVariant(resource, IndexResourceVariant.create(repository, entry)); } break; case DirCacheEntry.STAGE_3: remoteCache.setVariant(resource, IndexResourceVariant.create(repository, entry)); break; default: throw new IllegalStateException("Invalid stage: " + entry.getStage()); //$NON-NLS-1$ } } baseTree = new GitCachedResourceVariantTree(baseCache); sourceTree = new GitCachedResourceVariantTree(sourceCache); remoteTree = new GitCachedResourceVariantTree(remoteCache); roots = new LinkedHashSet<IResource>(); roots.addAll(baseCache.getRoots()); roots.addAll(sourceCache.getRoots()); roots.addAll(remoteCache.getRoots()); knownResources = new LinkedHashSet<IResource>(); knownResources.addAll(baseCache.getKnownResources()); knownResources.addAll(sourceCache.getKnownResources()); knownResources.addAll(remoteCache.getKnownResources()); }
From source file:org.eclipse.emf.compare.egit.ui.internal.merge.ModelGitMergeEditorInput.java
License:Open Source License
private IDiffContainer buildDiffContainer(Repository repository, RevCommit headCommit, RevCommit ancestorCommit, List<String> filterPaths, RevWalk rw, IProgressMonitor monitor) throws IOException, InterruptedException { monitor.setTaskName(UIText.GitMergeEditorInput_CalculatingDiffTaskName); IDiffContainer result = new DiffNode(Differencer.CONFLICTING); TreeWalk tw = new TreeWalk(repository); try {//from ww w . j a v a 2 s . c o m int dirCacheIndex = tw.addTree(new DirCacheIterator(repository.readDirCache())); int fileTreeIndex = tw.addTree(new FileTreeIterator(repository)); int repositoryTreeIndex = tw.addTree(rw.parseTree(repository.resolve(Constants.HEAD))); // skip ignored resources NotIgnoredFilter notIgnoredFilter = new NotIgnoredFilter(fileTreeIndex); // filter by selected resources if (filterPaths.size() > 1) { List<TreeFilter> suffixFilters = new ArrayList<TreeFilter>(); for (String filterPath : filterPaths) { suffixFilters.add(PathFilter.create(filterPath)); } TreeFilter otf = OrTreeFilter.create(suffixFilters); tw.setFilter(AndTreeFilter.create(otf, notIgnoredFilter)); } else if (filterPaths.size() > 0) { String path = filterPaths.get(0); if (path.length() == 0) { tw.setFilter(notIgnoredFilter); } else { tw.setFilter(AndTreeFilter.create(PathFilter.create(path), notIgnoredFilter)); } } else { tw.setFilter(notIgnoredFilter); } tw.setRecursive(true); while (tw.next()) { if (monitor.isCanceled()) { throw new InterruptedException(); } String gitPath = tw.getPathString(); monitor.setTaskName(gitPath); FileTreeIterator fit = tw.getTree(fileTreeIndex, FileTreeIterator.class); if (fit == null) { continue; } DirCacheIterator dit = tw.getTree(dirCacheIndex, DirCacheIterator.class); final DirCacheEntry dirCacheEntry = dit == null ? null : dit.getDirCacheEntry(); boolean conflicting = dirCacheEntry != null && dirCacheEntry.getStage() > 0; AbstractTreeIterator rt = tw.getTree(repositoryTreeIndex, AbstractTreeIterator.class); // compare local file against HEAD to see if it was modified boolean modified = rt != null && !fit.getEntryObjectId().equals(rt.getEntryObjectId()); // if this is neither conflicting nor changed, we skip it if (!conflicting && !modified) { continue; } ITypedElement right; if (conflicting) { GitFileRevision revision = GitFileRevision.inIndex(repository, gitPath, DirCacheEntry.STAGE_3); String encoding = CompareCoreUtils.getResourceEncoding(repository, gitPath); right = new FileRevisionTypedElement(revision, encoding); } else { right = CompareUtils.getFileRevisionTypedElement(gitPath, headCommit, repository); } // can this really happen? if (right instanceof EmptyTypedElement) { continue; } IFileRevision rev; // if the file is not conflicting (as it was auto-merged) // we will show the auto-merged (local) version Path repositoryPath = new Path(repository.getWorkTree().getAbsolutePath()); IPath location = repositoryPath.append(fit.getEntryPathString()); IFile file = ResourceUtil.getFileForLocation(location, false); if (!conflicting || useWorkspace) { if (file != null) { rev = new LocalFileRevision(file); } else { rev = new WorkingTreeFileRevision(location.toFile()); } } else { rev = GitFileRevision.inIndex(repository, gitPath, DirCacheEntry.STAGE_2); } IRunnableContext runnableContext = getContainer(); if (runnableContext == null) { runnableContext = PlatformUI.getWorkbench().getProgressService(); } EditableRevision leftEditable; if (file != null) { leftEditable = new ResourceEditableRevision(rev, file, runnableContext); } else { leftEditable = new LocationEditableRevision(rev, location, runnableContext); } // make sure we don't need a round trip later try { leftEditable.cacheContents(monitor); } catch (CoreException e) { throw new IOException(e.getMessage()); } int kind = Differencer.NO_CHANGE; if (conflicting) { kind = Differencer.CONFLICTING; } else if (modified) { kind = Differencer.PSEUDO_CONFLICT; } IDiffContainer fileParent = getFileParent(result, repositoryPath, file, location); ITypedElement anc; if (ancestorCommit != null) { anc = CompareUtils.getFileRevisionTypedElement(gitPath, ancestorCommit, repository); } else { anc = null; } // we get an ugly black icon if we have an EmptyTypedElement // instead of null if (anc instanceof EmptyTypedElement) { anc = null; } // create the node as child new DiffNode(fileParent, kind, anc, leftEditable, right); } return result; } finally { tw.close(); } }
From source file:org.eclipse.orion.server.git.servlets.GitIndexHandlerV1.java
License:Open Source License
private boolean handleGet(HttpServletRequest request, HttpServletResponse response, Repository db, String pattern) throws CoreException, IOException, ServletException { DirCache cache = db.readDirCache(); DirCacheEntry entry = cache.getEntry(pattern); if (entry == null) { String msg = NLS.bind("{0} not found in index", pattern); //$NON-NLS-1$ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.OK, HttpServletResponse.SC_NOT_FOUND, msg, null)); }/*from www . j a v a2 s . c om*/ ObjectId blobId = entry.getObjectId(); ObjectStream stream = db.open(blobId, Constants.OBJ_BLOB).openStream(); IOUtilities.pipe(stream, response.getOutputStream(), true, false); return true; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitStatusTest.java
License:Open Source License
@Test public void testConflict() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); // clone1: create JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null); String projectId1 = project1.getString(ProtocolConstants.KEY_ID); IPath clonePath1 = new Path("file").append(project1.getString(ProtocolConstants.KEY_ID)).makeAbsolute(); String contentLocation1 = clone(clonePath1).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata WebRequest request = getGetFilesRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project1 = new JSONObject(response.getText()); JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri1 = gitSection1.getString(GitConstants.KEY_INDEX); String gitHeadUri1 = gitSection1.getString(GitConstants.KEY_HEAD); String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE); // clone2: create JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null); String projectId2 = project2.getString(ProtocolConstants.KEY_ID); IPath clonePath2 = new Path("file").append(project2.getString(ProtocolConstants.KEY_ID)).makeAbsolute(); String contentLocation2 = clone(clonePath2).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata request = getGetFilesRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project2 = new JSONObject(response.getText()); JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri2 = gitSection2.getString(GitConstants.KEY_INDEX); String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD); String gitStatusUri2 = gitSection2.getString(GitConstants.KEY_STATUS); // clone1: change request = getPutFileRequest(projectId1 + "/test.txt", "change from clone1"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: add request = GitAddTest.getPutGitIndexRequest(gitIndexUri1); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: commit request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "change from clone1", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: push ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(true, pushStatus.isOK()); // this is how EGit checks for conflicts Repository db1 = getRepositoryForContentLocation(contentLocation1); Git git = new Git(db1); DirCache cache = db1.readDirCache(); DirCacheEntry entry = cache.getEntry("test.txt"); assertTrue(entry.getStage() == 0);//ww w.j a v a 2 s .c om // clone2: change request = getPutFileRequest(projectId2 + "/test.txt", "change from clone2"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone2: add request = GitAddTest.getPutGitIndexRequest(gitIndexUri2); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone2: commit request = GitCommitTest.getPostGitCommitRequest(gitHeadUri2, "change from clone2", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone2: pull // TODO: replace with REST API for git pull once bug 339114 is fixed Repository db2 = getRepositoryForContentLocation(contentLocation2); git = new Git(db2); PullResult pullResult = git.pull().call(); assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.CONFLICTING); // this is how EGit checks for conflicts cache = db2.readDirCache(); entry = cache.getEntry("test.txt"); assertTrue(entry.getStage() > 0); request = getGetGitStatusRequest(gitStatusUri2); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject statusResponse = new JSONObject(response.getText()); JSONArray statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_ADDED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CHANGED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MISSING); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MODIFIED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_REMOVED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_UNTRACKED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CONFLICTING); assertEquals(1, statusArray.length()); assertNotNull(getChildByName(statusArray, "test.txt")); }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java
License:Open Source License
/** * Returns ignored files in the index/* ww w.jav a 2s .c o m*/ * * @param ref reference to compute list of files for. If null use index. * * @return set of ignored files * @throws IOException * on file system problems */ public Set<String> getIgnoredFiles(RevTree ref) throws IOException { Repository repo = jgitRepo.getRepository(); TreeWalk treeWalk = new TreeWalk(repo); if (ref == null) { DirCache dirCache = repo.readDirCache(); treeWalk.addTree(new DirCacheIterator(dirCache)); } else { treeWalk.addTree(ref); } HashSet<String> ignoredFiles = new HashSet<String>(); int ignoreDepth = Integer.MAX_VALUE; // if the current subtree is ignored - than this is the depth at which to ignoring // starts while (treeWalk.next()) { boolean isSubtree = treeWalk.isSubtree(); int depth = treeWalk.getDepth(); String path = treeWalk.getPathString(); if (isSubtree) { treeWalk.enterSubtree(); } if (depth > ignoreDepth) { if (!isSubtree) { ignoredFiles.add(path); } continue; } if (depth <= ignoreDepth) { // sibling or parent of ignore subtree => reset ignoreDepth = Integer.MAX_VALUE; } if (shouldIgnore(path, isSubtree)) { if (isSubtree) { ignoreDepth = depth; } else { ignoredFiles.add(path); } } } return ignoredFiles; }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java
License:Open Source License
/** * Get all different files (modified/changed, missing/removed, untracked/added) * /* w ww .j av a2s .co m*/ * assumes that no files are in conflict (don't call during merge) * * @return different files * @throws IOException * on file system problems */ public DiffFiles getDiffFiles() throws IOException { final int INDEX = 0; final int WORKDIR = 1; assert (!jgitRepo.inUnresolvedMergeState()); Repository repo = jgitRepo.getRepository(); TreeWalk treeWalk = new TreeWalk(repo); treeWalk.addTree(new DirCacheIterator(repo.readDirCache())); treeWalk.addTree(new FileTreeIterator(repo)); // don't honor ignores - we do it manually instead. Doing it all with the filter // would require a WorkingTreeIterator that does the ignore handling correctly // (both directory including bugs 401161 and only using info/exclude, not .gitignore) treeWalk.setFilter(new IndexDiffFilter(INDEX, WORKDIR, false)); DiffFiles diffFiles = new DiffFiles(); int ignoreDepth = Integer.MAX_VALUE; // if the current subtree is ignored - than this is the depth at which ignoring // starts while (treeWalk.next()) { DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX, DirCacheIterator.class); String path = treeWalk.getPathString(); boolean isSubtree = treeWalk.isSubtree(); int depth = treeWalk.getDepth(); if (dirCacheIterator != null || // in index => either missing or modified !shouldIgnore(path, isSubtree)) { // not in index => untracked if (depth <= ignoreDepth) { ignoreDepth = Integer.MAX_VALUE; } if (dirCacheIterator != null && isSubtree && ignoreDepth == Integer.MAX_VALUE && shouldIgnore(path, isSubtree)) { ignoreDepth = depth; } if (isSubtree) { treeWalk.enterSubtree(); diffFiles.dirSet.add(path); } else if (dirCacheIterator != null || ignoreDepth == Integer.MAX_VALUE) { WorkingTreeIterator workTreeIter = treeWalk.getTree(WORKDIR, WorkingTreeIterator.class); if (workTreeIter != null) { diffFiles.added.add(path); } else { diffFiles.removed.add(path); } } } } return diffFiles; }