]> source.dussan.org Git - jgit.git/commitdiff
Include list of assume unchanged files in IndexDiff 68/1968/4
authorStefan Lay <stefan.lay@sap.com>
Tue, 30 Nov 2010 10:33:54 +0000 (11:33 +0100)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 30 Nov 2010 18:51:21 +0000 (10:51 -0800)
The IndexDiff had not collected the info if the flag
"assume-unchanged" is set. This information is useful for clients
which may want to decide if specific actions are allowed on a file.

Bug: 326213
Change-Id: I14bb7b03247d6c0b429a9d8d3f6b10f21d8ddeb1
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

index c73764a990140f92534009f5a40382c0037759ce..0ce85b4be0e5067e53705c7445bee797187738cb 100644 (file)
@@ -51,6 +51,7 @@ import java.io.IOException;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.dircache.DirCache;
 import org.eclipse.jgit.dircache.DirCacheEditor;
+import org.eclipse.jgit.dircache.DirCacheEntry;
 import org.eclipse.jgit.treewalk.FileTreeIterator;
 
 public class IndexDiffTest extends RepositoryTestCase {
@@ -234,6 +235,39 @@ public class IndexDiffTest extends RepositoryTestCase {
                assertTrue(diff.getUntracked().contains(path));
        }
 
+       public void testAssumeUnchanged() throws Exception {
+               Git git = new Git(db);
+               String path = "file";
+               writeTrashFile(path, "content");
+               git.add().addFilepattern(path).call();
+               String path2 = "file2";
+               writeTrashFile(path2, "content");
+               git.add().addFilepattern(path2).call();
+               git.commit().setMessage("commit").call();
+               assumeUnchanged(path2);
+               writeTrashFile(path, "more content");
+               writeTrashFile(path2, "more content");
+
+               FileTreeIterator iterator = new FileTreeIterator(db);
+               IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
+               diff.diff();
+               assertEquals(1, diff.getAssumeUnchanged().size());
+               assertEquals(2, diff.getModified().size());
+               assertEquals(0, diff.getChanged().size());
+
+               git.add().addFilepattern(".").call();
+
+               iterator = new FileTreeIterator(db);
+               diff = new IndexDiff(db, Constants.HEAD, iterator);
+               diff.diff();
+               assertEquals(1, diff.getAssumeUnchanged().size());
+               assertEquals(1, diff.getModified().size());
+               assertEquals(1, diff.getChanged().size());
+               assertTrue(diff.getAssumeUnchanged().contains("file2"));
+               assertTrue(diff.getModified().contains("file2"));
+               assertTrue(diff.getChanged().contains("file"));
+       }
+
        private void removeFromIndex(String path) throws IOException {
                final DirCache dirc = db.lockDirCache();
                final DirCacheEditor edit = dirc.editor();
@@ -241,4 +275,15 @@ public class IndexDiffTest extends RepositoryTestCase {
                if (!edit.commit())
                        throw new IOException("could not commit");
        }
+
+       private void assumeUnchanged(String path) throws IOException {
+               final DirCache dirc = db.lockDirCache();
+               final DirCacheEntry ent = dirc.getEntry(path);
+               if (ent != null)
+                       ent.setAssumeValid(true);
+               dirc.write();
+               if (!dirc.commit())
+                       throw new IOException("could not commit");
+       }
+
 }
index b19e7782596f0659eb231c7f481b445ca2a4e7df..b9291f11ddb5d61d1e19e7ca808db3e096a6038c 100644 (file)
@@ -65,15 +65,17 @@ import org.eclipse.jgit.treewalk.filter.SkipWorkTreeFilter;
 import org.eclipse.jgit.treewalk.filter.TreeFilter;
 
 /**
- * Compares the index, a tree, and the working directory
- * Ignored files are not taken into account.
- * The following information is retrieved:
- * <li> added files
- * <li> changed files
- * <li> removed files
- * <li> missing files
- * <li> modified files
- * <li> untracked files
+ * Compares the index, a tree, and the working directory Ignored files are not
+ * taken into account. The following information is retrieved:
+ * <ul>
+ * <li>added files</li>
+ * <li>changed files</li>
+ * <li>removed files</li>
+ * <li>missing files</li>
+ * <li>modified files</li>
+ * <li>untracked files</li>
+ * <li>files with assume-unchanged flag</li>
+ * </ul>
  */
 public class IndexDiff {
 
@@ -103,6 +105,8 @@ public class IndexDiff {
 
        private Set<String> untracked = new HashSet<String>();
 
+       private Set<String> assumeUnchanged = new HashSet<String>();
+
        /**
         * Construct an IndexDiff
         *
@@ -191,6 +195,11 @@ public class IndexDiff {
                                        WorkingTreeIterator.class);
                        FileMode fileModeTree = treeWalk.getFileMode(TREE);
 
+                       if (dirCacheIterator != null) {
+                               if (dirCacheIterator.getDirCacheEntry().isAssumeValid())
+                                       assumeUnchanged.add(dirCacheIterator.getEntryPathString());
+                       }
+
                        if (treeIterator != null) {
                                if (dirCacheIterator != null) {
                                        if (!treeIterator.getEntryObjectId().equals(
@@ -283,4 +292,10 @@ public class IndexDiff {
                return untracked;
        }
 
+       /**
+        * @return list of files with the flag assume-unchanged
+        */
+       public Set<String> getAssumeUnchanged() {
+               return assumeUnchanged;
+       }
 }