Thread (19 messages) flat view 19 messages, 1 author, 2016-06-15
DORMANTno replies

[EGIT PATCH 17/26] Support copying meta fields from one DirCacheEntry to another

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:45:08
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 .../org/spearce/jgit/dircache/DirCacheEntry.java   |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 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 eba2678..2b5ce03 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.
+	 * <p>
+	 * 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);
-- 
1.6.0.rc2.22.g71b99
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help