sha1_file: convert hash_sha1_file to object_id

Convert the declaration and definition of hash_sha1_file to use
struct object_id and adjust all function calls.

Rename this function to hash_object_file.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patryk Obara 2018-01-28 01:13:13 +01:00 committed by Junio C Hamano
parent 4b33e60201
commit f070faccc1
11 changed files with 36 additions and 35 deletions

View File

@ -3154,7 +3154,7 @@ static int apply_binary(struct apply_state *state,
* See if the old one matches what the patch * See if the old one matches what the patch
* applies to. * applies to.
*/ */
hash_sha1_file(img->buf, img->len, blob_type, oid.hash); 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_sha1_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 "
@ -3199,7 +3199,7 @@ static int apply_binary(struct apply_state *state,
name); name);
/* verify that the result matches */ /* verify that the result matches */
hash_sha1_file(img->buf, img->len, blob_type, oid.hash); 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_sha1_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_sha1_prefix, oid_to_hex(&oid));

View File

@ -958,9 +958,8 @@ static void resolve_delta(struct object_entry *delta_obj,
free(delta_data); free(delta_data);
if (!result->data) if (!result->data)
bad_object(delta_obj->idx.offset, _("failed to apply delta")); bad_object(delta_obj->idx.offset, _("failed to apply delta"));
hash_sha1_file(result->data, result->size, hash_object_file(result->data, result->size,
typename(delta_obj->real_type), typename(delta_obj->real_type), &delta_obj->idx.oid);
delta_obj->idx.oid.hash);
sha1_object(result->data, NULL, result->size, delta_obj->real_type, sha1_object(result->data, NULL, result->size, delta_obj->real_type,
&delta_obj->idx.oid); &delta_obj->idx.oid);
counter_lock(); counter_lock();

View File

@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
struct tag *tag; struct tag *tag;
int i; int i;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash); hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &tag_oid);
tag = lookup_tag(&tag_oid); tag = lookup_tag(&tag_oid);
if (!tag) if (!tag)
die(_("bad mergetag in commit '%s'"), ref); die(_("bad mergetag in commit '%s'"), ref);

View File

@ -258,7 +258,7 @@ static void write_object(unsigned nr, enum object_type type,
} else { } else {
struct object *obj; struct object *obj;
int eaten; int eaten;
hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash); hash_object_file(buf, size, typename(type), &obj_list[nr].oid);
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf, obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
&eaten); &eaten);

View File

@ -400,15 +400,14 @@ static int update_one(struct cache_tree *it,
} }
if (repair) { if (repair) {
unsigned char sha1[20]; struct object_id oid;
hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1); hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
if (has_sha1_file(sha1)) if (has_sha1_file(oid.hash))
hashcpy(it->oid.hash, sha1); oidcpy(&it->oid, &oid);
else else
to_invalidate = 1; to_invalidate = 1;
} else if (dryrun) } else if (dryrun)
hash_sha1_file(buffer.buf, buffer.len, tree_type, hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid);
it->oid.hash);
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) { else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
strbuf_release(&buffer); strbuf_release(&buffer);
return -1; return -1;

View File

@ -1236,7 +1236,10 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */ /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern int sha1_object_info(const unsigned char *, unsigned long *); extern int sha1_object_info(const unsigned char *, unsigned long *);
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
extern int hash_object_file(const void *buf, unsigned long len,
const char *type, struct object_id *oid);
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1); extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags); extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);

View File

@ -898,7 +898,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
static int ident_to_worktree(const char *path, const char *src, size_t len, static int ident_to_worktree(const char *path, const char *src, size_t len,
struct strbuf *buf, int ident) struct strbuf *buf, int ident)
{ {
unsigned char sha1[20]; struct object_id oid;
char *to_free = NULL, *dollar, *spc; char *to_free = NULL, *dollar, *spc;
int cnt; int cnt;
@ -912,7 +912,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
/* are we "faking" in place editing ? */ /* are we "faking" in place editing ? */
if (src == buf->buf) if (src == buf->buf)
to_free = strbuf_detach(buf, NULL); to_free = strbuf_detach(buf, NULL);
hash_sha1_file(src, len, "blob", sha1); hash_object_file(src, len, "blob", &oid);
strbuf_grow(buf, len + cnt * 43); strbuf_grow(buf, len + cnt * 43);
for (;;) { for (;;) {
@ -969,7 +969,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
/* step 4: substitute */ /* step 4: substitute */
strbuf_addstr(buf, "Id: "); strbuf_addstr(buf, "Id: ");
strbuf_add(buf, sha1_to_hex(sha1), 40); strbuf_addstr(buf, oid_to_hex(&oid));
strbuf_addstr(buf, " $"); strbuf_addstr(buf, " $");
} }
strbuf_add(buf, src, len); strbuf_add(buf, src, len);

View File

@ -260,8 +260,8 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
if (!filespec->oid_valid) { if (!filespec->oid_valid) {
if (diff_populate_filespec(filespec, 0)) if (diff_populate_filespec(filespec, 0))
return 0; return 0;
hash_sha1_file(filespec->data, filespec->size, "blob", hash_object_file(filespec->data, filespec->size, "blob",
filespec->oid.hash); &filespec->oid);
} }
return sha1hash(filespec->oid.hash); return sha1hash(filespec->oid.hash);
} }

