From e6c39227640536ac1c2e41d8970aeca84b3c6268 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 7 Dec 2010 18:53:09 -0800 Subject: [PATCH] IndexDiff: Fix getAssumeUnchanged() If the caller really needs the list of files that are flagged as assume-unchanged (aka assume-valid in the DirCache), we should give them the complete list and not just those that we wrongly identified as being modified during diff(). This change is necessary because diff() is slightly broken and is discovering differences on files that it shouldn't have considered. Change-Id: Ibe464c1a0e51c19dc287a4bc5348b7b07f4d840b Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/lib/IndexDiff.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java index 6b2af0763..52fc3db79 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java @@ -105,7 +105,9 @@ public class IndexDiff { private Set untracked = new HashSet(); - private Set assumeUnchanged = new HashSet(); + private Set assumeUnchanged; + + private DirCache dirCache; /** * Construct an IndexDiff @@ -167,7 +169,8 @@ public void setFilter(TreeFilter filter) { */ public boolean diff() throws IOException { boolean changesExist = false; - DirCache dirCache = repository.readDirCache(); + dirCache = repository.readDirCache(); + TreeWalk treeWalk = new TreeWalk(repository); treeWalk.setRecursive(true); // add the trees (tree, dirchache, workdir) @@ -192,11 +195,6 @@ public boolean diff() throws IOException { WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR, WorkingTreeIterator.class); - if (dirCacheIterator != null) { - if (dirCacheIterator.getDirCacheEntry().isAssumeValid()) - assumeUnchanged.add(treeWalk.getPathString()); - } - if (treeIterator != null) { if (dirCacheIterator != null) { if (!treeIterator.getEntryObjectId().equals( @@ -290,6 +288,13 @@ public Set getUntracked() { * @return list of files with the flag assume-unchanged */ public Set getAssumeUnchanged() { + if (assumeUnchanged == null) { + HashSet unchanged = new HashSet(); + for (int i = 0; i < dirCache.getEntryCount(); i++) + if (dirCache.getEntry(i).isAssumeValid()) + unchanged.add(dirCache.getEntry(i).getPathString()); + assumeUnchanged = unchanged; + } return assumeUnchanged; } }