From: "Daniel Cheng (aka SDiZ)" <j16sdiz+freenet@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org,
"Daniel Cheng (aka SDiZ)" <j16sdiz+freenet@gmail.com>
Subject: [PATCH JGIT 1/2] Calculate CRC32 on Pack Index v2
Date: Wed, 25 Mar 2009 14:21:54 +0800 [thread overview]
Message-ID: <1237962115-22709-1-git-send-email-j16sdiz+freenet@gmail.com> (raw)
In-Reply-To: <ff6a9c820903231953q29a5ccbk8e5b54c9afdb8abd@mail.gmail.com>
Signed-off-by: Daniel Cheng (aka SDiZ) <j16sdiz+freenet@gmail.com>
---
.../src/org/spearce/jgit/lib/PackWriter.java | 2 +
.../spearce/jgit/util/CountingOutputStream.java | 32 +++++++++++++++++++-
2 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
index 601ce71..d8b50e6 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackWriter.java
@@ -687,11 +687,13 @@ public class PackWriter {
assert !otp.isWritten();
+ countingOut.resetCRC32();
otp.setOffset(countingOut.getCount());
if (otp.isDeltaRepresentation())
writeDeltaObject(otp);
else
writeWholeObject(otp);
+ otp.setCRC((int) countingOut.getCRC32());
writeMonitor.update(1);
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/CountingOutputStream.java b/org.spearce.jgit/src/org/spearce/jgit/util/CountingOutputStream.java
index b0b5f7d..b4ae915 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/CountingOutputStream.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/CountingOutputStream.java
@@ -40,12 +40,16 @@ package org.spearce.jgit.util;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.zip.CRC32;
/**
- * Counting output stream decoration. Counts bytes written to stream.
+ * Counting output stream decoration. Counts bytes written to stream and
+ * calculate CRC32 checksum.
*/
public class CountingOutputStream extends FilterOutputStream {
private long count;
+
+ private CRC32 crc;
/**
* Create counting stream being decorated to provided real output stream.
@@ -55,6 +59,7 @@ public class CountingOutputStream extends FilterOutputStream {
*/
public CountingOutputStream(OutputStream out) {
super(out);
+ crc = new CRC32();
}
@Override
@@ -79,10 +84,35 @@ public class CountingOutputStream extends FilterOutputStream {
return count;
}
+ /**
+ * Resets CRC-32 to initial value.
+ */
+ public void resetCRC32() {
+ crc.reset();
+ }
+
+ /**
+ * Returns CRC-32 value.
+ * @return CRC32
+ */
+ public long getCRC32() {
+ return crc.getValue();
+ }
+
+
/**
* Reset counter to zero value.
*/
public void reset() {
count = 0;
+ crc.reset();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ crc = null;
+ super.close();
}
}
--
1.6.2
next prev parent reply other threads:[~2009-03-25 6:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 2:53 [JGit] Mismatch CRC in packed objects from `jgit push` Daniel Cheng
2009-03-24 11:13 ` [JGIT Test Case] This (incomplete) test case demo the index wrong CRC bug Daniel Cheng (aka SDiZ)
2009-03-25 6:21 ` Daniel Cheng (aka SDiZ) [this message]
2009-03-25 6:21 ` [PATCH JGIT 2/2] Test case for pack index CRC Daniel Cheng (aka SDiZ)
2009-03-25 13:31 ` [PATCH JGIT 1/2] Calculate CRC32 on Pack Index v2 Marek Zawirski
2009-03-25 21:59 ` Shawn O. Pearce
2009-03-26 0:49 ` Daniel Cheng
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=1237962115-22709-1-git-send-email-j16sdiz+freenet@gmail.com \
--to=j16sdiz+freenet@gmail.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.