You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IndexDiff.java 21KB

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