]> source.dussan.org Git - jgit.git/commitdiff
Refactor and comment complicated if statements 42/2342/1
authorChristian Halstrick <christian.halstrick@sap.com>
Wed, 12 Jan 2011 13:25:30 +0000 (14:25 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Wed, 26 Jan 2011 16:17:45 +0000 (17:17 +0100)
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>
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

index 25209d982b3fb4a733c7bcc91c62809d9b889a40..da7ea2c9cc0ed91ee4d18fadae705f7ff77820b1 100644 (file)
@@ -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());
+                       }
                }
        }