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

File tree

11 files changed

+36
-35
lines changed

11 files changed

+36
-35
lines changed

apply.c

Lines changed: 2 additions & 2 deletions
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));

builtin/index-pack.c

Lines changed: 2 additions & 3 deletions
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();

builtin/replace.c

Lines changed: 1 addition & 1 deletion
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);

builtin/unpack-objects.c

Lines changed: 1 addition & 1 deletion
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);

cache-tree.c

Lines changed: 5 additions & 6 deletions
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;

cache.h

Lines changed: 4 additions & 1 deletion
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

convert.c

Lines changed: 3 additions & 3 deletions
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);

diffcore-rename.c

Lines changed: 2 additions & 2 deletions
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
}

dir.c

Lines changed: 2 additions & 2 deletions
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
}

log-tree.c

Lines changed: 1 addition & 1 deletion
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 */

0 commit comments

Comments
 (0)