Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2012-09-22 23:37:09 +0000
committerChris Aniszczyk2012-11-16 18:12:40 +0000
commita2e691351f4c5217a908410c1bd796efa6b01023 (patch)
treefa94d37a1bbbacf4b9048b344c4589f10cd840ef
parent05a7113002063b80cf48591594c7e01cd2111ec6 (diff)
downloadjgit-a2e691351f4c5217a908410c1bd796efa6b01023.tar.gz
jgit-a2e691351f4c5217a908410c1bd796efa6b01023.tar.xz
jgit-a2e691351f4c5217a908410c1bd796efa6b01023.zip
DirCacheEditor: Apply PathEdit for each stage
This behavior was defined in the Javadoc of PathEdit, but not actually implemented. It's necessary when one wants to use a PathEdit to check out a specific stage in apply. Bug: 390147 Change-Id: Iaed5cf60c554fc17e6c4d188caf4f0231da920d0 Signed-off-by: Chris Aniszczyk <zx@twitter.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java43
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java13
2 files changed, 51 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
index 4a6a42b6d2..28140f330e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
@@ -44,6 +44,9 @@ package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
@@ -66,6 +69,19 @@ public class DirCachePathEditTest {
}
+ private static final class RecordingEdit extends PathEdit {
+ final List<DirCacheEntry> entries = new ArrayList<DirCacheEntry>();
+
+ public RecordingEdit(String entryPath) {
+ super(entryPath);
+ }
+
+ @Override
+ public void apply(DirCacheEntry ent) {
+ entries.add(ent);
+ }
+ }
+
@Test
public void testAddDeletePathAndTreeNormalNames() {
DirCache dc = DirCache.newInCore();
@@ -114,4 +130,31 @@ public class DirCachePathEditTest {
assertEquals("a.", dc.getEntry(0).getPathString());
assertEquals("ab", dc.getEntry(1).getPathString());
}
+
+ @Test
+ public void testPathEditShouldBeCalledForEachStage() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheBuilder builder = new DirCacheBuilder(dc, 3);
+ builder.add(createEntry("a", DirCacheEntry.STAGE_1));
+ builder.add(createEntry("a", DirCacheEntry.STAGE_2));
+ builder.add(createEntry("a", DirCacheEntry.STAGE_3));
+ builder.finish();
+
+ DirCacheEditor editor = dc.editor();
+ RecordingEdit recorder = new RecordingEdit("a");
+ editor.add(recorder);
+ editor.finish();
+
+ List<DirCacheEntry> entries = recorder.entries;
+ assertEquals(3, entries.size());
+ assertEquals(DirCacheEntry.STAGE_1, entries.get(0).getStage());
+ assertEquals(DirCacheEntry.STAGE_2, entries.get(1).getStage());
+ assertEquals(DirCacheEntry.STAGE_3, entries.get(2).getStage());
+ }
+
+ private static DirCacheEntry createEntry(String path, int stage) {
+ DirCacheEntry entry = new DirCacheEntry(path, stage);
+ entry.setFileMode(FileMode.REGULAR_FILE);
+ return entry;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java
index 6c12c402b6..b0cb34c352 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java
@@ -146,18 +146,21 @@ public class DirCacheEditor extends BaseDirCacheEditor {
continue;
}
- final DirCacheEntry ent;
if (missing) {
- ent = new DirCacheEntry(e.path);
+ final DirCacheEntry ent = new DirCacheEntry(e.path);
e.apply(ent);
if (ent.getRawMode() == 0)
throw new IllegalArgumentException(MessageFormat.format(JGitText.get().fileModeNotSetForPath
, ent.getPathString()));
+ fastAdd(ent);
} else {
- ent = cache.getEntry(eIdx);
- e.apply(ent);
+ // Apply to all entries of the current path (different stages)
+ for (int i = eIdx; i < lastIdx; i++) {
+ final DirCacheEntry ent = cache.getEntry(i);
+ e.apply(ent);
+ fastAdd(ent);
+ }
}
- fastAdd(ent);
}
final int cnt = maxIdx - lastIdx;

Back to the top