Skip to content

Commit f070fac

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4b33e60 commit f070fac

11 files changed

+36
-35
lines changed

Diff for: apply.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3154,7 +3154,7 @@ static int apply_binary(struct apply_state *state,
31543154
* See if the old one matches what the patch
31553155
* applies to.
31563156
*/
3157-
hash_sha1_file(img->buf, img->len, blob_type, oid.hash);
3157+
hash_object_file(img->buf, img->len, blob_type, &oid);
31583158
if (strcmp(oid_to_hex(&oid), patch->old_sha1_prefix))
31593159
return error(_("the patch applies to '%s' (%s), "
31603160
"which does not match the "
@@ -3199,7 +3199,7 @@ static int apply_binary(struct apply_state *state,
31993199
name);
32003200

32013201
/* verify that the result matches */
3202-
hash_sha1_file(img->buf, img->len, blob_type, oid.hash);
3202+
hash_object_file(img->buf, img->len, blob_type, &oid);
32033203
if (strcmp(oid_to_hex(&oid), patch->new_sha1_prefix))
32043204
return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"),
32053205
name, patch->new_sha1_prefix, oid_to_hex(&oid));

Diff for: builtin/index-pack.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -958,9 +958,8 @@ static void resolve_delta(struct object_entry *delta_obj,
958958
free(delta_data);
959959
if (!result->data)
960960
bad_object(delta_obj->idx.offset, _("failed to apply delta"));
961-
hash_sha1_file(result->data, result->size,
962-
typename(delta_obj->real_type),
963-
delta_obj->idx.oid.hash);
961+
hash_object_file(result->data, result->size,
962+
typename(delta_obj->real_type), &delta_obj->idx.oid);
964963
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
965964
&delta_obj->idx.oid);
966965
counter_lock();

Diff for: builtin/replace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
355355
struct tag *tag;
356356
int i;
357357

358-
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);
358+
hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &tag_oid);
359359
tag = lookup_tag(&tag_oid);
360360
if (!tag)
361361
die(_("bad mergetag in commit '%s'"), ref);

Diff for: builtin/unpack-objects.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static void write_object(unsigned nr, enum object_type type,
258258
} else {
259259
struct object *obj;
260260
int eaten;
261-
hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
261+
hash_object_file(buf, size, typename(type), &obj_list[nr].oid);
262262
added_object(nr, type, buf, size);
263263
obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
264264
&eaten);

Diff for: cache-tree.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,14 @@ static int update_one(struct cache_tree *it,
400400
}
401401

402402
if (repair) {
403-
unsigned char sha1[20];
404-
hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
405-
if (has_sha1_file(sha1))
406-
hashcpy(it->oid.hash, sha1);
403+
struct object_id oid;
404+
hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
405+
if (has_sha1_file(oid.hash))
406+
oidcpy(&it->oid, &oid);
407407
else
408408
to_invalidate = 1;
409409
} else if (dryrun)
410-
hash_sha1_file(buffer.buf, buffer.len, tree_type,
411-
it->oid.hash);
410+
hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid);
412411
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
413412
strbuf_release(&buffer);
414413
return -1;

Diff for: cache.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,10 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
12361236

12371237
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
12381238
extern int sha1_object_info(const unsigned char *, unsigned long *);
1239-
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
1239+
1240+
extern int hash_object_file(const void *buf, unsigned long len,
1241+
const char *type, struct object_id *oid);
1242+
12401243
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
12411244
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
12421245

Diff for: convert.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
898898
static int ident_to_worktree(const char *path, const char *src, size_t len,
899899
struct strbuf *buf, int ident)
900900
{
901-
unsigned char sha1[20];
901+
struct object_id oid;
902902
char *to_free = NULL, *dollar, *spc;
903903
int cnt;
904904

@@ -912,7 +912,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
912912
/* are we "faking" in place editing ? */
913913
if (src == buf->buf)
914914
to_free = strbuf_detach(buf, NULL);
915-
hash_sha1_file(src, len, "blob", sha1);
915+
hash_object_file(src, len, "blob", &oid);
916916

917917
strbuf_grow(buf, len + cnt * 43);
918918
for (;;) {
@@ -969,7 +969,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
969969

970970
/* step 4: substitute */
971971
strbuf_addstr(buf, "Id: ");
972-
strbuf_add(buf, sha1_to_hex(sha1), 40);
972+
strbuf_addstr(buf, oid_to_hex(&oid));
973973
strbuf_addstr(buf, " $");
974974
}
975975
strbuf_add(buf, src, len);

Diff for: diffcore-rename.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
260260
if (!filespec->oid_valid) {
261261
if (diff_populate_filespec(filespec, 0))
262262
return 0;
263-
hash_sha1_file(filespec->data, filespec->size, "blob",
264-
filespec->oid.hash);
263+
hash_object_file(filespec->data, filespec->size, "blob",
264+
&filespec->oid);
265265
}
266266
return sha1hash(filespec->oid.hash);
267267
}

