From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 2/5] Fix UnpackedObjectLoader.getBytes to return a copy
Date: Tue, 30 Sep 2008 18:31:27 -0700 [thread overview]
Message-ID: <1222824690-7632-3-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1222824690-7632-2-git-send-email-spearce@spearce.org>
The contract for ObjectLoader.getBytes() says the caller can modify
the returned array. UnpackedObjectLoader must copy the data and not
return its internal cached byte array.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/lib/ObjectLoader.java | 7 ++++++-
.../org/spearce/jgit/lib/PackedObjectLoader.java | 7 -------
.../org/spearce/jgit/lib/UnpackedObjectLoader.java | 4 ----
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java
index 5282491..87e861f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectLoader.java
@@ -105,7 +105,12 @@ protected void setId(final ObjectId id) {
* @throws IOException
* the object cannot be read.
*/
- public abstract byte[] getBytes() throws IOException;
+ public final byte[] getBytes() throws IOException {
+ final byte[] data = getCachedBytes();
+ final byte[] copy = new byte[data.length];
+ System.arraycopy(data, 0, copy, 0, data.length);
+ return data;
+ }
/**
* Obtain a reference to the (possibly cached) bytes of this object.
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java
index fa414d6..35983fe 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackedObjectLoader.java
@@ -80,13 +80,6 @@ public long getDataOffset() {
return dataOffset;
}
- public final byte[] getBytes() throws IOException {
- final byte[] data = getCachedBytes();
- final byte[] copy = new byte[data.length];
- System.arraycopy(data, 0, copy, 0, data.length);
- return data;
- }
-
/**
* Copy raw object representation from storage to provided output stream.
* <p>
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java
index 3c61254..3ad273f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java
@@ -200,10 +200,6 @@ public long getSize() {
return objectSize;
}
- public byte[] getBytes() {
- return bytes;
- }
-
@Override
public byte[] getCachedBytes() throws IOException {
return bytes;
--
1.6.0.2.569.g798a2a
next prev parent reply other threads:[~2008-10-01 1:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-01 1:31 [JGIT PATCH 0/5] Support receive.fsckobjects Shawn O. Pearce
2008-10-01 1:31 ` [JGIT PATCH 1/5] Expose RawParseUtils.match to application callers Shawn O. Pearce
2008-10-01 1:31 ` Shawn O. Pearce [this message]
2008-10-01 1:31 ` [JGIT PATCH 3/5] Object validation tests for "jgit fsck" Shawn O. Pearce
2008-10-01 1:31 ` [JGIT PATCH 4/5] Expose the critical receive configuration options to JGit Shawn O. Pearce
2008-10-01 1:31 ` [JGIT PATCH 5/5] Honor receive.fsckobjects during any fetch connection Shawn O. Pearce
2008-10-01 20:54 ` [JGIT PATCH 4/5] Expose the critical receive configuration options to JGit Robin Rosenberg
2008-10-02 22:46 ` Shawn O. Pearce
2008-10-09 21:46 ` [JGIT PATCH 2/5] Fix UnpackedObjectLoader.getBytes to return a copy Jonas Fonseca
2008-10-09 21:49 ` Shawn O. Pearce
2008-10-09 22:09 ` [JGIT PATCH] Fix ObjectLoader.getBytes to really return the created copy Jonas Fonseca
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1222824690-7632-3-git-send-email-spearce@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).