From 4f6c1a1b83a65e96400bdc11ac57f64fae943d24 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 11 Aug 2008 18:08:04 -0700 Subject: [PATCH] Support copying meta fields from one DirCacheEntry to another When an application moves a DirCacheEntry record from one path to another path in the index we need to recreate the entry object and also copy the meta fields from the old entry to the new entry. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/dircache/DirCacheEntry.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 10aafe57..c481e43e 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java +++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java @@ -354,6 +354,22 @@ public class DirCacheEntry { return Constants.CHARSET.decode(ByteBuffer.wrap(path)).toString(); } + /** + * Copy the ObjectId and other meta fields from an existing entry. + *

+ * This method copies everything except the path from one entry to another, + * supporting renaming. + * + * @param src + * the entry to copy ObjectId and meta fields from. + */ + public void copyMetaData(final DirCacheEntry src) { + final int pLen = NB.decodeUInt16(info, infoOffset + P_FLAGS) & 0xfff; + System.arraycopy(src.info, src.infoOffset, info, infoOffset, INFO_LEN); + NB.encodeInt16(info, infoOffset + P_FLAGS, pLen + | NB.decodeUInt16(info, infoOffset + P_FLAGS) & ~0xfff); + } + private long decodeTS(final int pIdx) { final int base = infoOffset + pIdx; final int sec = NB.decodeInt32(info, base); -- 2.11.4.GIT