4
dir.c
View File

@ -846,8 +846,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
oidcpy(&oid_stat->oid, oidcpy(&oid_stat->oid,
&istate->cache[pos]->oid); &istate->cache[pos]->oid);
else else
hash_sha1_file(buf, size, "blob", hash_object_file(buf, size, "blob",
oid_stat->oid.hash); &oid_stat->oid);
fill_stat_data(&oid_stat->stat, &st); fill_stat_data(&oid_stat->stat, &st);
oid_stat->valid = 1; oid_stat->valid = 1;
} }

View File

@ -499,7 +499,7 @@ static void show_one_mergetag(struct commit *commit,
int status, nth; int status, nth;
size_t payload_size, gpg_message_offset; size_t payload_size, gpg_message_offset;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash); hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &oid);
tag = lookup_tag(&oid); tag = lookup_tag(&oid);
if (!tag) if (!tag)
return; /* error message already given */ return; /* error message already given */

View File

@ -788,7 +788,7 @@ void *xmmap(void *start, size_t length,
int check_sha1_signature(const unsigned char *sha1, void *map, int check_sha1_signature(const unsigned char *sha1, void *map,
unsigned long size, const char *type) unsigned long size, const char *type)
{ {
unsigned char real_sha1[20]; struct object_id real_oid;
enum object_type obj_type; enum object_type obj_type;
struct git_istream *st; struct git_istream *st;
git_SHA_CTX c; git_SHA_CTX c;
@ -796,8 +796,8 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
int hdrlen; int hdrlen;
if (map) { if (map) {
hash_sha1_file(map, size, type, real_sha1); hash_object_file(map, size, type, &real_oid);
return hashcmp(sha1, real_sha1) ? -1 : 0; return hashcmp(sha1, real_oid.hash) ? -1 : 0;
} }
st = open_istream(sha1, &obj_type, &size, NULL); st = open_istream(sha1, &obj_type, &size, NULL);
@ -822,9 +822,9 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
break; break;
git_SHA1_Update(&c, buf, readlen); git_SHA1_Update(&c, buf, readlen);
} }
git_SHA1_Final(real_sha1, &c); git_SHA1_Final(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)
@ -1317,7 +1317,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
{ {
struct cached_object *co; struct cached_object *co;
hash_sha1_file(buf, len, typename(type), oid->hash); hash_object_file(buf, len, typename(type), oid);
if (has_sha1_file(oid->hash) || find_cached_object(oid->hash)) if (has_sha1_file(oid->hash) || find_cached_object(oid->hash))
return 0; return 0;
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc); ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
@ -1485,12 +1485,12 @@ static int write_buffer(int fd, const void *buf, size_t len)
return 0; return 0;
} }
int hash_sha1_file(const void *buf, unsigned long len, const char *type, int hash_object_file(const void *buf, unsigned long len, const char *type,
unsigned char *sha1) struct object_id *oid)
{ {
char hdr[32]; char hdr[32];
int hdrlen = sizeof(hdr); int hdrlen = sizeof(hdr);
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen); write_sha1_file_prepare(buf, len, type, oid->hash, hdr, &hdrlen);
return 0; return 0;
} }
@ -1769,7 +1769,7 @@ static int index_mem(struct object_id *oid, void *buf, size_t size,
if (write_object) if (write_object)
ret = write_sha1_file(buf, size, typename(type), oid->hash); ret = write_sha1_file(buf, size, typename(type), oid->hash);
else else
ret = hash_sha1_file(buf, size, typename(type), oid->hash); ret = hash_object_file(buf, size, typename(type), oid);
if (re_allocated) if (re_allocated)
free(buf); free(buf);
return ret; return ret;
@ -1792,8 +1792,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB), ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
oid->hash); oid->hash);
else else
ret = hash_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB), ret = hash_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
oid->hash); oid);
strbuf_release(&sbuf); strbuf_release(&sbuf);
return ret; return ret;
} }
@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
if (strbuf_readlink(&sb, path, st->st_size)) if (strbuf_readlink(&sb, path, st->st_size))
return error_errno("readlink(\"%s\")", path); return error_errno("readlink(\"%s\")", path);
if (!(flags & HASH_WRITE_OBJECT)) if (!(flags & HASH_WRITE_OBJECT))
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash); hash_object_file(sb.buf, sb.len, blob_type, oid);
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash)) else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
rc = error("%s: failed to insert into database", path); rc = error("%s: failed to insert into database", path);
strbuf_release(&sb); strbuf_release(&sb);