View Javadoc
1   /*
2    * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3    * Copyright (C) 2007-2008, Robin Rosenberg <robin.rosenberg@dewire.com>
4    * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
5    * Copyright (C) 2013, Robin Stocker <robin@nibor.org>
6    * Copyright (C) 2014, Axel Richard <axel.richard@obeo.fr>
7    * and other copyright owners as documented in the project's IP log.
8    *
9    * This program and the accompanying materials are made available
10   * under the terms of the Eclipse Distribution License v1.0 which
11   * accompanies this distribution, is reproduced below, and is
12   * available at http://www.eclipse.org/org/documents/edl-v10.php
13   *
14   * All rights reserved.
15   *
16   * Redistribution and use in source and binary forms, with or
17   * without modification, are permitted provided that the following
18   * conditions are met:
19   *
20   * - Redistributions of source code must retain the above copyright
21   *   notice, this list of conditions and the following disclaimer.
22   *
23   * - Redistributions in binary form must reproduce the above
24   *   copyright notice, this list of conditions and the following
25   *   disclaimer in the documentation and/or other materials provided
26   *   with the distribution.
27   *
28   * - Neither the name of the Eclipse Foundation, Inc. nor the
29   *   names of its contributors may be used to endorse or promote
30   *   products derived from this software without specific prior
31   *   written permission.
32   *
33   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
34   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
35   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
38   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
40   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
42   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
45   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46   */
47  
48  package org.eclipse.jgit.lib;
49  
50  import java.io.IOException;
51  import java.text.MessageFormat;
52  import java.util.ArrayList;
53  import java.util.Collection;
54  import java.util.Collections;
55  import java.util.HashMap;
56  import java.util.HashSet;
57  import java.util.Map;
58  import java.util.Set;
59  
60  import org.eclipse.jgit.dircache.DirCache;
61  import org.eclipse.jgit.dircache.DirCacheEntry;
62  import org.eclipse.jgit.dircache.DirCacheIterator;
63  import org.eclipse.jgit.errors.ConfigInvalidException;
64  import org.eclipse.jgit.errors.IncorrectObjectTypeException;
65  import org.eclipse.jgit.errors.MissingObjectException;
66  import org.eclipse.jgit.errors.StopWalkException;
67  import org.eclipse.jgit.internal.JGitText;
68  import org.eclipse.jgit.revwalk.RevTree;
69  import org.eclipse.jgit.revwalk.RevWalk;
70  import org.eclipse.jgit.submodule.SubmoduleWalk;
71  import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
72  import org.eclipse.jgit.treewalk.AbstractTreeIterator;
73  import org.eclipse.jgit.treewalk.EmptyTreeIterator;
74  import org.eclipse.jgit.treewalk.FileTreeIterator;
75  import org.eclipse.jgit.treewalk.TreeWalk;
76  import org.eclipse.jgit.treewalk.WorkingTreeIterator;
77  import org.eclipse.jgit.treewalk.TreeWalk.OperationType;
78  import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
79  import org.eclipse.jgit.treewalk.filter.IndexDiffFilter;
80  import org.eclipse.jgit.treewalk.filter.SkipWorkTreeFilter;
81  import org.eclipse.jgit.treewalk.filter.TreeFilter;
82  
83  /**
84   * Compares the index, a tree, and the working directory Ignored files are not
85   * taken into account. The following information is retrieved:
86   * <ul>
87   * <li>added files</li>
88   * <li>changed files</li>
89   * <li>removed files</li>
90   * <li>missing files</li>
91   * <li>modified files</li>
92   * <li>conflicting files</li>
93   * <li>untracked files</li>
94   * <li>files with assume-unchanged flag</li>
95   * </ul>
96   */
97  public class IndexDiff {
98  
99  	/**
100 	 * Represents the state of the index for a certain path regarding the stages
101 	 * - which stages exist for a path and which not (base, ours, theirs).
102 	 * <p>
103 	 * This is used for figuring out what kind of conflict occurred.
104 	 *
105 	 * @see IndexDiff#getConflictingStageStates()
106 	 * @since 3.0
107 	 */
108 	public static enum StageState {
109 		/**
110 		 * Exists in base, but neither in ours nor in theirs.
111 		 */
112 		BOTH_DELETED(1),
113 
114 		/**
115 		 * Only exists in ours.
116 		 */
117 		ADDED_BY_US(2),
118 
119 		/**
120 		 * Exists in base and ours, but no in theirs.
121 		 */
122 		DELETED_BY_THEM(3),
123 
124 		/**
125 		 * Only exists in theirs.
126 		 */
127 		ADDED_BY_THEM(4),
128 
129 		/**
130 		 * Exists in base and theirs, but not in ours.
131 		 */
132 		DELETED_BY_US(5),
133 
134 		/**
135 		 * Exists in ours and theirs, but not in base.
136 		 */
137 		BOTH_ADDED(6),
138 
139 		/**
140 		 * Exists in all stages, content conflict.
141 		 */
142 		BOTH_MODIFIED(7);
143 
144 		private final int stageMask;
145 
146 		private StageState(int stageMask) {
147 			this.stageMask = stageMask;
148 		}
149 
150 		int getStageMask() {
151 			return stageMask;
152 		}
153 
154 		/**
155 		 * @return whether there is a "base" stage entry
156 		 */
157 		public boolean hasBase() {
158 			return (stageMask & 1) != 0;
159 		}
160 
161 		/**
162 		 * @return whether there is an "ours" stage entry
163 		 */
164 		public boolean hasOurs() {
165 			return (stageMask & 2) != 0;
166 		}
167 
168 		/**
169 		 * @return whether there is a "theirs" stage entry
170 		 */
171 		public boolean hasTheirs() {
172 			return (stageMask & 4) != 0;
173 		}
174 
175 		static StageState fromMask(int stageMask) {
176 			// bits represent: theirs, ours, base
177 			switch (stageMask) {
178 			case 1: // 0b001
179 				return BOTH_DELETED;
180 			case 2: // 0b010
181 				return ADDED_BY_US;
182 			case 3: // 0b011
183 				return DELETED_BY_THEM;
184 			case 4: // 0b100
185 				return ADDED_BY_THEM;
186 			case 5: // 0b101
187 				return DELETED_BY_US;
188 			case 6: // 0b110
189 				return BOTH_ADDED;
190 			case 7: // 0b111
191 				return BOTH_MODIFIED;
192 			default:
193 				return null;
194 			}
195 		}
196 	}
197 
198 	private static final class ProgressReportingFilter extends TreeFilter {
199 
200 		private final ProgressMonitor monitor;
201 
202 		private int count = 0;
203 
204 		private int stepSize;
205 
206 		private final int total;
207 
208 		private ProgressReportingFilter(ProgressMonitor monitor, int total) {
209 			this.monitor = monitor;
210 			this.total = total;
211 			stepSize = total / 100;
212 			if (stepSize == 0)
213 				stepSize = 1000;
214 		}
215 
216 		@Override
217 		public boolean shouldBeRecursive() {
218 			return false;
219 		}
220 
221 		@Override
222 		public boolean include(TreeWalk walker)
223 				throws MissingObjectException,
224 				IncorrectObjectTypeException, IOException {
225 			count++;
226 			if (count % stepSize == 0) {
227 				if (count <= total)
228 					monitor.update(stepSize);
229 				if (monitor.isCancelled())
230 					throw StopWalkException.INSTANCE;
231 			}
232 			return true;
233 		}
234 
235 		@Override
236 		public TreeFilter clone() {
237 			throw new IllegalStateException(
238 					"Do not clone this kind of filter: " //$NON-NLS-1$
239 							+ getClass().getName());
240 		}
241 	}
242 
243 	private final static int TREE = 0;
244 
245 	private final static int INDEX = 1;
246 
247 	private final static int WORKDIR = 2;
248 
249 	private final Repository repository;
250 
251 	private final RevTree tree;
252 
253 	private TreeFilter filter = null;
254 
255 	private final WorkingTreeIterator initialWorkingTreeIterator;
256 
257 	private Set<String> added = new HashSet<String>();
258 
259 	private Set<String> changed = new HashSet<String>();
260 
261 	private Set<String> removed = new HashSet<String>();
262 
263 	private Set<String> missing = new HashSet<String>();
264 
265 	private Set<String> modified = new HashSet<String>();
266 
267 	private Set<String> untracked = new HashSet<String>();
268 
269 	private Map<String, StageState> conflicts = new HashMap<String, StageState>();
270 
271 	private Set<String> ignored;
272 
273 	private Set<String> assumeUnchanged;
274 
275 	private DirCache dirCache;
276 
277 	private IndexDiffFilter indexDiffFilter;
278 
279 	private Map<String, IndexDiff> submoduleIndexDiffs = new HashMap<String, IndexDiff>();
280 
281 	private IgnoreSubmoduleMode ignoreSubmoduleMode = null;
282 
283 	private Map<FileMode, Set<String>> fileModes = new HashMap<FileMode, Set<String>>();
284 
285 	/**
286 	 * Construct an IndexDiff
287 	 *
288 	 * @param repository
289 	 * @param revstr
290 	 *            symbolic name e.g. HEAD
291 	 *            An EmptyTreeIterator is used if <code>revstr</code> cannot be resolved.
292 	 * @param workingTreeIterator
293 	 *            iterator for working directory
294 	 * @throws IOException
295 	 */
296 	public IndexDiff(Repository repository, String revstr,
297 			WorkingTreeIterator workingTreeIterator) throws IOException {
298 		this(repository, repository.resolve(revstr), workingTreeIterator);
299 	}
300 
301 	/**
302 	 * Construct an Indexdiff
303 	 *
304 	 * @param repository
305 	 * @param objectId
306 	 *            tree id. If null, an EmptyTreeIterator is used.
307 	 * @param workingTreeIterator
308 	 *            iterator for working directory
309 	 * @throws IOException
310 	 */
311 	public IndexDiff(Repository repository, ObjectId objectId,
312 			WorkingTreeIterator workingTreeIterator) throws IOException {
313 		this.repository = repository;
314 		if (objectId != null)
315 			tree = new RevWalk(repository).parseTree(objectId);
316 		else
317 			tree = null;
318 		this.initialWorkingTreeIterator = workingTreeIterator;
319 	}
320 
321 	/**
322 	 * @param mode
323 	 *            defines how modifications in submodules are treated
324 	 * @since 3.6
325 	 */
326 	public void setIgnoreSubmoduleMode(IgnoreSubmoduleMode mode) {
327 		this.ignoreSubmoduleMode = mode;
328 	}
329 
330 	/**
331 	 * A factory to producing WorkingTreeIterators
332 	 * @since 3.6
333 	 */
334 	public interface WorkingTreeIteratorFactory {
335 		/**
336 		 * @param repo
337 		 * @return a WorkingTreeIterator for repo
338 		 */
339 		public WorkingTreeIterator getWorkingTreeIterator(Repository repo);
340 	}
341 
342 	private WorkingTreeIteratorFactory wTreeIt = new WorkingTreeIteratorFactory() {
343 		public WorkingTreeIterator getWorkingTreeIterator(Repository repo) {
344 			return new FileTreeIterator(repo);
345 		}
346 	};
347 
348 	/**
349 	 * Allows higher layers to set the factory for WorkingTreeIterators.
350 	 *
351 	 * @param wTreeIt
352 	 * @since 3.6
353 	 */
354 	public void setWorkingTreeItFactory(WorkingTreeIteratorFactory wTreeIt) {
355 		this.wTreeIt = wTreeIt;
356 	}
357 
358 	/**
359 	 * Sets a filter. Can be used e.g. for restricting the tree walk to a set of
360 	 * files.
361 	 *
362 	 * @param filter
363 	 */
364 	public void setFilter(TreeFilter filter) {
365 		this.filter = filter;
366 	}
367 
368 	/**
369 	 * Run the diff operation. Until this is called, all lists will be empty.
370 	 * Use {@link #diff(ProgressMonitor, int, int, String)} if a progress
371 	 * monitor is required.
372 	 *
373 	 * @return if anything is different between index, tree, and workdir
374 	 * @throws IOException
375 	 */
376 	public boolean diff() throws IOException {
377 		return diff(null, 0, 0, ""); //$NON-NLS-1$
378 	}
379 
380 	/**
381 	 * Run the diff operation. Until this is called, all lists will be empty.
382 	 * <p>
383 	 * The operation may be aborted by the progress monitor. In that event it
384 	 * will report what was found before the cancel operation was detected.
385 	 * Callers should ignore the result if monitor.isCancelled() is true. If a
386 	 * progress monitor is not needed, callers should use {@link #diff()}
387 	 * instead. Progress reporting is crude and approximate and only intended
388 	 * for informing the user.
389 	 *
390 	 * @param monitor
391 	 *            for reporting progress, may be null
392 	 * @param estWorkTreeSize
393 	 *            number or estimated files in the working tree
394 	 * @param estIndexSize
395 	 *            number of estimated entries in the cache
396 	 * @param title
397 	 *
398 	 * @return if anything is different between index, tree, and workdir
399 	 * @throws IOException
400 	 */
401 	public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
402 			int estIndexSize, final String title)
403 			throws IOException {
404 		dirCache = repository.readDirCache();
405 
406 		try (TreeWalk treeWalk = new TreeWalk(repository)) {
407 			treeWalk.setOperationType(OperationType.CHECKIN_OP);
408 			treeWalk.setRecursive(true);
409 			// add the trees (tree, dirchache, workdir)
410 			if (tree != null)
411 				treeWalk.addTree(tree);
412 			else
413 				treeWalk.addTree(new EmptyTreeIterator());
414 			treeWalk.addTree(new DirCacheIterator(dirCache));
415 			treeWalk.addTree(initialWorkingTreeIterator);
416 			initialWorkingTreeIterator.setDirCacheIterator(treeWalk, 1);
417 			Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);
418 
419 			if (monitor != null) {
420 				// Get the maximum size of the work tree and index
421 				// and add some (quite arbitrary)
422 				if (estIndexSize == 0)
423 					estIndexSize = dirCache.getEntryCount();
424 				int total = Math.max(estIndexSize * 10 / 9,
425 						estWorkTreeSize * 10 / 9);
426 				monitor.beginTask(title, total);
427 				filters.add(new ProgressReportingFilter(monitor, total));
428 			}
429 
430 			if (filter != null)
431 				filters.add(filter);
432 			filters.add(new SkipWorkTreeFilter(INDEX));
433 			indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
434 			filters.add(indexDiffFilter);
435 			treeWalk.setFilter(AndTreeFilter.create(filters));
436 			fileModes.clear();
437 			while (treeWalk.next()) {
438 				AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
439 						AbstractTreeIterator.class);
440 				DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
441 						DirCacheIterator.class);
442 				WorkingTreeIterator workingTreeIterator = treeWalk
443 						.getTree(WORKDIR, WorkingTreeIterator.class);
444 
445 				if (dirCacheIterator != null) {
446 					final DirCacheEntry dirCacheEntry = dirCacheIterator
447 							.getDirCacheEntry();
448 					if (dirCacheEntry != null) {
449 						int stage = dirCacheEntry.getStage();
450 						if (stage > 0) {
451 							String path = treeWalk.getPathString();
452 							addConflict(path, stage);
453 							continue;
454 						}
455 					}
456 				}
457 
458 				if (treeIterator != null) {
459 					if (dirCacheIterator != null) {
460 						if (!treeIterator.idEqual(dirCacheIterator)
461 								|| treeIterator
462 										.getEntryRawMode() != dirCacheIterator
463 												.getEntryRawMode()) {
464 							// in repo, in index, content diff => changed
465 							if (!isEntryGitLink(treeIterator)
466 									|| !isEntryGitLink(dirCacheIterator)
467 									|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
468 								changed.add(treeWalk.getPathString());
469 						}
470 					} else {
471 						// in repo, not in index => removed
472 						if (!isEntryGitLink(treeIterator)
473 								|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
474 							removed.add(treeWalk.getPathString());
475 						if (workingTreeIterator != null)
476 							untracked.add(treeWalk.getPathString());
477 					}
478 				} else {
479 					if (dirCacheIterator != null) {
480 						// not in repo, in index => added
481 						if (!isEntryGitLink(dirCacheIterator)
482 								|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
483 							added.add(treeWalk.getPathString());
484 					} else {
485 						// not in repo, not in index => untracked
486 						if (workingTreeIterator != null
487 								&& !workingTreeIterator.isEntryIgnored()) {
488 							untracked.add(treeWalk.getPathString());
489 						}
490 					}
491 				}
492 
493 				if (dirCacheIterator != null) {
494 					if (workingTreeIterator == null) {
495 						// in index, not in workdir => missing
496 						if (!isEntryGitLink(dirCacheIterator)
497 								|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
498 							missing.add(treeWalk.getPathString());
499 					} else {
500 						if (workingTreeIterator.isModified(
501 								dirCacheIterator.getDirCacheEntry(), true,
502 								treeWalk.getObjectReader())) {
503 							// in index, in workdir, content differs => modified
504 							if (!isEntryGitLink(dirCacheIterator)
505 									|| !isEntryGitLink(workingTreeIterator)
506 									|| (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL
507 											&& ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
508 								modified.add(treeWalk.getPathString());
509 						}
510 					}
511 				}
512 
513 				for (int i = 0; i < treeWalk.getTreeCount(); i++) {
514 					Set<String> values = fileModes.get(treeWalk.getFileMode(i));
515 					String path = treeWalk.getPathString();
516 					if (path != null) {
517 						if (values == null)
518 							values = new HashSet<String>();
519 						values.add(path);
520 						fileModes.put(treeWalk.getFileMode(i), values);
521 					}
522 				}
523 			}
524 		}
525 
526 		if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
527 			IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode;
528 			SubmoduleWalk smw = SubmoduleWalk.forIndex(repository);
529 			while (smw.next()) {
530 				try {
531 					if (localIgnoreSubmoduleMode == null)
532 						localIgnoreSubmoduleMode = smw.getModulesIgnore();
533 					if (IgnoreSubmoduleMode.ALL
534 							.equals(localIgnoreSubmoduleMode))
535 						continue;
536 				} catch (ConfigInvalidException e) {
537 					IOException e1 = new IOException(MessageFormat.format(
538 							JGitText.get().invalidIgnoreParamSubmodule,
539 							smw.getPath()));
540 					e1.initCause(e);
541 					throw e1;
542 				}
543 				Repository subRepo = smw.getRepository();
544 				if (subRepo != null) {
545 					try {
546 						ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$
547 						if (subHead != null
548 								&& !subHead.equals(smw.getObjectId()))
549 							modified.add(smw.getPath());
550 						else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
551 							IndexDiff smid = submoduleIndexDiffs.get(smw
552 									.getPath());
553 							if (smid == null) {
554 								smid = new IndexDiff(subRepo,
555 										smw.getObjectId(),
556 										wTreeIt.getWorkingTreeIterator(subRepo));
557 								submoduleIndexDiffs.put(smw.getPath(), smid);
558 							}
559 							if (smid.diff()) {
560 								if (ignoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED
561 										&& smid.getAdded().isEmpty()
562 										&& smid.getChanged().isEmpty()
563 										&& smid.getConflicting().isEmpty()
564 										&& smid.getMissing().isEmpty()
565 										&& smid.getModified().isEmpty()
566 										&& smid.getRemoved().isEmpty()) {
567 									continue;
568 								}
569 								modified.add(smw.getPath());
570 							}
571 						}
572 					} finally {
573 						subRepo.close();
574 					}
575 				}
576 			}
577 
578 		}
579 
580 		// consume the remaining work
581 		if (monitor != null)
582 			monitor.endTask();
583 
584 		ignored = indexDiffFilter.getIgnoredPaths();
585 		if (added.isEmpty() && changed.isEmpty() && removed.isEmpty()
586 				&& missing.isEmpty() && modified.isEmpty()
587 				&& untracked.isEmpty())
588 			return false;
589 		else
590 			return true;
591 	}
592 
593 	private boolean isEntryGitLink(AbstractTreeIterator ti) {
594 		return ((ti != null) && (ti.getEntryRawMode() == FileMode.GITLINK
595 				.getBits()));
596 	}
597 
598 	private void addConflict(String path, int stage) {
599 		StageState existingStageStates = conflicts.get(path);
600 		byte stageMask = 0;
601 		if (existingStageStates != null)
602 			stageMask |= existingStageStates.getStageMask();
603 		// stage 1 (base) should be shifted 0 times
604 		int shifts = stage - 1;
605 		stageMask |= (1 << shifts);
606 		StageState stageState = StageState.fromMask(stageMask);
607 		conflicts.put(path, stageState);
608 	}
609 
610 	/**
611 	 * @return list of files added to the index, not in the tree
612 	 */
613 	public Set<String> getAdded() {
614 		return added;
615 	}
616 
617 	/**
618 	 * @return list of files changed from tree to index
619 	 */
620 	public Set<String> getChanged() {
621 		return changed;
622 	}
623 
624 	/**
625 	 * @return list of files removed from index, but in tree
626 	 */
627 	public Set<String> getRemoved() {
628 		return removed;
629 	}
630 
631 	/**
632 	 * @return list of files in index, but not filesystem
633 	 */
634 	public Set<String> getMissing() {
635 		return missing;
636 	}
637 
638 	/**
639 	 * @return list of files modified on disk relative to the index
640 	 */
641 	public Set<String> getModified() {
642 		return modified;
643 	}
644 
645 	/**
646 	 * @return list of files that are not ignored, and not in the index.
647 	 */
648 	public Set<String> getUntracked() {
649 		return untracked;
650 	}
651 
652 	/**
653 	 * @return list of files that are in conflict, corresponds to the keys of
654 	 *         {@link #getConflictingStageStates()}
655 	 */
656 	public Set<String> getConflicting() {
657 		return conflicts.keySet();
658 	}
659 
660 	/**
661 	 * @return the map from each path of {@link #getConflicting()} to its
662 	 *         corresponding {@link StageState}
663 	 * @since 3.0
664 	 */
665 	public Map<String, StageState> getConflictingStageStates() {
666 		return conflicts;
667 	}
668 
669 	/**
670 	 * The method returns the list of ignored files and folders. Only the root
671 	 * folder of an ignored folder hierarchy is reported. If a/b/c is listed in
672 	 * the .gitignore then you should not expect a/b/c/d/e/f to be reported
673 	 * here. Only a/b/c will be reported. Furthermore only ignored files /
674 	 * folders are returned that are NOT in the index.
675 	 *
676 	 * @return list of files / folders that are ignored
677 	 */
678 	public Set<String> getIgnoredNotInIndex() {
679 		return ignored;
680 	}
681 
682 	/**
683 	 * @return list of files with the flag assume-unchanged
684 	 */
685 	public Set<String> getAssumeUnchanged() {
686 		if (assumeUnchanged == null) {
687 			HashSet<String> unchanged = new HashSet<String>();
688 			for (int i = 0; i < dirCache.getEntryCount(); i++)
689 				if (dirCache.getEntry(i).isAssumeValid())
690 					unchanged.add(dirCache.getEntry(i).getPathString());
691 			assumeUnchanged = unchanged;
692 		}
693 		return assumeUnchanged;
694 	}
695 
696 	/**
697 	 * @return list of folders containing only untracked files/folders
698 	 */
699 	public Set<String> getUntrackedFolders() {
700 		return ((indexDiffFilter == null) ? Collections.<String> emptySet()
701 				: new HashSet<String>(indexDiffFilter.getUntrackedFolders()));
702 	}
703 
704 	/**
705 	 * Get the file mode of the given path in the index
706 	 *
707 	 * @param path
708 	 * @return file mode
709 	 */
710 	public FileMode getIndexMode(final String path) {
711 		final DirCacheEntry entry = dirCache.getEntry(path);
712 		return entry != null ? entry.getFileMode() : FileMode.MISSING;
713 	}
714 
715 	/**
716 	 * Get the list of paths that IndexDiff has detected to differ and have the
717 	 * given file mode
718 	 *
719 	 * @param mode
720 	 * @return the list of paths that IndexDiff has detected to differ and have
721 	 *         the given file mode
722 	 * @since 3.6
723 	 */
724 	public Set<String> getPathsWithIndexMode(final FileMode mode) {
725 		Set<String> paths = fileModes.get(mode);
726 		if (paths == null)
727 			paths = new HashSet<String>();
728 		return paths;
729 	}
730 }