From 95ed300b04f52e6d0625dfb5a6e0e52aac4bc412 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 14 Apr 2012 00:40:06 +0200 Subject: Enable DirCacheEntry's copyMetaData to not copy stage info When there is a conflict sometimes we did not set the stage of the conflict entries properly for the STAGE_1 entry. Change-Id: I1c28ff6251fdbc95f7c40fc3e401f1b41157a9f6 --- .../eclipse/jgit/dircache/DirCacheCheckout.java | 2 +- .../org/eclipse/jgit/dircache/DirCacheEntry.java | 29 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'org.eclipse.jgit') 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 fa29042312..859f611737 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -795,7 +795,7 @@ public class DirCacheCheckout { DirCacheEntry entry; if (e != null) { entry = new DirCacheEntry(e.getPathString(), DirCacheEntry.STAGE_1); - entry.copyMetaData(e); + entry.copyMetaData(e, true); builder.add(entry); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java index 71d9c4bdf9..85df340d37 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -641,10 +641,33 @@ public class DirCacheEntry { * the entry to copy ObjectId and meta fields from. */ public void copyMetaData(final DirCacheEntry src) { - final int pLen = NB.decodeUInt16(info, infoOffset + P_FLAGS) & NAME_MASK; + copyMetaData(src, false); + } + + /** + * Copy the ObjectId and other meta fields from an existing entry. + *

+ * This method copies everything except the path and possibly stage from one + * entry to another, supporting renaming. + * + * @param src + * the entry to copy ObjectId and meta fields from. + * @param keepStage + * if true, the stage attribute will not be copied + */ + void copyMetaData(final DirCacheEntry src, boolean keepStage) { + int origflags = NB.decodeUInt16(info, infoOffset + P_FLAGS); + int newflags = NB.decodeUInt16(src.info, src.infoOffset + P_FLAGS); System.arraycopy(src.info, src.infoOffset, info, infoOffset, INFO_LEN); - NB.encodeInt16(info, infoOffset + P_FLAGS, pLen - | NB.decodeUInt16(info, infoOffset + P_FLAGS) & ~NAME_MASK); + final int pLen = origflags & NAME_MASK; + final int SHIFTED_STAGE_MASK = 0x3 << 12; + final int pStageShifted; + if (keepStage) + pStageShifted = origflags & SHIFTED_STAGE_MASK; + else + pStageShifted = newflags & SHIFTED_STAGE_MASK; + NB.encodeInt16(info, infoOffset + P_FLAGS, pStageShifted | pLen + | (newflags & ~NAME_MASK & ~SHIFTED_STAGE_MASK)); } /** -- cgit v1.2.3