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