Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
sha1_file: switch uses of SHA-1 to the_hash_algo
author
brian m. carlson
<sandals@crustytoothpaste.net>
Thu, 1 Feb 2018 02:18:41 +0000
(
02:18
+0000)
committer
Junio C Hamano
<gitster@pobox.com>
Fri, 2 Feb 2018 19:28:41 +0000
(11:28 -0800)
Switch various uses of explicit calls to SHA-1 into references to
the_hash_algo for better abstraction. Convert some calls to use struct
object_id.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
3206b6b
)
diff --git
a/sha1_file.c
b/sha1_file.c
index ec6ecea170ff24ff080968e3e83c7225c515b853..ff55fb303dcbc0c0a67d1bffc740896c5bc4116c 100644
(file)
--- a/
sha1_file.c
+++ b/
sha1_file.c
@@
-786,16
+786,16
@@
void *xmmap(void *start, size_t length,
int check_sha1_signature(const unsigned char *sha1, void *map,
unsigned long size, const char *type)
{
int check_sha1_signature(const unsigned char *sha1, void *map,
unsigned long size, const char *type)
{
-
unsigned char real_sha1[20]
;
+
struct object_id real_oid
;
enum object_type obj_type;
struct git_istream *st;
enum object_type obj_type;
struct git_istream *st;
- git_
SHA_CTX
c;
+ git_
hash_ctx
c;
char hdr[32];
int hdrlen;
if (map) {
char hdr[32];
int hdrlen;
if (map) {
- hash_sha1_file(map, size, type, real_
sha1
);
- return hashcmp(sha1, real_
sha1
) ? -1 : 0;
+ hash_sha1_file(map, size, type, real_
oid.hash
);
+ return hashcmp(sha1, real_
oid.hash
) ? -1 : 0;
}
st = open_istream(sha1, &obj_type, &size, NULL);
}
st = open_istream(sha1, &obj_type, &size, NULL);
@@
-806,8
+806,8
@@
int check_sha1_signature(const unsigned char *sha1, void *map,
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(obj_type), size) + 1;
/* Sha1.. */
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(obj_type), size) + 1;
/* Sha1.. */
-
git_SHA1_Init
(&c);
-
git_SHA1_Update
(&c, hdr, hdrlen);
+
the_hash_algo->init_fn
(&c);
+
the_hash_algo->update_fn
(&c, hdr, hdrlen);
for (;;) {
char buf[1024 * 16];
ssize_t readlen = read_istream(st, buf, sizeof(buf));
for (;;) {
char buf[1024 * 16];
ssize_t readlen = read_istream(st, buf, sizeof(buf));
@@
-818,11
+818,11
@@
int check_sha1_signature(const unsigned char *sha1, void *map,
}
if (!readlen)
break;
}
if (!readlen)
break;
-
git_SHA1_Update
(&c, buf, readlen);
+
the_hash_algo->update_fn
(&c, buf, readlen);
}
}
-
git_SHA1_Final(real_sha1
, &c);
+
the_hash_algo->final_fn(real_oid.hash
, &c);
close_istream(st);
close_istream(st);
- return hashcmp(sha1, real_
sha1
) ? -1 : 0;
+ return hashcmp(sha1, real_
oid.hash
) ? -1 : 0;
}
int git_open_cloexec(const char *name, int flags)
}
int git_open_cloexec(const char *name, int flags)
@@
-1421,16
+1421,16
@@
static void write_sha1_file_prepare(const void *buf, unsigned long len,
const char *type, unsigned char *sha1,
char *hdr, int *hdrlen)
{
const char *type, unsigned char *sha1,
char *hdr, int *hdrlen)
{
- git_
SHA_CTX
c;
+ git_
hash_ctx
c;
/* Generate the header */
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %lu", type, len)+1;
/* Sha1.. */
/* Generate the header */
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %lu", type, len)+1;
/* Sha1.. */
-
git_SHA1_Init
(&c);
-
git_SHA1_Update
(&c, hdr, *hdrlen);
-
git_SHA1_Update
(&c, buf, len);
-
git_SHA1_Final
(sha1, &c);
+
the_hash_algo->init_fn
(&c);
+
the_hash_algo->update_fn
(&c, hdr, *hdrlen);
+
the_hash_algo->update_fn
(&c, buf, len);
+
the_hash_algo->final_fn
(sha1, &c);
}
/*
}
/*
@@
-1552,8
+1552,8
@@
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
int fd, ret;
unsigned char compressed[4096];
git_zstream stream;
int fd, ret;
unsigned char compressed[4096];
git_zstream stream;
- git_
SHA_CTX
c;
-
unsigned char parano_sha1[20]
;
+ git_
hash_ctx
c;
+
struct object_id parano_oid
;
static struct strbuf tmp_file = STRBUF_INIT;
const char *filename = sha1_file_name(sha1);
static struct strbuf tmp_file = STRBUF_INIT;
const char *filename = sha1_file_name(sha1);
@@
-1569,14
+1569,14
@@
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
git_deflate_init(&stream, zlib_compression_level);
stream.next_out = compressed;
stream.avail_out = sizeof(compressed);
git_deflate_init(&stream, zlib_compression_level);
stream.next_out = compressed;
stream.avail_out = sizeof(compressed);
-
git_SHA1_Init
(&c);
+
the_hash_algo->init_fn
(&c);
/* First header.. */
stream.next_in = (unsigned char *)hdr;
stream.avail_in = hdrlen;
while (git_deflate(&stream, 0) == Z_OK)
; /* nothing */
/* First header.. */
stream.next_in = (unsigned char *)hdr;
stream.avail_in = hdrlen;
while (git_deflate(&stream, 0) == Z_OK)
; /* nothing */
-
git_SHA1_Update
(&c, hdr, hdrlen);
+
the_hash_algo->update_fn
(&c, hdr, hdrlen);
/* Then the data itself.. */
stream.next_in = (void *)buf;
/* Then the data itself.. */
stream.next_in = (void *)buf;
@@
-1584,7
+1584,7
@@
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
do {
unsigned char *in0 = stream.next_in;
ret = git_deflate(&stream, Z_FINISH);
do {
unsigned char *in0 = stream.next_in;
ret = git_deflate(&stream, Z_FINISH);
-
git_SHA1_Update
(&c, in0, stream.next_in - in0);
+
the_hash_algo->update_fn
(&c, in0, stream.next_in - in0);
if (write_buffer(fd, compressed, stream.next_out - compressed) < 0)
die("unable to write sha1 file");
stream.next_out = compressed;
if (write_buffer(fd, compressed, stream.next_out - compressed) < 0)
die("unable to write sha1 file");
stream.next_out = compressed;
@@
-1596,8
+1596,8
@@
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
ret = git_deflate_end_gently(&stream);
if (ret != Z_OK)
die("deflateEnd on object %s failed (%d)", sha1_to_hex(sha1), ret);
ret = git_deflate_end_gently(&stream);
if (ret != Z_OK)
die("deflateEnd on object %s failed (%d)", sha1_to_hex(sha1), ret);
-
git_SHA1_Final(parano_sha1
, &c);
- if (hashcmp(sha1, parano_
sha1
) != 0)
+
the_hash_algo->final_fn(parano_oid.hash
, &c);
+ if (hashcmp(sha1, parano_
oid.hash
) != 0)
die("confused by unstable object source data for %s", sha1_to_hex(sha1));
close_sha1_file(fd);
die("confused by unstable object source data for %s", sha1_to_hex(sha1));
close_sha1_file(fd);
@@
-2091,14
+2091,14
@@
static int check_stream_sha1(git_zstream *stream,
const char *path,
const unsigned char *expected_sha1)
{
const char *path,
const unsigned char *expected_sha1)
{
- git_
SHA_CTX
c;
+ git_
hash_ctx
c;
unsigned char real_sha1[GIT_MAX_RAWSZ];
unsigned char buf[4096];
unsigned long total_read;
int status = Z_OK;
unsigned char real_sha1[GIT_MAX_RAWSZ];
unsigned char buf[4096];
unsigned long total_read;
int status = Z_OK;
-
git_SHA1_Init
(&c);
-
git_SHA1_Update
(&c, hdr, stream->total_out);
+
the_hash_algo->init_fn
(&c);
+
the_hash_algo->update_fn
(&c, hdr, stream->total_out);
/*
* We already read some bytes into hdr, but the ones up to the NUL
/*
* We already read some bytes into hdr, but the ones up to the NUL
@@
-2117,7
+2117,7
@@
static int check_stream_sha1(git_zstream *stream,
if (size - total_read < stream->avail_out)
stream->avail_out = size - total_read;
status = git_inflate(stream, Z_FINISH);
if (size - total_read < stream->avail_out)
stream->avail_out = size - total_read;
status = git_inflate(stream, Z_FINISH);
-
git_SHA1_Update
(&c, buf, stream->next_out - buf);
+
the_hash_algo->update_fn
(&c, buf, stream->next_out - buf);
total_read += stream->next_out - buf;
}
git_inflate_end(stream);
total_read += stream->next_out - buf;
}
git_inflate_end(stream);
@@
-2132,7
+2132,7
@@
static int check_stream_sha1(git_zstream *stream,
return -1;
}
return -1;
}
-
git_SHA1_Final
(real_sha1, &c);
+
the_hash_algo->final_fn
(real_sha1, &c);
if (hashcmp(expected_sha1, real_sha1)) {
error("sha1 mismatch for %s (expected %s)", path,
sha1_to_hex(expected_sha1));
if (hashcmp(expected_sha1, real_sha1)) {
error("sha1 mismatch for %s (expected %s)", path,
sha1_to_hex(expected_sha1));