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>
Patryk Obara committed
Jan 28, 2018 at 01:13 UTC
f070faccc1a446e44463560add8434efa8c6bed1
11 files changed
+36
-35
apply.c
+2
-2
@@ -3154,7 +3154,7 @@ static int apply_binary(struct apply_state *state,
3154
* See if the old one matches what the patch
3155
* applies to.
3156
*/
3157
- hash_sha1_file(img->buf, img->len, blob_type, oid.hash);
3157
+ hash_object_file(img->buf, img->len, blob_type, &oid);
3158
if (strcmp(oid_to_hex(&oid), patch->old_sha1_prefix))
3159
return error(_("the patch applies to '%s' (%s), "
3160
"which does not match the "
@@ -3199,7 +3199,7 @@ static int apply_binary(struct apply_state *state,
3199
name);
3200
3201
/* 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);
3203
if (strcmp(oid_to_hex(&oid), patch->new_sha1_prefix))
3204
return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"),
3205
name, patch->new_sha1_prefix, oid_to_hex(&oid));
builtin/index-pack.c
+2
-3
@@ -958,9 +958,8 @@ static void resolve_delta(struct object_entry *delta_obj,
958
free(delta_data);
959
if (!result->data)
960
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);
963
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
964
&delta_obj->idx.oid);
965
counter_lock();
builtin/replace.c
+1
-1
@@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
355
struct tag *tag;
356
int i;
357
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);
359
tag = lookup_tag(&tag_oid);
360
if (!tag)
361
die(_("bad mergetag in commit '%s'"), ref);
builtin/unpack-objects.c
+1
-1
@@ -258,7 +258,7 @@ static void write_object(unsigned nr, enum object_type type,
258
} else {
259
struct object *obj;
260
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);
262
added_object(nr, type, buf, size);
263
obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
264
&eaten);
cache-tree.c
+5
-6
@@ -400,15 +400,14 @@ static int update_one(struct cache_tree *it,
400
}
401
402
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);
407
else
408
to_invalidate = 1;
409
} 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);
411
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
412
strbuf_release(&buffer);
413
return -1;
cache.h
+4
-1
@@ -1236,7 +1236,10 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
1236
1237
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
1238
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
+
1243
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
1244
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
1245
convert.c
+3
-3
@@ -898,7 +898,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
898
static int ident_to_worktree(const char *path, const char *src, size_t len,
899
struct strbuf *buf, int ident)
900
{
901
- unsigned char sha1[20];
901
+ struct object_id oid;
902
char *to_free = NULL, *dollar, *spc;
903
int cnt;
904
@@ -912,7 +912,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
912
/* are we "faking" in place editing ? */
913
if (src == buf->buf)
914
to_free = strbuf_detach(buf, NULL);
915
- hash_sha1_file(src, len, "blob", sha1);
915
+ hash_object_file(src, len, "blob", &oid);
916
917
strbuf_grow(buf, len + cnt * 43);
918
for (;;) {
@@ -969,7 +969,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
969
970
/* step 4: substitute */
971
strbuf_addstr(buf, "Id: ");
972
- strbuf_add(buf, sha1_to_hex(sha1), 40);
972
+ strbuf_addstr(buf, oid_to_hex(&oid));
973
strbuf_addstr(buf, " $");
974
}
975
strbuf_add(buf, src, len);
diffcore-rename.c
+2
-2
@@ -260,8 +260,8 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
260
if (!filespec->oid_valid) {
261
if (diff_populate_filespec(filespec, 0))
262
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);
265
}
266
return sha1hash(filespec->oid.hash);
267
}
dir.c
+2
-2
@@ -846,8 +846,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
846
oidcpy(&oid_stat->oid,
847
&istate->cache[pos]->oid);
848
else
849
- hash_sha1_file(buf, size, "blob",
850
- oid_stat->oid.hash);
849
+ hash_object_file(buf, size, "blob",
850
+ &oid_stat->oid);
851
fill_stat_data(&oid_stat->stat, &st);
852
oid_stat->valid = 1;
853
}
log-tree.c
+1
-1
@@ -499,7 +499,7 @@ static void show_one_mergetag(struct commit *commit,
499
int status, nth;
500
size_t payload_size, gpg_message_offset;
501
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);
503
tag = lookup_tag(&oid);
504
if (!tag)
505
return; /* error message already given */
sha1_file.c
+13
-13
@@ -788,7 +788,7 @@ void *xmmap(void *start, size_t length,
788
int check_sha1_signature(const unsigned char *sha1, void *map,
789
unsigned long size, const char *type)
790
{
791
- unsigned char real_sha1[20];
791
+ struct object_id real_oid;
792
enum object_type obj_type;
793
struct git_istream *st;
794
git_SHA_CTX c;
@@ -796,8 +796,8 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
796
int hdrlen;
797
798
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;
801
}
802
803
st = open_istream(sha1, &obj_type, &size, NULL);
@@ -822,9 +822,9 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
822
break;
823
git_SHA1_Update(&c, buf, readlen);
824
}
825
- git_SHA1_Final(real_sha1, &c);
825
+ git_SHA1_Final(real_oid.hash, &c);
826
close_istream(st);
827
- return hashcmp(sha1, real_sha1) ? -1 : 0;
827
+ return hashcmp(sha1, real_oid.hash) ? -1 : 0;
828
}
829
830
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,
1317
{
1318
struct cached_object *co;
1319
1320
- hash_sha1_file(buf, len, typename(type), oid->hash);
1320
+ hash_object_file(buf, len, typename(type), oid);
1321
if (has_sha1_file(oid->hash) || find_cached_object(oid->hash))
1322
return 0;
1323
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)
1485
return 0;
1486
}
1487
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)
1490
{
1491
char hdr[32];
1492
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);
1494
return 0;
1495
}
1496
@@ -1769,7 +1769,7 @@ static int index_mem(struct object_id *oid, void *buf, size_t size,
1769
if (write_object)
1770
ret = write_sha1_file(buf, size, typename(type), oid->hash);
1771
else
1772
- ret = hash_sha1_file(buf, size, typename(type), oid->hash);
1772
+ ret = hash_object_file(buf, size, typename(type), oid);
1773
if (re_allocated)
1774
free(buf);
1775
return ret;
@@ -1792,8 +1792,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
1792
ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1793
oid->hash);
1794
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);
1797
strbuf_release(&sbuf);
1798
return ret;
1799
}
@@ -1907,7 +1907,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
1907
if (strbuf_readlink(&sb, path, st->st_size))
1908
return error_errno("readlink(\"%s\")", path);
1909
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);
1911
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
1912
rc = error("%s: failed to insert into database", path);
1913
strbuf_release(&sb);