From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Thomas Rast" <trast@inf.ethz.ch>,
"Joshua Redstone" <joshua.redstone@fb.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/6] csum-file: make sha1 calculation optional
Date: Mon, 6 Feb 2012 12:48:35 +0700 [thread overview]
Message-ID: <1328507319-24687-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1328507319-24687-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
csum-file.c | 16 +++++++++++++---
csum-file.h | 2 +-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/csum-file.c b/csum-file.c
index 53f5375..4c517d1 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -11,6 +11,12 @@
#include "progress.h"
#include "csum-file.h"
+static void sha1update(struct sha1file *f, const void *data, unsigned offset)
+{
+ if (f->do_sha1)
+ git_SHA1_Update(&f->ctx, data, offset);
+}
+
static void flush(struct sha1file *f, void *buf, unsigned int count)
{
if (0 <= f->check_fd && count) {
@@ -47,7 +53,7 @@ void sha1flush(struct sha1file *f)
unsigned offset = f->offset;
if (offset) {
- git_SHA1_Update(&f->ctx, f->buffer, offset);
+ sha1update(f, f->buffer, offset);
flush(f, f->buffer, offset);
f->offset = 0;
}
@@ -58,7 +64,10 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
int fd;
sha1flush(f);
- git_SHA1_Final(f->buffer, &f->ctx);
+ if (f->do_sha1)
+ git_SHA1_Final(f->buffer, &f->ctx);
+ else
+ hashclr(f->buffer);
if (result)
hashcpy(result, f->buffer);
if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
@@ -110,7 +119,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
buf = (char *) buf + nr;
left -= nr;
if (!left) {
- git_SHA1_Update(&f->ctx, data, offset);
+ sha1update(f, data, offset);
flush(f, data, offset);
offset = 0;
}
@@ -154,6 +163,7 @@ struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp
f->tp = tp;
f->name = name;
f->do_crc = 0;
+ f->do_sha1 = 1;
git_SHA1_Init(&f->ctx);
return f;
}
diff --git a/csum-file.h b/csum-file.h
index 3b540bd..c23ea62 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -12,7 +12,7 @@ struct sha1file {
off_t total;
struct progress *tp;
const char *name;
- int do_crc;
+ int do_crc, do_sha1;
uint32_t crc32;
unsigned char buffer[8192];
};
--
1.7.8.36.g69ee2
next prev parent reply other threads:[~2012-02-06 5:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-06 5:48 [PATCH 1/6] read-cache: use sha1file for sha1 calculation Nguyễn Thái Ngọc Duy
2012-02-06 5:48 ` Nguyễn Thái Ngọc Duy [this message]
2012-02-06 5:48 ` [PATCH 3/6] Stop producing index version 2 Nguyễn Thái Ngọc Duy
2012-02-06 7:10 ` Junio C Hamano
2012-02-07 3:09 ` Shawn Pearce
2012-02-07 4:50 ` Nguyen Thai Ngoc Duy
2012-02-07 8:51 ` Nguyen Thai Ngoc Duy
2012-02-07 5:21 ` Junio C Hamano
2012-02-07 17:25 ` Thomas Rast
2012-02-06 5:48 ` [PATCH 4/6] Introduce index version 4 with global flags Nguyễn Thái Ngọc Duy
2012-02-06 5:48 ` [PATCH 5/6] Allow to use crc32 as a lighter checksum on index Nguyễn Thái Ngọc Duy
2012-02-07 3:17 ` Shawn Pearce
2012-02-07 4:04 ` Dave Zarzycki
2012-02-07 4:29 ` Dave Zarzycki
2012-02-06 5:48 ` [PATCH 6/6] Automatically switch to crc32 checksum for index when it's too large Nguyễn Thái Ngọc Duy
2012-02-06 8:50 ` Dave Zarzycki
2012-02-06 8:54 ` Nguyen Thai Ngoc Duy
2012-02-06 9:07 ` Dave Zarzycki
2012-02-06 7:34 ` [PATCH 1/6] read-cache: use sha1file for sha1 calculation Junio C Hamano
2012-02-06 8:36 ` Nguyen Thai Ngoc Duy
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=1328507319-24687-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=joshua.redstone@fb.com \
--cc=trast@inf.ethz.ch \
/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).