diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2011-01-12 14:25:30 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2011-01-26 17:17:45 +0100 |
commit | 4cba86bfeaaadbac2d13aa8176965feb424d748c (patch) | |
tree | 423842197fec8049267bc72bb03e1154f79327ff | |
parent | 85f69c286b6c3225dcff05aba42910daefb28da0 (diff) | |
download | jgit-4cba86bfeaaadbac2d13aa8176965feb424d748c.tar.gz jgit-4cba86bfeaaadbac2d13aa8176965feb424d748c.zip |
Refactor and comment complicated if statements
When debugging and enhancing DirCacheCheckout.processEntry() I found
that some of if-statements where hard to read/understand. This
change just splits some long if statements and adds more comments
explaining in which state we are. This change is only a preparation
for followup commits which introduce checks for untracked+ignored
files.
Change-Id: I670ff08310b72c858709b9e395f0aebb4b290a56
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index 25209d982b..da7ea2c9cc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -304,29 +304,56 @@ public class DirCacheCheckout { void processEntry(CanonicalTreeParser m, DirCacheBuildIterator i, WorkingTreeIterator f) { if (m != null) { - if (i == null || f == null || !m.idEqual(i) - || (i.getDirCacheEntry() != null && (f.isModified( - i.getDirCacheEntry(), true) || - i.getDirCacheEntry().getStage() != 0))) { + // There is an entry in the merge commit. Means: we want to update + // what's currently in the index and working-tree to that one + if (i == null) { + // The index entry is missing update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); + } else if (f == null || !m.idEqual(i)) { + // The working tree file is missing or the merge content differs + // from index content + update(m.getEntryPathString(), m.getEntryObjectId(), + m.getEntryFileMode()); + } else if (i.getDirCacheEntry() != null) { + // The index contains a file (and not a folder) + if (f.isModified(i.getDirCacheEntry(), true) + || i.getDirCacheEntry().getStage() != 0) + // The working tree file is dirty or the index contains a + // conflict + update(m.getEntryPathString(), m.getEntryObjectId(), + m.getEntryFileMode()); + else + keep(i.getDirCacheEntry()); } else + // The index contains a folder keep(i.getDirCacheEntry()); } else { + // There is no entry in the merge commit. Means: we want to delete + // what's currently in the index and working tree if (f != null) { + // There is a file/folder for that path in the working tree if (walk.isDirectoryFileConflict()) { conflicts.add(walk.getPathString()); } else { + // No file/folder conflict exists. All entries are files or + // all entries are folders if (i != null) { - // ... and the working dir contained a file or folder -> - // add it to the removed set and remove it from + // ... and the working tree contained a file or folder + // -> add it to the removed set and remove it from // conflicts set remove(i.getEntryPathString()); conflicts.remove(i.getEntryPathString()); } } - } else if (i.getDirCacheEntry().getStage() == 0) - keep(i.getDirCacheEntry()); + } else { + // There is no file/folder for that path in the working tree. + // The only entry we have is the index entry. If that entry is a + // conflict simply remove it. Otherwise keep that entry in the + // index + if (i.getDirCacheEntry().getStage() == 0) + keep(i.getDirCacheEntry()); + } } } |