Browse Source

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>
stable-0.11
Christian Halstrick 14 years ago
parent
commit
4cba86bfea
  1. 43
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

43
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java vendored

@ -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());
}
}
}

Loading…
Cancel
Save