From 1f800e062f6149b439339b0fa5c0bd94f9fa321f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 22 Jan 2009 15:28:08 -0800 Subject: [PATCH] Allow DirCacheEntry instances to be created with stage > 0 As the stage is part of the sorting criteria for DirCacheEntry objects we don't allow the stage to be modified on the fly in an existing instance. Instead the stage must be set by reading it from the on-disk format or by creating a new entry with the proper path and stage components. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../org/spearce/jgit/dircache/DirCacheEntry.java | 48 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java index 024fffc8..6d46648e 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java +++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java @@ -60,6 +60,18 @@ import org.spearce.jgit.util.NB; public class DirCacheEntry { private static final byte[] nullpad = new byte[8]; + /** The standard (fully merged) stage for an entry. */ + public static final int STAGE_0 = 0; + + /** The base tree revision for an entry. */ + public static final int STAGE_1 = 1; + + /** The first tree revision (usually called "ours"). */ + public static final int STAGE_2 = 2; + + /** The second tree revision (usually called "theirs"). */ + public static final int STAGE_3 = 3; + // private static final int P_CTIME = 0; // private static final int P_CTIME_NSEC = 4; @@ -141,7 +153,7 @@ public class DirCacheEntry { } /** - * Create an empty entry. + * Create an empty entry at stage 0. * * @param newPath * name of the cache entry. @@ -151,20 +163,46 @@ public class DirCacheEntry { } /** - * Create an empty entry. + * Create an empty entry at the specified stage. + * + * @param newPath + * name of the cache entry. + * @param stage + * the stage index of the new entry. + */ + public DirCacheEntry(final String newPath, final int stage) { + this(Constants.encode(newPath), stage); + } + + /** + * Create an empty entry at stage 0. * * @param newPath * name of the cache entry, in the standard encoding. */ public DirCacheEntry(final byte[] newPath) { + this(newPath, STAGE_0); + } + + /** + * Create an empty entry at the specified stage. + * + * @param newPath + * name of the cache entry, in the standard encoding. + * @param stage + * the stage index of the new entry. + */ + public DirCacheEntry(final byte[] newPath, final int stage) { info = new byte[INFO_LEN]; infoOffset = 0; - path = newPath; + + int flags = ((stage & 0x3) << 12); if (path.length < NAME_MASK) - NB.encodeInt16(info, infoOffset + P_FLAGS, path.length); + flags |= path.length; else - NB.encodeInt16(info, infoOffset + P_FLAGS, NAME_MASK); + flags |= NAME_MASK; + NB.encodeInt16(info, infoOffset + P_FLAGS, flags); } void write(final OutputStream os) throws IOException { -- 2.11.4.GIT