summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2012-06-06 06:43:20 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2012-06-06 06:43:20 -0400
commit87c558885349b8ce6f3660729a74e92fe0ff210e (patch)
tree24249eb79c0025c4dc419e6208b02b3f6101a796 /org.eclipse.jgit
parent794f42f0acf70293d9a872a02c6337fde2af6e3a (diff)
parent59a98b49d2bf1e4514967dfa0acbceea6b37dbd4 (diff)
downloadjgit-87c558885349b8ce6f3660729a74e92fe0ff210e.tar.gz
jgit-87c558885349b8ce6f3660729a74e92fe0ff210e.zip
Merge "Use working tree iterator to compare file modes" into stable-2.0
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java19
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java46
2 files changed, 41 insertions, 24 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index 261aa9f0a8..2c1aa6fbf7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
@@ -399,7 +399,7 @@ public class ResolveMerger extends ThreeWayMerger {
else {
// the preferred version THEIRS has a different mode
// than ours. Check it out!
- if (isWorktreeDirty())
+ if (isWorktreeDirty(work))
return false;
DirCacheEntry e = add(tw.getRawPath(), theirs,
DirCacheEntry.STAGE_0);
@@ -434,7 +434,7 @@ public class ResolveMerger extends ThreeWayMerger {
// THEIRS. THEIRS is chosen.
// Check worktree before checking out THEIRS
- if (isWorktreeDirty())
+ if (isWorktreeDirty(work))
return false;
if (nonTree(modeT)) {
DirCacheEntry e = add(tw.getRawPath(), theirs,
@@ -485,7 +485,7 @@ public class ResolveMerger extends ThreeWayMerger {
if (nonTree(modeO) && nonTree(modeT)) {
// Check worktree before modifying files
- if (isWorktreeDirty())
+ if (isWorktreeDirty(work))
return false;
MergeResult<RawText> result = contentMerge(base, ours, theirs);
@@ -507,7 +507,7 @@ public class ResolveMerger extends ThreeWayMerger {
// OURS was deleted checkout THEIRS
if (modeO == 0) {
// Check worktree before checking out THEIRS
- if (isWorktreeDirty())
+ if (isWorktreeDirty(work))
return false;
if (nonTree(modeT)) {
if (e != null)
@@ -563,7 +563,7 @@ public class ResolveMerger extends ThreeWayMerger {
return isDirty;
}
- private boolean isWorktreeDirty() {
+ private boolean isWorktreeDirty(WorkingTreeIterator work) {
if (inCore)
return false;
@@ -571,8 +571,13 @@ public class ResolveMerger extends ThreeWayMerger {
final int modeO = tw.getRawMode(T_OURS);
// Worktree entry has to match ours to be considered clean
- final boolean isDirty = nonTree(modeF)
- && !(modeO == modeF && tw.idEqual(T_FILE, T_OURS));
+ final boolean isDirty;
+ if (nonTree(modeF))
+ isDirty = work.isModeDifferent(modeO)
+ || !tw.idEqual(T_FILE, T_OURS);
+ else
+ isDirty = false;
+
if (isDirty)
failingPaths.put(tw.getPathString(),
MergeFailureReason.DIRTY_WORKTREE);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index 759613ba27..ebe9f73fbd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -696,6 +696,33 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
}
/**
+ * Is the file mode of the current entry different than the given raw mode?
+ *
+ * @param rawMode
+ * @return true if different, false otherwise
+ */
+ public boolean isModeDifferent(final int rawMode) {
+ // Determine difference in mode-bits of file and index-entry. In the
+ // bitwise presentation of modeDiff we'll have a '1' when the two modes
+ // differ at this position.
+ int modeDiff = getEntryRawMode() ^ rawMode;
+
+ if (modeDiff == 0)
+ return false;
+
+ // Do not rely on filemode differences in case of symbolic links
+ if (FileMode.SYMLINK.equals(rawMode))
+ return false;
+
+ // Ignore the executable file bits if WorkingTreeOptions tell me to
+ // do so. Ignoring is done by setting the bits representing a
+ // EXECUTABLE_FILE to '0' in modeDiff
+ if (!state.options.isFileMode())
+ modeDiff &= ~FileMode.EXECUTABLE_FILE.getBits();
+ return modeDiff != 0;
+ }
+
+ /**
* Compare the metadata (mode, length, modification-timestamp) of the
* current entry and a {@link DirCacheEntry}
*
@@ -714,23 +741,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
if (!entry.isSmudged() && entry.getLength() != (int) getEntryLength())
return MetadataDiff.DIFFER_BY_METADATA;
- // Determine difference in mode-bits of file and index-entry. In the
- // bitwise presentation of modeDiff we'll have a '1' when the two modes
- // differ at this position.
- int modeDiff = getEntryRawMode() ^ entry.getRawMode();
-
- // Do not rely on filemode differences in case of symbolic links
- if (modeDiff != 0 && !FileMode.SYMLINK.equals(entry.getRawMode())) {
- // Ignore the executable file bits if WorkingTreeOptions tell me to
- // do so. Ignoring is done by setting the bits representing a
- // EXECUTABLE_FILE to '0' in modeDiff
- if (!state.options.isFileMode())
- modeDiff &= ~FileMode.EXECUTABLE_FILE.getBits();
- if (modeDiff != 0)
- // Report a modification if the modes still (after potentially
- // ignoring EXECUTABLE_FILE bits) differ
- return MetadataDiff.DIFFER_BY_METADATA;
- }
+ if (isModeDifferent(entry.getRawMode()))
+ return MetadataDiff.DIFFER_BY_METADATA;
// Git under windows only stores seconds so we round the timestamp
// Java gives us if it looks like the timestamp in index is seconds