Diff for: dir.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
846846
oidcpy(&oid_stat->oid,
847847
&istate->cache[pos]->oid);
848848
else
849-
hash_sha1_file(buf, size, "blob",
850-
oid_stat->oid.hash);
849+
hash_object_file(buf, size, "blob",
850+
&oid_stat->oid);
851851
fill_stat_data(&oid_stat->stat, &st);
852852
oid_stat->valid = 1;
853853
}

Diff for: log-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ static void show_one_mergetag(struct commit *commit,
499499
int status, nth;
500500
size_t payload_size, gpg_message_offset;
501501

502-
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
502+
hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &oid);
503503
tag = lookup_tag(&oid);
504504
if (!tag)
505505
return; /* error message already given */

Diff for: sha1_file.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -788,16 +788,16 @@ void *xmmap(void *start, size_t length,
788788
int check_sha1_signature(const unsigned char *sha1, void *map,
789789
unsigned long size, const char *type)
790790
{
791-
unsigned char real_sha1[20];
791+
struct object_id real_oid;
792792
enum object_type obj_type;
793793
struct git_istream *st;
794794
git_SHA_CTX c;
795795
char hdr[32];
796796
int hdrlen;
797797

798798
if (map) {
799-
hash_sha1_file(map, size, type, real_sha1);
800-
return hashcmp(sha1, real_sha1) ? -1 : 0;
799+
hash_object_file(map, size, type, &real_oid);
800+
return hashcmp(sha1, real_oid.hash) ? -1 : 0;
801801
}
802802

803803
st = open_istream(sha1, &obj_type, &size, NULL);
@@ -822,9 +822,9 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
822822
break;
823823
git_SHA1_Update(&c, buf, readlen);
824824
}
825-
git_SHA1_Final(real_sha1, &c);
825+
git_SHA1_Final(real_oid.hash, &c);
826826
close_istream(st);
827-
return hashcmp(sha1, real_sha1) ? -1 : 0;
827+
return hashcmp(sha1, real_oid.hash) ? -1 : 0;
828828
}
829829

830830
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,
13171317
{
13181318
struct cached_object *co;
13191319

1320-
hash_sha1_file(buf, len, typename(type), oid->hash);
1320+
hash_object_file(buf, len, typename(type), oid);
13211321
if (has_sha1_file(oid->hash) || find_cached_object(oid->hash))
13221322
return 0;
13231323
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)
14851485
return 0;
14861486
}
14871487

1488-
int hash_sha1_file(const void *buf, unsigned long len, const char *type,
1489-
unsigned char *sha1)
1488+
int hash_object_file(const void *buf, unsigned long len, const char *type,
1489+
struct object_id *oid)
14901490
{
14911491
char hdr[32];
14921492
int hdrlen = sizeof(hdr);
1493-
write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
1493+
write_sha1_file_prepare(buf, len, type, oid->hash, hdr, &hdrlen);
14941494
return 0;
14951495
}
14961496

@@ -1769,7 +1769,7 @@ static int index_mem(struct object_id *oid, void *buf, size_t size,
17691769
if (write_object)
17701770
ret = write_sha1_file(buf, size, typename(type), oid->hash);
17711771
else
1772-
ret = hash_sha1_file(buf, size, typename(type), oid->hash);
1772+
ret = hash_object_file(buf, size, typename(type), oid);
17731773
if (re_allocated)
17741774
free(buf);
17751775
return ret;
@@ -1792,8 +1792,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
17921792
ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
17931793
oid->hash);
17941794
else
1795-
ret = hash_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1796-
oid->hash);
1795+
ret = hash_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1796+
oid);
17971797
strbuf_release(&sbuf);
17981798
return ret;
17991799
}
@@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
19071907
if (strbuf_readlink(&sb, path, st->st_size))
19081908
return error_errno("readlink(\"%s\")", path);
19091909
if (!(flags & HASH_WRITE_OBJECT))
1910-
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash);
1910+
hash_object_file(sb.buf, sb.len, blob_type, oid);
19111911
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
19121912
rc = error("%s: failed to insert into database", path);
19131913
strbuf_release(&sb);

0 commit comments

Comments
 (0)