提交 d829d491 编写于 作者: J Junio C Hamano

Merge branch 'bc/hash-transition-part-15'

More codepaths are moving away from hardcoded hash sizes.

* bc/hash-transition-part-15:
  rerere: convert to use the_hash_algo
  submodule: make zero-oid comparison hash function agnostic
  apply: rename new_sha1_prefix and old_sha1_prefix
  apply: replace hard-coded constants
  tag: express constant in terms of the_hash_algo
  transport: use parse_oid_hex instead of a constant
  upload-pack: express constants in terms of the_hash_algo
  refs/packed-backend: express constants using the_hash_algo
  packfile: express constants in terms of the_hash_algo
  pack-revindex: express constants in terms of the_hash_algo
  builtin/fetch-pack: remove constants with parse_oid_hex
  builtin/mktree: remove hard-coded constant
  builtin/repack: replace hard-coded constants
  pack-bitmap-write: use GIT_MAX_RAWSZ for allocation
  object_id.cocci: match only expressions of type 'struct object_id'
...@@ -223,8 +223,8 @@ struct patch { ...@@ -223,8 +223,8 @@ struct patch {
struct fragment *fragments; struct fragment *fragments;
char *result; char *result;
size_t resultsize; size_t resultsize;
char old_sha1_prefix[41]; char old_oid_prefix[GIT_MAX_HEXSZ + 1];
char new_sha1_prefix[41]; char new_oid_prefix[GIT_MAX_HEXSZ + 1];
struct patch *next; struct patch *next;
/* three-way fallback result */ /* three-way fallback result */
...@@ -1093,13 +1093,14 @@ static int gitdiff_index(struct apply_state *state, ...@@ -1093,13 +1093,14 @@ static int gitdiff_index(struct apply_state *state,
*/ */
const char *ptr, *eol; const char *ptr, *eol;
int len; int len;
const unsigned hexsz = the_hash_algo->hexsz;
ptr = strchr(line, '.'); ptr = strchr(line, '.');
if (!ptr || ptr[1] != '.' || 40 < ptr - line) if (!ptr || ptr[1] != '.' || hexsz < ptr - line)
return 0; return 0;
len = ptr - line; len = ptr - line;
memcpy(patch->old_sha1_prefix, line, len); memcpy(patch->old_oid_prefix, line, len);
patch->old_sha1_prefix[len] = 0; patch->old_oid_prefix[len] = 0;
line = ptr + 2; line = ptr + 2;
ptr = strchr(line, ' '); ptr = strchr(line, ' ');
...@@ -1109,10 +1110,10 @@ static int gitdiff_index(struct apply_state *state, ...@@ -1109,10 +1110,10 @@ static int gitdiff_index(struct apply_state *state,
ptr = eol; ptr = eol;
len = ptr - line; len = ptr - line;
if (40 < len) if (hexsz < len)
return 0; return 0;
memcpy(patch->new_sha1_prefix, line, len); memcpy(patch->new_oid_prefix, line, len);
patch->new_sha1_prefix[len] = 0; patch->new_oid_prefix[len] = 0;
if (*ptr == ' ') if (*ptr == ' ')
return gitdiff_oldmode(state, ptr + 1, patch); return gitdiff_oldmode(state, ptr + 1, patch);
return 0; return 0;
...@@ -2206,7 +2207,7 @@ static void reverse_patches(struct patch *p) ...@@ -2206,7 +2207,7 @@ static void reverse_patches(struct patch *p)
SWAP(p->new_mode, p->old_mode); SWAP(p->new_mode, p->old_mode);
SWAP(p->is_new, p->is_delete); SWAP(p->is_new, p->is_delete);
SWAP(p->lines_added, p->lines_deleted); SWAP(p->lines_added, p->lines_deleted);
SWAP(p->old_sha1_prefix, p->new_sha1_prefix); SWAP(p->old_oid_prefix, p->new_oid_prefix);
for (; frag; frag = frag->next) { for (; frag; frag = frag->next) {
SWAP(frag->newpos, frag->oldpos); SWAP(frag->newpos, frag->oldpos);
...@@ -3144,15 +3145,16 @@ static int apply_binary(struct apply_state *state, ...@@ -3144,15 +3145,16 @@ static int apply_binary(struct apply_state *state,
{ {
const char *name = patch->old_name ? patch->old_name : patch->new_name; const char *name = patch->old_name ? patch->old_name : patch->new_name;
struct object_id oid; struct object_id oid;
const unsigned hexsz = the_hash_algo->hexsz;
/* /*
* For safety, we require patch index line to contain * For safety, we require patch index line to contain
* full 40-byte textual SHA1 for old and new, at least for now. * full hex textual object ID for old and new, at least for now.
*/ */
if (strlen(patch->old_sha1_prefix) != 40 || if (strlen(patch->old_oid_prefix) != hexsz ||
strlen(patch->new_sha1_prefix) != 40 || strlen(patch->new_oid_prefix) != hexsz ||
get_oid_hex(patch->old_sha1_prefix, &oid) || get_oid_hex(patch->old_oid_prefix, &oid) ||
get_oid_hex(patch->new_sha1_prefix, &oid)) get_oid_hex(patch->new_oid_prefix, &oid))
return error(_("cannot apply binary patch to '%s' " return error(_("cannot apply binary patch to '%s' "
"without full index line"), name); "without full index line"), name);
...@@ -3162,7 +3164,7 @@ static int apply_binary(struct apply_state *state, ...@@ -3162,7 +3164,7 @@ static int apply_binary(struct apply_state *state,
* applies to. * applies to.
*/ */
hash_object_file(img->buf, img->len, blob_type, &oid); hash_object_file(img->buf, img->len, blob_type, &oid);
if (strcmp(oid_to_hex(&oid), patch->old_sha1_prefix)) if (strcmp(oid_to_hex(&oid), patch->old_oid_prefix))
return error(_("the patch applies to '%s' (%s), " return error(_("the patch applies to '%s' (%s), "
"which does not match the " "which does not match the "
"current contents."), "current contents."),
...@@ -3175,7 +3177,7 @@ static int apply_binary(struct apply_state *state, ...@@ -3175,7 +3177,7 @@ static int apply_binary(struct apply_state *state,
"'%s' but it is not empty"), name); "'%s' but it is not empty"), name);
} }
get_oid_hex(patch->new_sha1_prefix, &oid); get_oid_hex(patch->new_oid_prefix, &oid);
if (is_null_oid(&oid)) { if (is_null_oid(&oid)) {
clear_image(img); clear_image(img);
return 0; /* deletion patch */ return 0; /* deletion patch */
...@@ -3191,7 +3193,7 @@ static int apply_binary(struct apply_state *state, ...@@ -3191,7 +3193,7 @@ static int apply_binary(struct apply_state *state,
if (!result) if (!result)
return error(_("the necessary postimage %s for " return error(_("the necessary postimage %s for "
"'%s' cannot be read"), "'%s' cannot be read"),
patch->new_sha1_prefix, name); patch->new_oid_prefix, name);
clear_image(img); clear_image(img);
img->buf = result; img->buf = result;
img->len = size; img->len = size;
...@@ -3207,9 +3209,9 @@ static int apply_binary(struct apply_state *state, ...@@ -3207,9 +3209,9 @@ static int apply_binary(struct apply_state *state,
/* verify that the result matches */ /* verify that the result matches */
hash_object_file(img->buf, img->len, blob_type, &oid); hash_object_file(img->buf, img->len, blob_type, &oid);
if (strcmp(oid_to_hex(&oid), patch->new_sha1_prefix)) if (strcmp(oid_to_hex(&oid), patch->new_oid_prefix))
return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"), return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"),
name, patch->new_sha1_prefix, oid_to_hex(&oid)); name, patch->new_oid_prefix, oid_to_hex(&oid));
} }
return 0; return 0;
...@@ -3568,7 +3570,7 @@ static int try_threeway(struct apply_state *state, ...@@ -3568,7 +3570,7 @@ static int try_threeway(struct apply_state *state,
/* Preimage the patch was prepared for */ /* Preimage the patch was prepared for */
if (patch->is_new) if (patch->is_new)
write_object_file("", 0, blob_type, &pre_oid); write_object_file("", 0, blob_type, &pre_oid);
else if (get_oid(patch->old_sha1_prefix, &pre_oid) || else if (get_oid(patch->old_oid_prefix, &pre_oid) ||
read_blob_object(&buf, &pre_oid, patch->old_mode)) read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to fall back on 3-way merge.")); return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
...@@ -4060,13 +4062,13 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid) ...@@ -4060,13 +4062,13 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
starts_with(++preimage, heading) && starts_with(++preimage, heading) &&
/* does it record full SHA-1? */ /* does it record full SHA-1? */
!get_oid_hex(preimage + sizeof(heading) - 1, oid) && !get_oid_hex(preimage + sizeof(heading) - 1, oid) &&
preimage[sizeof(heading) + GIT_SHA1_HEXSZ - 1] == '\n' && preimage[sizeof(heading) + the_hash_algo->hexsz - 1] == '\n' &&
/* does the abbreviated name on the index line agree with it? */ /* does the abbreviated name on the index line agree with it? */
starts_with(preimage + sizeof(heading) - 1, p->old_sha1_prefix)) starts_with(preimage + sizeof(heading) - 1, p->old_oid_prefix))
return 0; /* it all looks fine */ return 0; /* it all looks fine */
/* we may have full object name on the index line */ /* we may have full object name on the index line */
return get_oid_hex(p->old_sha1_prefix, oid); return get_oid_hex(p->old_oid_prefix, oid);
} }
/* Build an index that contains just the files needed for a 3way merge */ /* Build an index that contains just the files needed for a 3way merge */
...@@ -4095,7 +4097,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list) ...@@ -4095,7 +4097,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
else else
return error(_("sha1 information is lacking or " return error(_("sha1 information is lacking or "
"useless for submodule %s"), name); "useless for submodule %s"), name);
} else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) { } else if (!get_oid_blob(patch->old_oid_prefix, &oid)) {
; /* ok */ ; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) { } else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */ /* mode-only change: update the current */
......
...@@ -16,13 +16,14 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc, ...@@ -16,13 +16,14 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
{ {
struct ref *ref; struct ref *ref;
struct object_id oid; struct object_id oid;
const char *p;
if (!get_oid_hex(name, &oid)) { if (!parse_oid_hex(name, &oid, &p)) {
if (name[GIT_SHA1_HEXSZ] == ' ') { if (*p == ' ') {
/* <sha1> <ref>, find refname */ /* <oid> <ref>, find refname */
name += GIT_SHA1_HEXSZ + 1; name = p + 1;
} else if (name[GIT_SHA1_HEXSZ] == '\0') { } else if (*p == '\0') {
; /* <sha1>, leave sha1 as name */ ; /* <oid>, leave oid as name */
} else { } else {
/* <ref>, clear cruft from oid */ /* <ref>, clear cruft from oid */
oidclr(&oid); oidclr(&oid);
......
...@@ -98,7 +98,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss ...@@ -98,7 +98,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
*ntr++ = 0; /* now at the beginning of SHA1 */ *ntr++ = 0; /* now at the beginning of SHA1 */
path = ntr + 41; /* at the beginning of name */ path = (char *)p + 1; /* at the beginning of name */
if (!nul_term_line && path[0] == '"') { if (!nul_term_line && path[0] == '"') {
struct strbuf p_uq = STRBUF_INIT; struct strbuf p_uq = STRBUF_INIT;
if (unquote_c_style(&p_uq, path, NULL)) if (unquote_c_style(&p_uq, path, NULL))
......
...@@ -235,8 +235,8 @@ static void repack_promisor_objects(const struct pack_objects_args *args, ...@@ -235,8 +235,8 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
while (strbuf_getline_lf(&line, out) != EOF) { while (strbuf_getline_lf(&line, out) != EOF) {
char *promisor_name; char *promisor_name;
int fd; int fd;
if (line.len != 40) if (line.len != the_hash_algo->hexsz)
die("repack: Expecting 40 character sha1 lines only from pack-objects."); die("repack: Expecting full hex object ID lines only from pack-objects.");
string_list_append(names, line.buf); string_list_append(names, line.buf);
/* /*
...@@ -407,8 +407,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix) ...@@ -407,8 +407,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
out = xfdopen(cmd.out, "r"); out = xfdopen(cmd.out, "r");
while (strbuf_getline_lf(&line, out) != EOF) { while (strbuf_getline_lf(&line, out) != EOF) {
if (line.len != 40) if (line.len != the_hash_algo->hexsz)
die("repack: Expecting 40 character sha1 lines only from pack-objects."); die("repack: Expecting full hex object ID lines only from pack-objects.");
string_list_append(&names, line.buf); string_list_append(&names, line.buf);
} }
fclose(out); fclose(out);
...@@ -535,14 +535,15 @@ int cmd_repack(int argc, const char **argv, const char *prefix) ...@@ -535,14 +535,15 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
reprepare_packed_git(the_repository); reprepare_packed_git(the_repository);
if (delete_redundant) { if (delete_redundant) {
const int hexsz = the_hash_algo->hexsz;
int opts = 0; int opts = 0;
string_list_sort(&names); string_list_sort(&names);
for_each_string_list_item(item, &existing_packs) { for_each_string_list_item(item, &existing_packs) {
char *sha1; char *sha1;
size_t len = strlen(item->string); size_t len = strlen(item->string);
if (len < 40) if (len < hexsz)
continue; continue;
sha1 = item->string + len - 40; sha1 = item->string + len - hexsz;
if (!string_list_has_string(&names, sha1)) if (!string_list_has_string(&names, sha1))
remove_redundant_pack(packdir, item->string); remove_redundant_pack(packdir, item->string);
} }
......
@@ @@
expression E1; struct object_id OID;
@@ @@
- is_null_sha1(E1.hash) - is_null_sha1(OID.hash)
+ is_null_oid(&E1) + is_null_oid(&OID)
@@ @@
expression E1; struct object_id *OIDPTR;
@@ @@
- is_null_sha1(E1->hash) - is_null_sha1(OIDPTR->hash)
+ is_null_oid(E1) + is_null_oid(OIDPTR)
@@ @@
expression E1; struct object_id OID;
@@ @@
- sha1_to_hex(E1.hash) - sha1_to_hex(OID.hash)
+ oid_to_hex(&E1) + oid_to_hex(&OID)
@@ @@
identifier f != oid_to_hex; identifier f != oid_to_hex;
expression E1; struct object_id *OIDPTR;
@@ @@
f(...) {<... f(...) {<...
- sha1_to_hex(E1->hash) - sha1_to_hex(OIDPTR->hash)
+ oid_to_hex(E1) + oid_to_hex(OIDPTR)
...>} ...>}
@@ @@
expression E1, E2; expression E;
struct object_id OID;
@@ @@
- sha1_to_hex_r(E1, E2.hash) - sha1_to_hex_r(E, OID.hash)
+ oid_to_hex_r(E1, &E2) + oid_to_hex_r(E, &OID)
@@ @@
identifier f != oid_to_hex_r; identifier f != oid_to_hex_r;
expression E1, E2; expression E;
struct object_id *OIDPTR;
@@ @@
f(...) {<... f(...) {<...
- sha1_to_hex_r(E1, E2->hash) - sha1_to_hex_r(E, OIDPTR->hash)
+ oid_to_hex_r(E1, E2) + oid_to_hex_r(E, OIDPTR)
...>} ...>}
@@ @@
expression E1; struct object_id OID;
@@ @@
- hashclr(E1.hash) - hashclr(OID.hash)
+ oidclr(&E1) + oidclr(&OID)
@@ @@
identifier f != oidclr; identifier f != oidclr;
expression E1; struct object_id *OIDPTR;
@@ @@
f(...) {<... f(...) {<...
- hashclr(E1->hash) - hashclr(OIDPTR->hash)
+ oidclr(E1) + oidclr(OIDPTR)
...>} ...>}
@@ @@
expression E1, E2; struct object_id OID1, OID2;
@@ @@
- hashcmp(E1.hash, E2.hash) - hashcmp(OID1.hash, OID2.hash)
+ oidcmp(&E1, &E2) + oidcmp(&OID1, &OID2)
@@ @@
identifier f != oidcmp; identifier f != oidcmp;
expression E1, E2; struct object_id *OIDPTR1, OIDPTR2;
@@ @@
f(...) {<... f(...) {<...
- hashcmp(E1->hash, E2->hash) - hashcmp(OIDPTR1->hash, OIDPTR2->hash)
+ oidcmp(E1, E2) + oidcmp(OIDPTR1, OIDPTR2)
...>} ...>}
@@ @@
expression E1, E2; struct object_id *OIDPTR;
struct object_id OID;
@@ @@
- hashcmp(E1->hash, E2.hash) - hashcmp(OIDPTR->hash, OID.hash)
+ oidcmp(E1, &E2) + oidcmp(OIDPTR, &OID)
@@ @@
expression E1, E2; struct object_id *OIDPTR;
struct object_id OID;
@@ @@
- hashcmp(E1.hash, E2->hash) - hashcmp(OID.hash, OIDPTR->hash)
+ oidcmp(&E1, E2) + oidcmp(&OID, OIDPTR)
@@ @@
expression E1, E2; struct object_id OID1, OID2;
@@ @@
- hashcpy(E1.hash, E2.hash) - hashcpy(OID1.hash, OID2.hash)
+ oidcpy(&E1, &E2) + oidcpy(&OID1, &OID2)
@@ @@
identifier f != oidcpy; identifier f != oidcpy;
expression E1, E2; struct object_id *OIDPTR1;
struct object_id *OIDPTR2;
@@ @@
f(...) {<... f(...) {<...
- hashcpy(E1->hash, E2->hash) - hashcpy(OIDPTR1->hash, OIDPTR2->hash)
+ oidcpy(E1, E2) + oidcpy(OIDPTR1, OIDPTR2)
...>} ...>}
@@ @@
expression E1, E2; struct object_id *OIDPTR;
struct object_id OID;
@@ @@
- hashcpy(E1->hash, E2.hash) - hashcpy(OIDPTR->hash, OID.hash)
+ oidcpy(E1, &E2) + oidcpy(OIDPTR, &OID)
@@ @@
expression E1, E2; struct object_id *OIDPTR;
struct object_id OID;
@@ @@
- hashcpy(E1.hash, E2->hash) - hashcpy(OID.hash, OIDPTR->hash)
+ oidcpy(&E1, E2) + oidcpy(&OID, OIDPTR)
@@ @@
expression E1, E2; struct object_id *OIDPTR1;
struct object_id *OIDPTR2;
@@ @@
- oidcmp(E1, E2) == 0 - oidcmp(OIDPTR1, OIDPTR2) == 0
+ oideq(E1, E2) + oideq(OIDPTR1, OIDPTR2)
@@ @@
identifier f != hasheq; identifier f != hasheq;
...@@ -125,10 +133,11 @@ expression E1, E2; ...@@ -125,10 +133,11 @@ expression E1, E2;
...>} ...>}
@@ @@
expression E1, E2; struct object_id *OIDPTR1;
struct object_id *OIDPTR2;
@@ @@
- oidcmp(E1, E2) != 0 - oidcmp(OIDPTR1, OIDPTR2) != 0
+ !oideq(E1, E2) + !oideq(OIDPTR1, OIDPTR2)
@@ @@
identifier f != hasheq; identifier f != hasheq;
......
...@@ -82,6 +82,11 @@ isnumber() ...@@ -82,6 +82,11 @@ isnumber()
n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
} }
# Given a full hex object ID, is this the zero OID?
is_zero_oid () {
echo "$1" | sane_egrep '^0+$' >/dev/null 2>&1
}
# Sanitize the local git environment for use within a submodule. We # Sanitize the local git environment for use within a submodule. We
# can't simply use clear_local_git_env since we want to preserve some # can't simply use clear_local_git_env since we want to preserve some
# of the settings from GIT_CONFIG_PARAMETERS. # of the settings from GIT_CONFIG_PARAMETERS.
...@@ -780,7 +785,7 @@ cmd_summary() { ...@@ -780,7 +785,7 @@ cmd_summary() {
while read -r mod_src mod_dst sha1_src sha1_dst status name while read -r mod_src mod_dst sha1_src sha1_dst status name
do do
if test -z "$cached" && if test -z "$cached" &&
test $sha1_dst = 0000000000000000000000000000000000000000 is_zero_oid $sha1_dst
then then
case "$mod_dst" in case "$mod_dst" in
160000) 160000)
......
...@@ -37,7 +37,7 @@ struct bitmap_writer { ...@@ -37,7 +37,7 @@ struct bitmap_writer {
struct progress *progress; struct progress *progress;
int show_progress; int show_progress;
unsigned char pack_checksum[20]; unsigned char pack_checksum[GIT_MAX_RAWSZ];
}; };
static struct bitmap_writer writer; static struct bitmap_writer writer;
......
...@@ -122,13 +122,14 @@ static void create_pack_revindex(struct packed_git *p) ...@@ -122,13 +122,14 @@ static void create_pack_revindex(struct packed_git *p)
unsigned num_ent = p->num_objects; unsigned num_ent = p->num_objects;
unsigned i; unsigned i;
const char *index = p->index_data; const char *index = p->index_data;
const unsigned hashsz = the_hash_algo->rawsz;
ALLOC_ARRAY(p->revindex, num_ent + 1); ALLOC_ARRAY(p->revindex, num_ent + 1);
index += 4 * 256; index += 4 * 256;
if (p->index_version > 1) { if (p->index_version > 1) {
const uint32_t *off_32 = const uint32_t *off_32 =
(uint32_t *)(index + 8 + p->num_objects * (20 + 4)); (uint32_t *)(index + 8 + p->num_objects * (hashsz + 4));
const uint32_t *off_64 = off_32 + p->num_objects; const uint32_t *off_64 = off_32 + p->num_objects;
for (i = 0; i < num_ent; i++) { for (i = 0; i < num_ent; i++) {
uint32_t off = ntohl(*off_32++); uint32_t off = ntohl(*off_32++);
...@@ -142,16 +143,17 @@ static void create_pack_revindex(struct packed_git *p) ...@@ -142,16 +143,17 @@ static void create_pack_revindex(struct packed_git *p)
} }
} else { } else {
for (i = 0; i < num_ent; i++) { for (i = 0; i < num_ent; i++) {
uint32_t hl = *((uint32_t *)(index + 24 * i)); uint32_t hl = *((uint32_t *)(index + (hashsz + 4) * i));
p->revindex[i].offset = ntohl(hl); p->revindex[i].offset = ntohl(hl);
p->revindex[i].nr = i; p->revindex[i].nr = i;
} }
} }
/* This knows the pack format -- the 20-byte trailer /*
* This knows the pack format -- the hash trailer
* follows immediately after the last object data. * follows immediately after the last object data.
*/ */
p->revindex[num_ent].offset = p->pack_size - 20; p->revindex[num_ent].offset = p->pack_size - hashsz;
p->revindex[num_ent].nr = -1; p->revindex[num_ent].nr = -1;
sort_revindex(p->revindex, num_ent, p->pack_size); sort_revindex(p->revindex, num_ent, p->pack_size);
} }
......
...@@ -1127,13 +1127,14 @@ int unpack_object_header(struct packed_git *p, ...@@ -1127,13 +1127,14 @@ int unpack_object_header(struct packed_git *p,
void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1) void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
{ {
unsigned i; unsigned i;
const unsigned hashsz = the_hash_algo->rawsz;
for (i = 0; i < p->num_bad_objects; i++) for (i = 0; i < p->num_bad_objects; i++)
if (hasheq(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i)) if (hasheq(sha1, p->bad_object_sha1 + hashsz * i))
return; return;
p->bad_object_sha1 = xrealloc(p->bad_object_sha1, p->bad_object_sha1 = xrealloc(p->bad_object_sha1,
st_mult(GIT_MAX_RAWSZ, st_mult(GIT_MAX_RAWSZ,
st_add(p->num_bad_objects, 1))); st_add(p->num_bad_objects, 1)));
hashcpy(p->bad_object_sha1 + GIT_SHA1_RAWSZ * p->num_bad_objects, sha1); hashcpy(p->bad_object_sha1 + hashsz * p->num_bad_objects, sha1);
p->num_bad_objects++; p->num_bad_objects++;
} }
......
...@@ -274,8 +274,8 @@ struct snapshot_record { ...@@ -274,8 +274,8 @@ struct snapshot_record {
static int cmp_packed_ref_records(const void *v1, const void *v2) static int cmp_packed_ref_records(const void *v1, const void *v2)
{ {
const struct snapshot_record *e1 = v1, *e2 = v2; const struct snapshot_record *e1 = v1, *e2 = v2;
const char *r1 = e1->start + GIT_SHA1_HEXSZ + 1; const char *r1 = e1->start + the_hash_algo->hexsz + 1;
const char *r2 = e2->start + GIT_SHA1_HEXSZ + 1; const char *r2 = e2->start + the_hash_algo->hexsz + 1;
while (1) { while (1) {
if (*r1 == '\n') if (*r1 == '\n')
...@@ -297,7 +297,7 @@ static int cmp_packed_ref_records(const void *v1, const void *v2) ...@@ -297,7 +297,7 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)
*/ */
static int cmp_record_to_refname(const char *rec, const char *refname) static int cmp_record_to_refname(const char *rec, const char *refname)
{ {
const char *r1 = rec + GIT_SHA1_HEXSZ + 1; const char *r1 = rec + the_hash_algo->hexsz + 1;
const char *r2 = refname; const char *r2 = refname;
while (1) { while (1) {
...@@ -344,7 +344,7 @@ static void sort_snapshot(struct snapshot *snapshot) ...@@ -344,7 +344,7 @@ static void sort_snapshot(struct snapshot *snapshot)
if (!eol) if (!eol)
/* The safety check should prevent this. */ /* The safety check should prevent this. */
BUG("unterminated line found in packed-refs"); BUG("unterminated line found in packed-refs");
if (eol - pos < GIT_SHA1_HEXSZ + 2) if (eol - pos < the_hash_algo->hexsz + 2)
die_invalid_line(snapshot->refs->path, die_invalid_line(snapshot->refs->path,
pos, eof - pos); pos, eof - pos);
eol++; eol++;
...@@ -456,7 +456,7 @@ static void verify_buffer_safe(struct snapshot *snapshot) ...@@ -456,7 +456,7 @@ static void verify_buffer_safe(struct snapshot *snapshot)
return; return;
last_line = find_start_of_record(start, eof - 1); last_line = find_start_of_record(start, eof - 1);
if (*(eof - 1) != '\n' || eof - last_line < GIT_SHA1_HEXSZ + 2) if (*(eof - 1) != '\n' || eof - last_line < the_hash_algo->hexsz + 2)
die_invalid_line(snapshot->refs->path, die_invalid_line(snapshot->refs->path,
last_line, eof - last_line); last_line, eof - last_line);
} }
...@@ -796,7 +796,7 @@ static int next_record(struct packed_ref_iterator *iter) ...@@ -796,7 +796,7 @@ static int next_record(struct packed_ref_iterator *iter)
iter->base.flags = REF_ISPACKED; iter->base.flags = REF_ISPACKED;
if (iter->eof - p < GIT_SHA1_HEXSZ + 2 || if (iter->eof - p < the_hash_algo->hexsz + 2 ||
parse_oid_hex(p, &iter->oid, &p) || parse_oid_hex(p, &iter->oid, &p) ||
!isspace(*p++)) !isspace(*p++))
die_invalid_line(iter->snapshot->refs->path, die_invalid_line(iter->snapshot->refs->path,
...@@ -826,7 +826,7 @@ static int next_record(struct packed_ref_iterator *iter) ...@@ -826,7 +826,7 @@ static int next_record(struct packed_ref_iterator *iter)
if (iter->pos < iter->eof && *iter->pos == '^') { if (iter->pos < iter->eof && *iter->pos == '^') {
p = iter->pos + 1; p = iter->pos + 1;
if (iter->eof - p < GIT_SHA1_HEXSZ + 1 || if (iter->eof - p < the_hash_algo->hexsz + 1 ||
parse_oid_hex(p, &iter->peeled, &p) || parse_oid_hex(p, &iter->peeled, &p) ||
*p++ != '\n') *p++ != '\n')
die_invalid_line(iter->snapshot->refs->path, die_invalid_line(iter->snapshot->refs->path,
......
...@@ -29,7 +29,7 @@ static int rerere_dir_alloc; ...@@ -29,7 +29,7 @@ static int rerere_dir_alloc;
#define RR_HAS_POSTIMAGE 1 #define RR_HAS_POSTIMAGE 1
#define RR_HAS_PREIMAGE 2 #define RR_HAS_PREIMAGE 2
static struct rerere_dir { static struct rerere_dir {
unsigned char sha1[20]; unsigned char hash[GIT_MAX_HEXSZ];
int status_alloc, status_nr; int status_alloc, status_nr;
unsigned char *status; unsigned char *status;
} **rerere_dir; } **rerere_dir;
...@@ -52,7 +52,7 @@ static void free_rerere_id(struct string_list_item *item) ...@@ -52,7 +52,7 @@ static void free_rerere_id(struct string_list_item *item)
static const char *rerere_id_hex(const struct rerere_id *id) static const char *rerere_id_hex(const struct rerere_id *id)
{ {
return sha1_to_hex(id->collection->sha1); return sha1_to_hex(id->collection->hash);
} }
static void fit_variant(struct rerere_dir *rr_dir, int variant) static void fit_variant(struct rerere_dir *rr_dir, int variant)
...@@ -115,7 +115,7 @@ static int is_rr_file(const char *name, const char *filename, int *variant) ...@@ -115,7 +115,7 @@ static int is_rr_file(const char *name, const char *filename, int *variant)
static void scan_rerere_dir(struct rerere_dir *rr_dir) static void scan_rerere_dir(struct rerere_dir *rr_dir)
{ {
struct dirent *de; struct dirent *de;
DIR *dir = opendir(git_path("rr-cache/%s", sha1_to_hex(rr_dir->sha1))); DIR *dir = opendir(git_path("rr-cache/%s", sha1_to_hex(rr_dir->hash)));
if (!dir) if (!dir)
return; return;
...@@ -133,24 +133,24 @@ static void scan_rerere_dir(struct rerere_dir *rr_dir) ...@@ -133,24 +133,24 @@ static void scan_rerere_dir(struct rerere_dir *rr_dir)
closedir(dir); closedir(dir);
} }
static const unsigned char *rerere_dir_sha1(size_t i, void *table) static const unsigned char *rerere_dir_hash(size_t i, void *table)
{ {
struct rerere_dir **rr_dir = table; struct rerere_dir **rr_dir = table;
return rr_dir[i]->sha1; return rr_dir[i]->hash;
} }
static struct rerere_dir *find_rerere_dir(const char *hex) static struct rerere_dir *find_rerere_dir(const char *hex)
{ {
unsigned char sha1[20]; unsigned char hash[GIT_MAX_RAWSZ];
struct rerere_dir *rr_dir; struct rerere_dir *rr_dir;
int pos; int pos;
if (get_sha1_hex(hex, sha1)) if (get_sha1_hex(hex, hash))
return NULL; /* BUG */ return NULL; /* BUG */
pos = sha1_pos(sha1, rerere_dir, rerere_dir_nr, rerere_dir_sha1); pos = sha1_pos(hash, rerere_dir, rerere_dir_nr, rerere_dir_hash);
if (pos < 0) { if (pos < 0) {
rr_dir = xmalloc(sizeof(*rr_dir)); rr_dir = xmalloc(sizeof(*rr_dir));
hashcpy(rr_dir->sha1, sha1); hashcpy(rr_dir->hash, hash);
rr_dir->status = NULL; rr_dir->status = NULL;
rr_dir->status_nr = 0; rr_dir->status_nr = 0;
rr_dir->status_alloc = 0; rr_dir->status_alloc = 0;
...@@ -207,26 +207,27 @@ static void read_rr(struct string_list *rr) ...@@ -207,26 +207,27 @@ static void read_rr(struct string_list *rr)
return; return;
while (!strbuf_getwholeline(&buf, in, '\0')) { while (!strbuf_getwholeline(&buf, in, '\0')) {
char *path; char *path;
unsigned char sha1[20]; unsigned char hash[GIT_MAX_RAWSZ];
struct rerere_id *id; struct rerere_id *id;
int variant; int variant;
const unsigned hexsz = the_hash_algo->hexsz;
/* There has to be the hash, tab, path and then NUL */ /* There has to be the hash, tab, path and then NUL */
if (buf.len < 42 || get_sha1_hex(buf.buf, sha1)) if (buf.len < hexsz + 2 || get_sha1_hex(buf.buf, hash))
die(_("corrupt MERGE_RR")); die(_("corrupt MERGE_RR"));
if (buf.buf[40] != '.') { if (buf.buf[hexsz] != '.') {
variant = 0; variant = 0;
path = buf.buf + 40; path = buf.buf + hexsz;
} else { } else {
errno = 0; errno = 0;
variant = strtol(buf.buf + 41, &path, 10); variant = strtol(buf.buf + hexsz + 1, &path, 10);
if (errno) if (errno)
die(_("corrupt MERGE_RR")); die(_("corrupt MERGE_RR"));
} }
if (*(path++) != '\t') if (*(path++) != '\t')
die(_("corrupt MERGE_RR")); die(_("corrupt MERGE_RR"));
buf.buf[40] = '\0'; buf.buf[hexsz] = '\0';
id = new_rerere_id_hex(buf.buf); id = new_rerere_id_hex(buf.buf);
id->variant = variant; id->variant = variant;
string_list_insert(rr, path)->util = id; string_list_insert(rr, path)->util = id;
...@@ -360,7 +361,7 @@ static void rerere_strbuf_putconflict(struct strbuf *buf, int ch, size_t size) ...@@ -360,7 +361,7 @@ static void rerere_strbuf_putconflict(struct strbuf *buf, int ch, size_t size)
} }
static int handle_conflict(struct strbuf *out, struct rerere_io *io, static int handle_conflict(struct strbuf *out, struct rerere_io *io,
int marker_size, git_SHA_CTX *ctx) int marker_size, git_hash_ctx *ctx)
{ {
enum { enum {
RR_SIDE_1 = 0, RR_SIDE_2, RR_ORIGINAL RR_SIDE_1 = 0, RR_SIDE_2, RR_ORIGINAL
...@@ -398,10 +399,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, ...@@ -398,10 +399,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
strbuf_addbuf(out, &two); strbuf_addbuf(out, &two);
rerere_strbuf_putconflict(out, '>', marker_size); rerere_strbuf_putconflict(out, '>', marker_size);
if (ctx) { if (ctx) {
git_SHA1_Update(ctx, one.buf ? one.buf : "", the_hash_algo->update_fn(ctx, one.buf ?
one.len + 1); one.buf : "",
git_SHA1_Update(ctx, two.buf ? two.buf : "", one.len + 1);
two.len + 1); the_hash_algo->update_fn(ctx, two.buf ?
two.buf : "",
two.len + 1);
} }
break; break;
} else if (hunk == RR_SIDE_1) } else if (hunk == RR_SIDE_1)
...@@ -430,18 +433,18 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, ...@@ -430,18 +433,18 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
* Return 1 if conflict hunks are found, 0 if there are no conflict * Return 1 if conflict hunks are found, 0 if there are no conflict
* hunks and -1 if an error occured. * hunks and -1 if an error occured.
*/ */
static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_size) static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_size)
{ {
git_SHA_CTX ctx; git_hash_ctx ctx;
struct strbuf buf = STRBUF_INIT, out = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, out = STRBUF_INIT;
int has_conflicts = 0; int has_conflicts = 0;
if (sha1) if (hash)
git_SHA1_Init(&ctx); the_hash_algo->init_fn(&ctx);
while (!io->getline(&buf, io)) { while (!io->getline(&buf, io)) {
if (is_cmarker(buf.buf, '<', marker_size)) { if (is_cmarker(buf.buf, '<', marker_size)) {
has_conflicts = handle_conflict(&out, io, marker_size, has_conflicts = handle_conflict(&out, io, marker_size,
sha1 ? &ctx : NULL); hash ? &ctx : NULL);
if (has_conflicts < 0) if (has_conflicts < 0)
break; break;
rerere_io_putmem(out.buf, out.len, io); rerere_io_putmem(out.buf, out.len, io);
...@@ -452,8 +455,8 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz ...@@ -452,8 +455,8 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
strbuf_release(&buf); strbuf_release(&buf);
strbuf_release(&out); strbuf_release(&out);
if (sha1) if (hash)
git_SHA1_Final(sha1, &ctx); the_hash_algo->final_fn(hash, &ctx);
return has_conflicts; return has_conflicts;
} }
...@@ -462,8 +465,8 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz ...@@ -462,8 +465,8 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
* Scan the path for conflicts, do the "handle_path()" thing above, and * Scan the path for conflicts, do the "handle_path()" thing above, and
* return the number of conflict hunks found. * return the number of conflict hunks found.
*/ */
static int handle_file(struct index_state *istate, const char *path, static int handle_file(struct index_state *istate,
unsigned char *sha1, const char *output) const char *path, unsigned char *hash, const char *output)
{ {
int has_conflicts = 0; int has_conflicts = 0;
struct rerere_io_file io; struct rerere_io_file io;
...@@ -485,7 +488,7 @@ static int handle_file(struct index_state *istate, const char *path, ...@@ -485,7 +488,7 @@ static int handle_file(struct index_state *istate, const char *path,
} }
} }
has_conflicts = handle_path(sha1, (struct rerere_io *)&io, marker_size); has_conflicts = handle_path(hash, (struct rerere_io *)&io, marker_size);
fclose(io.input); fclose(io.input);
if (io.io.wrerror) if (io.io.wrerror)
...@@ -821,7 +824,7 @@ static int do_plain_rerere(struct repository *r, ...@@ -821,7 +824,7 @@ static int do_plain_rerere(struct repository *r,
*/ */
for (i = 0; i < conflict.nr; i++) { for (i = 0; i < conflict.nr; i++) {
struct rerere_id *id; struct rerere_id *id;
unsigned char sha1[20]; unsigned char hash[GIT_MAX_RAWSZ];
const char *path = conflict.items[i].string; const char *path = conflict.items[i].string;
int ret; int ret;
...@@ -830,7 +833,7 @@ static int do_plain_rerere(struct repository *r, ...@@ -830,7 +833,7 @@ static int do_plain_rerere(struct repository *r,
* conflict ID. No need to write anything out * conflict ID. No need to write anything out
* yet. * yet.
*/ */
ret = handle_file(r->index, path, sha1, NULL); ret = handle_file(r->index, path, hash, NULL);
if (ret != 0 && string_list_has_string(rr, path)) { if (ret != 0 && string_list_has_string(rr, path)) {
remove_variant(string_list_lookup(rr, path)->util); remove_variant(string_list_lookup(rr, path)->util);
string_list_remove(rr, path, 1); string_list_remove(rr, path, 1);
...@@ -838,7 +841,7 @@ static int do_plain_rerere(struct repository *r, ...@@ -838,7 +841,7 @@ static int do_plain_rerere(struct repository *r,
if (ret < 1) if (ret < 1)
continue; continue;
id = new_rerere_id(sha1); id = new_rerere_id(hash);
string_list_insert(rr, path)->util = id; string_list_insert(rr, path)->util = id;
/* Ensure that the directory exists. */ /* Ensure that the directory exists. */
...@@ -949,8 +952,8 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_) ...@@ -949,8 +952,8 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
return 0; return 0;
} }
static int handle_cache(struct index_state *istate, const char *path, static int handle_cache(struct index_state *istate,
unsigned char *sha1, const char *output) const char *path, unsigned char *hash, const char *output)
{ {
mmfile_t mmfile[3] = {{NULL}}; mmfile_t mmfile[3] = {{NULL}};
mmbuffer_t result = {NULL, 0}; mmbuffer_t result = {NULL, 0};
...@@ -1010,7 +1013,7 @@ static int handle_cache(struct index_state *istate, const char *path, ...@@ -1010,7 +1013,7 @@ static int handle_cache(struct index_state *istate, const char *path,
* Grab the conflict ID and optionally write the original * Grab the conflict ID and optionally write the original
* contents with conflict markers out. * contents with conflict markers out.
*/ */
has_conflicts = handle_path(sha1, (struct rerere_io *)&io, marker_size); has_conflicts = handle_path(hash, (struct rerere_io *)&io, marker_size);
strbuf_release(&io.input); strbuf_release(&io.input);
if (io.io.output) if (io.io.output)
fclose(io.io.output); fclose(io.io.output);
...@@ -1023,7 +1026,7 @@ static int rerere_forget_one_path(struct index_state *istate, ...@@ -1023,7 +1026,7 @@ static int rerere_forget_one_path(struct index_state *istate,
{ {
const char *filename; const char *filename;
struct rerere_id *id; struct rerere_id *id;
unsigned char sha1[20]; unsigned char hash[GIT_MAX_RAWSZ];
int ret; int ret;
struct string_list_item *item; struct string_list_item *item;
...@@ -1031,12 +1034,12 @@ static int rerere_forget_one_path(struct index_state *istate, ...@@ -1031,12 +1034,12 @@ static int rerere_forget_one_path(struct index_state *istate,
* Recreate the original conflict from the stages in the * Recreate the original conflict from the stages in the
* index and compute the conflict ID * index and compute the conflict ID
*/ */
ret = handle_cache(istate, path, sha1, NULL); ret = handle_cache(istate, path, hash, NULL);
if (ret < 1) if (ret < 1)
return error(_("could not parse conflict hunks in '%s'"), path); return error(_("could not parse conflict hunks in '%s'"), path);
/* Nuke the recorded resolution for the conflict */ /* Nuke the recorded resolution for the conflict */
id = new_rerere_id(sha1); id = new_rerere_id(hash);
for (id->variant = 0; for (id->variant = 0;
id->variant < id->collection->status_nr; id->variant < id->collection->status_nr;
...@@ -1048,7 +1051,7 @@ static int rerere_forget_one_path(struct index_state *istate, ...@@ -1048,7 +1051,7 @@ static int rerere_forget_one_path(struct index_state *istate,
if (!has_rerere_resolution(id)) if (!has_rerere_resolution(id))
continue; continue;
handle_cache(istate, path, sha1, rerere_path(id, "thisimage")); handle_cache(istate, path, hash, rerere_path(id, "thisimage"));
if (read_mmfile(&cur, rerere_path(id, "thisimage"))) { if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
free(cur.ptr); free(cur.ptr);
error(_("failed to update conflicted state in '%s'"), path); error(_("failed to update conflicted state in '%s'"), path);
...@@ -1080,7 +1083,7 @@ static int rerere_forget_one_path(struct index_state *istate, ...@@ -1080,7 +1083,7 @@ static int rerere_forget_one_path(struct index_state *istate,
* conflict in the working tree, run us again to record * conflict in the working tree, run us again to record
* the postimage. * the postimage.
*/ */
handle_cache(istate, path, sha1, rerere_path(id, "preimage")); handle_cache(istate, path, hash, rerere_path(id, "preimage"));
fprintf_ln(stderr, _("Updated preimage for '%s'"), path); fprintf_ln(stderr, _("Updated preimage for '%s'"), path);
/* /*
......
...@@ -144,7 +144,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u ...@@ -144,7 +144,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
return 0; return 0;
item->object.parsed = 1; item->object.parsed = 1;
if (size < GIT_SHA1_HEXSZ + 24) if (size < the_hash_algo->hexsz + 24)
return -1; return -1;
if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n') if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n')
return -1; return -1;
......
...@@ -1413,9 +1413,9 @@ static void read_alternate_refs(const char *path, ...@@ -1413,9 +1413,9 @@ static void read_alternate_refs(const char *path,
fh = xfdopen(cmd.out, "r"); fh = xfdopen(cmd.out, "r");
while (strbuf_getline_lf(&line, fh) != EOF) { while (strbuf_getline_lf(&line, fh) != EOF) {
struct object_id oid; struct object_id oid;
const char *p;
if (get_oid_hex(line.buf, &oid) || if (parse_oid_hex(line.buf, &oid, &p) || *p) {
line.buf[GIT_SHA1_HEXSZ]) {
warning(_("invalid line while parsing alternate refs: %s"), warning(_("invalid line while parsing alternate refs: %s"),
line.buf); line.buf);
break; break;
......
...@@ -444,6 +444,7 @@ static int do_reachable_revlist(struct child_process *cmd, ...@@ -444,6 +444,7 @@ static int do_reachable_revlist(struct child_process *cmd,
struct object *o; struct object *o;
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
int i; int i;
const unsigned hexsz = the_hash_algo->hexsz;
cmd->argv = argv; cmd->argv = argv;
cmd->git_cmd = 1; cmd->git_cmd = 1;
...@@ -462,7 +463,7 @@ static int do_reachable_revlist(struct child_process *cmd, ...@@ -462,7 +463,7 @@ static int do_reachable_revlist(struct child_process *cmd,
goto error; goto error;
namebuf[0] = '^'; namebuf[0] = '^';
namebuf[GIT_SHA1_HEXSZ + 1] = '\n'; namebuf[hexsz + 1] = '\n';
for (i = get_max_object_index(); 0 < i; ) { for (i = get_max_object_index(); 0 < i; ) {
o = get_indexed_object(--i); o = get_indexed_object(--i);
if (!o) if (!o)
...@@ -471,11 +472,11 @@ static int do_reachable_revlist(struct child_process *cmd, ...@@ -471,11 +472,11 @@ static int do_reachable_revlist(struct child_process *cmd,
o->flags &= ~TMP_MARK; o->flags &= ~TMP_MARK;
if (!is_our_ref(o)) if (!is_our_ref(o))
continue; continue;
memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ); memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0) if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
goto error; goto error;
} }
namebuf[GIT_SHA1_HEXSZ] = '\n'; namebuf[hexsz] = '\n';
for (i = 0; i < src->nr; i++) { for (i = 0; i < src->nr; i++) {
o = src->objects[i].item; o = src->objects[i].item;
if (is_our_ref(o)) { if (is_our_ref(o)) {
...@@ -485,8 +486,8 @@ static int do_reachable_revlist(struct child_process *cmd, ...@@ -485,8 +486,8 @@ static int do_reachable_revlist(struct child_process *cmd,
} }
if (reachable && o->type == OBJ_COMMIT) if (reachable && o->type == OBJ_COMMIT)
o->flags |= TMP_MARK; o->flags |= TMP_MARK;
memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ); memcpy(namebuf, oid_to_hex(&o->oid), hexsz);
if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0) if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
goto error; goto error;
} }
close(cmd->in); close(cmd->in);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册