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 19KB

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