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 	 *            a {@link org.eclipse.jgit.lib.Repository} object.
289 	 * @param revstr
290 	 *            symbolic name e.g. HEAD An EmptyTreeIterator is used if
291 	 *            <code>revstr</code> cannot be resolved.
292 	 * @param workingTreeIterator
293 	 *            iterator for working directory
294 	 * @throws java.io.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 	 *            a {@link org.eclipse.jgit.lib.Repository} object.
306 	 * @param objectId
307 	 *            tree id. If null, an EmptyTreeIterator is used.
308 	 * @param workingTreeIterator
309 	 *            iterator for working directory
310 	 * @throws java.io.IOException
311 	 */
312 	public IndexDiff(Repository repository, ObjectId objectId,
313 			WorkingTreeIterator workingTreeIterator) throws IOException {
314 		this.repository = repository;
315 		if (objectId != null) {
316 			try (RevWalkRevWalk.html#RevWalk">RevWalk rw = new RevWalk(repository)) {
317 				tree = rw.parseTree(objectId);
318 			}
319 		} else {
320 			tree = null;
321 		}
322 		this.initialWorkingTreeIterator = workingTreeIterator;
323 	}
324 
325 	/**
326 	 * Defines how modifications in submodules are treated
327 	 *
328 	 * @param mode
329 	 *            defines how modifications in submodules are treated
330 	 * @since 3.6
331 	 */
332 	public void setIgnoreSubmoduleMode(IgnoreSubmoduleMode mode) {
333 		this.ignoreSubmoduleMode = mode;
334 	}
335 
336 	/**
337 	 * A factory to producing WorkingTreeIterators
338 	 * @since 3.6
339 	 */
340 	public interface WorkingTreeIteratorFactory {
341 		/**
342 		 * @param repo
343 		 *            the repository
344 		 * @return working tree iterator
345 		 */
346 		public WorkingTreeIterator getWorkingTreeIterator(Repository repo);
347 	}
348 
349 	private WorkingTreeIteratorFactory wTreeIt = new WorkingTreeIteratorFactory() {
350 		@Override
351 		public WorkingTreeIterator getWorkingTreeIterator(Repository repo) {
352 			return new FileTreeIterator(repo);
353 		}
354 	};
355 
356 	/**
357 	 * Allows higher layers to set the factory for WorkingTreeIterators.
358 	 *
359 	 * @param wTreeIt
360 	 * @since 3.6
361 	 */
362 	public void setWorkingTreeItFactory(WorkingTreeIteratorFactory wTreeIt) {
363 		this.wTreeIt = wTreeIt;
364 	}
365 
366 	/**
367 	 * Sets a filter. Can be used e.g. for restricting the tree walk to a set of
368 	 * files.
369 	 *
370 	 * @param filter
371 	 *            a {@link org.eclipse.jgit.treewalk.filter.TreeFilter} object.
372 	 */
373 	public void setFilter(TreeFilter filter) {
374 		this.filter = filter;
375 	}
376 
377 	/**
378 	 * Run the diff operation. Until this is called, all lists will be empty.
379 	 * Use {@link #diff(ProgressMonitor, int, int, String)} if a progress
380 	 * monitor is required.
381 	 *
382 	 * @return if anything is different between index, tree, and workdir
383 	 * @throws java.io.IOException
384 	 */
385 	public boolean diff() throws IOException {
386 		return diff(null, 0, 0, ""); //$NON-NLS-1$
387 	}
388 
389 	/**
390 	 * Run the diff operation. Until this is called, all lists will be empty.
391 	 * <p>
392 	 * The operation may be aborted by the progress monitor. In that event it
393 	 * will report what was found before the cancel operation was detected.
394 	 * Callers should ignore the result if monitor.isCancelled() is true. If a
395 	 * progress monitor is not needed, callers should use {@link #diff()}
396 	 * instead. Progress reporting is crude and approximate and only intended
397 	 * for informing the user.
398 	 *
399 	 * @param monitor
400 	 *            for reporting progress, may be null
401 	 * @param estWorkTreeSize
402 	 *            number or estimated files in the working tree
403 	 * @param estIndexSize
404 	 *            number of estimated entries in the cache
405 	 * @param title a {@link java.lang.String} object.
406 	 * @return if anything is different between index, tree, and workdir
407 	 * @throws java.io.IOException
408 	 */
409 	public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
410 			int estIndexSize, final String title)
411 			throws IOException {
412 		dirCache = repository.readDirCache();
413 
414 		try (TreeWalklk.html#TreeWalk">TreeWalk treeWalk = new TreeWalk(repository)) {
415 			treeWalk.setOperationType(OperationType.CHECKIN_OP);
416 			treeWalk.setRecursive(true);
417 			// add the trees (tree, dirchache, workdir)
418 			if (tree != null)
419 				treeWalk.addTree(tree);
420 			else
421 				treeWalk.addTree(new EmptyTreeIterator());
422 			treeWalk.addTree(new DirCacheIterator(dirCache));
423 			treeWalk.addTree(initialWorkingTreeIterator);
424 			initialWorkingTreeIterator.setDirCacheIterator(treeWalk, 1);
425 			Collection<TreeFilter> filters = new ArrayList<>(4);
426 
427 			if (monitor != null) {
428 				// Get the maximum size of the work tree and index
429 				// and add some (quite arbitrary)
430 				if (estIndexSize == 0)
431 					estIndexSize = dirCache.getEntryCount();
432 				int total = Math.max(estIndexSize * 10 / 9,
433 						estWorkTreeSize * 10 / 9);
434 				monitor.beginTask(title, total);
435 				filters.add(new ProgressReportingFilter(monitor, total));
436 			}
437 
438 			if (filter != null)
439 				filters.add(filter);
440 			filters.add(new SkipWorkTreeFilter(INDEX));
441 			indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
442 			filters.add(indexDiffFilter);
443 			treeWalk.setFilter(AndTreeFilter.create(filters));
444 			fileModes.clear();
445 			while (treeWalk.next()) {
446 				AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
447 						AbstractTreeIterator.class);
448 				DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
449 						DirCacheIterator.class);
450 				WorkingTreeIterator workingTreeIterator = treeWalk
451 						.getTree(WORKDIR, WorkingTreeIterator.class);
452 
453 				if (dirCacheIterator != null) {
454 					final DirCacheEntry dirCacheEntry = dirCacheIterator
455 							.getDirCacheEntry();
456 					if (dirCacheEntry != null) {
457 						int stage = dirCacheEntry.getStage();
458 						if (stage > 0) {
459 							String path = treeWalk.getPathString();
460 							addConflict(path, stage);
461 							continue;
462 						}
463 					}
464 				}
465 
466 				if (treeIterator != null) {
467 					if (dirCacheIterator != null) {
468 						if (!treeIterator.idEqual(dirCacheIterator)
469 								|| treeIterator
470 										.getEntryRawMode() != dirCacheIterator
471 												.getEntryRawMode()) {
472 							// in repo, in index, content diff => changed
473 							if (!isEntryGitLink(treeIterator)
474 									|| !isEntryGitLink(dirCacheIterator)
475 									|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
476 								changed.add(treeWalk.getPathString());
477 						}
478 					} else {
479 						// in repo, not in index => removed
480 						if (!isEntryGitLink(treeIterator)
481 								|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
482 							removed.add(treeWalk.getPathString());
483 						if (workingTreeIterator != null)
484 							untracked.add(treeWalk.getPathString());
485 					}
486 				} else {
487 					if (dirCacheIterator != null) {
488 						// not in repo, in index => added
489 						if (!isEntryGitLink(dirCacheIterator)
490 								|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
491 							added.add(treeWalk.getPathString());
492 					} else {
493 						// not in repo, not in index => untracked
494 						if (workingTreeIterator != null
495 								&& !workingTreeIterator.isEntryIgnored()) {
496 							untracked.add(treeWalk.getPathString());
497 						}
498 					}
499 				}
500 
501 				if (dirCacheIterator != null) {
502 					if (workingTreeIterator == null) {
503 						// in index, not in workdir => missing
504 						if (!isEntryGitLink(dirCacheIterator)
505 								|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
506 							missing.add(treeWalk.getPathString());
507 					} else {
508 						if (workingTreeIterator.isModified(
509 								dirCacheIterator.getDirCacheEntry(), true,
510 								treeWalk.getObjectReader())) {
511 							// in index, in workdir, content differs => modified
512 							if (!isEntryGitLink(dirCacheIterator)
513 									|| !isEntryGitLink(workingTreeIterator)
514 									|| (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL
515 											&& ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
516 								modified.add(treeWalk.getPathString());
517 						}
518 					}
519 				}
520 
521 				String path = treeWalk.getPathString();
522 				if (path != null) {
523 					for (int i = 0; i < treeWalk.getTreeCount(); i++) {
524 						recordFileMode(path, treeWalk.getFileMode(i));
525 					}
526 				}
527 			}
528 		}
529 
530 		if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
531 			IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode;
532 			SubmoduleWalk smw = SubmoduleWalk.forIndex(repository);
533 			while (smw.next()) {
534 				try {
535 					if (localIgnoreSubmoduleMode == null)
536 						localIgnoreSubmoduleMode = smw.getModulesIgnore();
537 					if (IgnoreSubmoduleMode.ALL
538 							.equals(localIgnoreSubmoduleMode))
539 						continue;
540 				} catch (ConfigInvalidException e) {
541 					throw new IOException(MessageFormat.format(
542 							JGitText.get().invalidIgnoreParamSubmodule,
543 							smw.getPath()), e);
544 				}
545 				try (Repository subRepo = smw.getRepository()) {
546 					if (subRepo != null) {
547 						String subRepoPath = smw.getPath();
548 						ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$
549 						if (subHead != null
550 								&& !subHead.equals(smw.getObjectId())) {
551 							modified.add(subRepoPath);
552 							recordFileMode(subRepoPath, FileMode.GITLINK);
553 						} else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
554 							IndexDiff smid = submoduleIndexDiffs.get(smw
555 									.getPath());
556 							if (smid == null) {
557 								smid = new IndexDiff(subRepo,
558 										smw.getObjectId(),
559 										wTreeIt.getWorkingTreeIterator(subRepo));
560 								submoduleIndexDiffs.put(subRepoPath, smid);
561 							}
562 							if (smid.diff()) {
563 								if (ignoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED
564 										&& smid.getAdded().isEmpty()
565 										&& smid.getChanged().isEmpty()
566 										&& smid.getConflicting().isEmpty()
567 										&& smid.getMissing().isEmpty()
568 										&& smid.getModified().isEmpty()
569 										&& smid.getRemoved().isEmpty()) {
570 									continue;
571 								}
572 								modified.add(subRepoPath);
573 								recordFileMode(subRepoPath, FileMode.GITLINK);
574 							}
575 						}
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 	 * Get list of files added to the index, not in the tree
625 	 *
626 	 * @return list of files added to the index, not in the tree
627 	 */
628 	public Set<String> getAdded() {
629 		return added;
630 	}
631 
632 	/**
633 	 * Get list of files changed from tree to index
634 	 *
635 	 * @return list of files changed from tree to index
636 	 */
637 	public Set<String> getChanged() {
638 		return changed;
639 	}
640 
641 	/**
642 	 * Get list of files removed from index, but in tree
643 	 *
644 	 * @return list of files removed from index, but in tree
645 	 */
646 	public Set<String> getRemoved() {
647 		return removed;
648 	}
649 
650 	/**
651 	 * Get list of files in index, but not filesystem
652 	 *
653 	 * @return list of files in index, but not filesystem
654 	 */
655 	public Set<String> getMissing() {
656 		return missing;
657 	}
658 
659 	/**
660 	 * Get list of files modified on disk relative to the index
661 	 *
662 	 * @return list of files modified on disk relative to the index
663 	 */
664 	public Set<String> getModified() {
665 		return modified;
666 	}
667 
668 	/**
669 	 * Get list of files that are not ignored, and not in the index.
670 	 *
671 	 * @return list of files that are not ignored, and not in the index.
672 	 */
673 	public Set<String> getUntracked() {
674 		return untracked;
675 	}
676 
677 	/**
678 	 * Get list of files that are in conflict, corresponds to the keys of
679 	 * {@link #getConflictingStageStates()}
680 	 *
681 	 * @return list of files that are in conflict, corresponds to the keys of
682 	 *         {@link #getConflictingStageStates()}
683 	 */
684 	public Set<String> getConflicting() {
685 		return conflicts.keySet();
686 	}
687 
688 	/**
689 	 * Get the map from each path of {@link #getConflicting()} to its
690 	 * corresponding {@link org.eclipse.jgit.lib.IndexDiff.StageState}
691 	 *
692 	 * @return the map from each path of {@link #getConflicting()} to its
693 	 *         corresponding {@link org.eclipse.jgit.lib.IndexDiff.StageState}
694 	 * @since 3.0
695 	 */
696 	public Map<String, StageState> getConflictingStageStates() {
697 		return conflicts;
698 	}
699 
700 	/**
701 	 * The method returns the list of ignored files and folders. Only the root
702 	 * folder of an ignored folder hierarchy is reported. If a/b/c is listed in
703 	 * the .gitignore then you should not expect a/b/c/d/e/f to be reported
704 	 * here. Only a/b/c will be reported. Furthermore only ignored files /
705 	 * folders are returned that are NOT in the index.
706 	 *
707 	 * @return list of files / folders that are ignored
708 	 */
709 	public Set<String> getIgnoredNotInIndex() {
710 		return ignored;
711 	}
712 
713 	/**
714 	 * Get list of files with the flag assume-unchanged
715 	 *
716 	 * @return list of files with the flag assume-unchanged
717 	 */
718 	public Set<String> getAssumeUnchanged() {
719 		if (assumeUnchanged == null) {
720 			HashSet<String> unchanged = new HashSet<>();
721 			for (int i = 0; i < dirCache.getEntryCount(); i++)
722 				if (dirCache.getEntry(i).isAssumeValid())
723 					unchanged.add(dirCache.getEntry(i).getPathString());
724 			assumeUnchanged = unchanged;
725 		}
726 		return assumeUnchanged;
727 	}
728 
729 	/**
730 	 * Get list of folders containing only untracked files/folders
731 	 *
732 	 * @return list of folders containing only untracked files/folders
733 	 */
734 	public Set<String> getUntrackedFolders() {
735 		return ((indexDiffFilter == null) ? Collections.<String> emptySet()
736 				: new HashSet<>(indexDiffFilter.getUntrackedFolders()));
737 	}
738 
739 	/**
740 	 * Get the file mode of the given path in the index
741 	 *
742 	 * @param path a {@link java.lang.String} object.
743 	 * @return file mode
744 	 */
745 	public FileMode getIndexMode(String path) {
746 		final DirCacheEntry entry = dirCache.getEntry(path);
747 		return entry != null ? entry.getFileMode() : FileMode.MISSING;
748 	}
749 
750 	/**
751 	 * Get the list of paths that IndexDiff has detected to differ and have the
752 	 * given file mode
753 	 *
754 	 * @param mode a {@link org.eclipse.jgit.lib.FileMode} object.
755 	 * @return the list of paths that IndexDiff has detected to differ and have
756 	 *         the given file mode
757 	 * @since 3.6
758 	 */
759 	public Set<String> getPathsWithIndexMode(FileMode mode) {
760 		Set<String> paths = fileModes.get(mode);
761 		if (paths == null)
762 			paths = new HashSet<>();
763 		return paths;
764 	}
765 }