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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <spearce@xxxxxxxxxxx>
---
 .../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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux