]> source.dussan.org Git - jgit.git/commitdiff
Add MutableObjectId.copyFrom(AnyObjectId) 22/922/2
authorShawn O. Pearce <spearce@spearce.org>
Tue, 22 Jun 2010 23:42:29 +0000 (16:42 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 23 Jun 2010 23:54:15 +0000 (16:54 -0700)
This simplifies the PackIndex code, which is trying to quickly copy
an existing ObjectId into a MutableObjectId.  Rather than having
the PackIndex violate the ObjectId's internals, expose a copy from
function similar to the other ones for copying from raw byte arrays
or hex formatted strings.

Change-Id: I142635cbece54af2ab83c58477961ce925dc8255
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/PackIndex.java

index 2e0e0118f034976cefc9d8e6bfc4e0555c2d8c67..26e83d423bae48ea5bf485de3135b425bd77ac44 100644 (file)
@@ -71,11 +71,7 @@ public class MutableObjectId extends AnyObjectId {
         *            original entry, to copy id from
         */
        MutableObjectId(MutableObjectId src) {
-               this.w1 = src.w1;
-               this.w2 = src.w2;
-               this.w3 = src.w3;
-               this.w4 = src.w4;
-               this.w5 = src.w5;
+               fromObjectId(src);
        }
 
        /** Make this id match {@link ObjectId#zeroId()}. */
@@ -87,6 +83,20 @@ public class MutableObjectId extends AnyObjectId {
                w5 = 0;
        }
 
+       /**
+        * Copy an ObjectId into this mutable buffer.
+        *
+        * @param src
+        *            the source id to copy from.
+        */
+       public void fromObjectId(AnyObjectId src) {
+               this.w1 = src.w1;
+               this.w2 = src.w2;
+               this.w3 = src.w3;
+               this.w4 = src.w4;
+               this.w5 = src.w5;
+       }
+
        /**
         * Convert an ObjectId from raw binary representation.
         *
index 25b4f569c1fdf53508b03a03e545b06654106c50..13985e78e949dfa1aec1dbd51a87bee7f4780388 100644 (file)
@@ -281,11 +281,7 @@ public abstract class PackIndex implements Iterable<PackIndex.MutableEntry> {
                public MutableEntry cloneEntry() {
                        final MutableEntry r = new MutableEntry();
                        ensureId();
-                       r.idBuffer.w1 = idBuffer.w1;
-                       r.idBuffer.w2 = idBuffer.w2;
-                       r.idBuffer.w3 = idBuffer.w3;
-                       r.idBuffer.w4 = idBuffer.w4;
-                       r.idBuffer.w5 = idBuffer.w5;
+                       r.idBuffer.fromObjectId(idBuffer);
                        r.offset = offset;
                        return r;
                }