Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

IndexDiff.java 20KB

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