Skip to content

Commit 6b8aa32

Browse files
committed
Merge branch 'po/object-id'
* po/object-id: sha1_file: convert index_stream to struct object_id sha1_file: convert hash_sha1_file_literally to struct object_id sha1_file: convert index_fd to struct object_id sha1_file: convert index_path to struct object_id read-cache: convert to struct object_id builtin/hash-object: convert to struct object_id
2 parents 18c88f9 + 7d5e1dc commit 6b8aa32

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int use_wt_file(const char *workdir, const char *name,
111111
int fd = open(buf.buf, O_RDONLY);
112112

113113
if (fd >= 0 &&
114-
!index_fd(wt_oid.hash, fd, &st, OBJ_BLOB, name, 0)) {
114+
!index_fd(&wt_oid, fd, &st, OBJ_BLOB, name, 0)) {
115115
if (is_null_oid(oid)) {
116116
oidcpy(oid, &wt_oid);
117117
use = 1;

builtin/hash-object.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
* needs to bypass the data conversion performed by, and the type
1717
* limitation imposed by, index_fd() and its callees.
1818
*/
19-
static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigned flags)
19+
static int hash_literally(struct object_id *oid, int fd, const char *type, unsigned flags)
2020
{
2121
struct strbuf buf = STRBUF_INIT;
2222
int ret;
2323

2424
if (strbuf_read(&buf, fd, 4096) < 0)
2525
ret = -1;
2626
else
27-
ret = hash_sha1_file_literally(buf.buf, buf.len, type, sha1, flags);
27+
ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid, flags);
2828
strbuf_release(&buf);
2929
return ret;
3030
}
@@ -33,16 +33,16 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
3333
int literally)
3434
{
3535
struct stat st;
36-
unsigned char sha1[20];
36+
struct object_id oid;
3737

3838
if (fstat(fd, &st) < 0 ||
3939
(literally
40-
? hash_literally(sha1, fd, type, flags)
41-
: index_fd(sha1, fd, &st, type_from_string(type), path, flags)))
40+
? hash_literally(&oid, fd, type, flags)
41+
: index_fd(&oid, fd, &st, type_from_string(type), path, flags)))
4242
die((flags & HASH_WRITE_OBJECT)
4343
? "Unable to add %s to database"
4444
: "Unable to hash %s", path);
45-
printf("%s\n", sha1_to_hex(sha1));
45+
printf("%s\n", oid_to_hex(&oid));
4646
maybe_flush_or_die(stdout, "hash to stdout");
4747
}
4848

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static void import_object(struct object_id *oid, enum object_type type,
269269

270270
if (fstat(fd, &st) < 0)
271271
die_errno("unable to fstat %s", filename);
272-
if (index_fd(oid->hash, fd, &st, type, NULL, flags) < 0)
272+
if (index_fd(oid, fd, &st, type, NULL, flags) < 0)
273273
die("unable to write object to database");
274274
/* index_fd close()s fd for us */
275275
}

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
280280
fill_stat_cache_info(ce, st);
281281
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
282282

283-
if (index_path(ce->oid.hash, path, st,
283+
if (index_path(&ce->oid, path, st,
284284
info_only ? 0 : HASH_WRITE_OBJECT)) {
285285
free(ce);
286286
return -1;

cache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ extern int ie_modified(const struct index_state *, const struct cache_entry *, s
684684

685685
#define HASH_WRITE_OBJECT 1
686686
#define HASH_FORMAT_CHECK 2
687-
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
688-
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags);
687+
extern int index_fd(struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
688+
extern int index_path(struct object_id *oid, const char *path, struct stat *st, unsigned flags);
689689

690690
/*
691691
* Record to sd the data from st that we use to check whether a file
@@ -1192,7 +1192,7 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
11921192
extern int sha1_object_info(const unsigned char *, unsigned long *);
11931193
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
11941194
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
1195-
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, unsigned char *sha1, unsigned flags);
1195+
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags);
11961196
extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
11971197
extern int force_object_loose(const unsigned char *sha1, time_t mtime);
11981198
extern int git_open_cloexec(const char *name, int flags);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4011,7 +4011,7 @@ static void diff_fill_oid_info(struct diff_filespec *one)
40114011
}
40124012
if (lstat(one->path, &st) < 0)
40134013
die_errno("stat '%s'", one->path);
4014-
if (index_path(one->oid.hash, one->path, &st, 0))
4014+
if (index_path(&one->oid, one->path, &st, 0))
40154015
die("cannot hash %s", one->path);
40164016
}
40174017
}

notes-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ int notes_merge_commit(struct notes_merge_options *o,
709709
/* write file as blob, and add to partial_tree */
710710
if (stat(path.buf, &st))
711711
die_errno("Failed to stat '%s'", path.buf);
712-
if (index_path(blob_oid.hash, path.buf, &st, HASH_WRITE_OBJECT))
712+
if (index_path(&blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
713713
die("Failed to write blob object from '%s'", path.buf);
714714
if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
715715
die("Failed to add resolved note '%s' to notes tree",

read-cache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st)
160160
int fd = git_open_cloexec(ce->name, O_RDONLY);
161161

162162
if (fd >= 0) {
163-
unsigned char sha1[20];
164-
if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0))
165-
match = hashcmp(sha1, ce->oid.hash);
163+
struct object_id oid;
164+
if (!index_fd(&oid, fd, st, OBJ_BLOB, ce->name, 0))
165+
match = oidcmp(&oid, &ce->oid);
166166
/* index_fd() closed the file descriptor already */
167167
}
168168
return match;
@@ -689,7 +689,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
689689
return 0;
690690
}
691691
if (!intent_only) {
692-
if (index_path(ce->oid.hash, path, st, HASH_WRITE_OBJECT)) {
692+
if (index_path(&ce->oid, path, st, HASH_WRITE_OBJECT)) {
693693
free(ce);
694694
return error("unable to index file %s", path);
695695
}

sha1_file.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,21 +3403,21 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
34033403
}
34043404

34053405
int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
3406-
unsigned char *sha1, unsigned flags)
3406+
struct object_id *oid, unsigned flags)
34073407
{
34083408
char *header;
34093409
int hdrlen, status = 0;
34103410

34113411
/* type string, SP, %lu of the length plus NUL must fit this */
34123412
hdrlen = strlen(type) + 32;
34133413
header = xmalloc(hdrlen);
3414-
write_sha1_file_prepare(buf, len, type, sha1, header, &hdrlen);
3414+
write_sha1_file_prepare(buf, len, type, oid->hash, header, &hdrlen);
34153415

34163416
if (!(flags & HASH_WRITE_OBJECT))
34173417
goto cleanup;
3418-
if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
3418+
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
34193419
goto cleanup;
3420-
status = write_loose_object(sha1, header, hdrlen, buf, len, 0);
3420+
status = write_loose_object(oid->hash, header, hdrlen, buf, len, 0);
34213421

34223422
cleanup:
34233423
free(header);
@@ -3621,14 +3621,14 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
36213621
* binary blobs, they generally do not want to get any conversion, and
36223622
* callers should avoid this code path when filters are requested.
36233623
*/
3624-
static int index_stream(unsigned char *sha1, int fd, size_t size,
3624+
static int index_stream(struct object_id *oid, int fd, size_t size,
36253625
enum object_type type, const char *path,
36263626
unsigned flags)
36273627
{
3628-
return index_bulk_checkin(sha1, fd, size, type, path, flags);
3628+
return index_bulk_checkin(oid->hash, fd, size, type, path, flags);
36293629
}
36303630

3631-
int index_fd(unsigned char *sha1, int fd, struct stat *st,
3631+
int index_fd(struct object_id *oid, int fd, struct stat *st,
36323632
enum object_type type, const char *path, unsigned flags)
36333633
{
36343634
int ret;
@@ -3638,21 +3638,21 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,
36383638
* die() for large files.
36393639
*/
36403640
if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
3641-
ret = index_stream_convert_blob(sha1, fd, path, flags);
3641+
ret = index_stream_convert_blob(oid->hash, fd, path, flags);
36423642
else if (!S_ISREG(st->st_mode))
3643-
ret = index_pipe(sha1, fd, type, path, flags);
3643+
ret = index_pipe(oid->hash, fd, type, path, flags);
36443644
else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
36453645
(path && would_convert_to_git(&the_index, path)))
3646-
ret = index_core(sha1, fd, xsize_t(st->st_size), type, path,
3646+
ret = index_core(oid->hash, fd, xsize_t(st->st_size), type, path,
36473647
flags);
36483648
else
3649-
ret = index_stream(sha1, fd, xsize_t(st->st_size), type, path,
3649+
ret = index_stream(oid, fd, xsize_t(st->st_size), type, path,
36503650
flags);
36513651
close(fd);
36523652
return ret;
36533653
}
36543654

3655-
int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags)
3655+
int index_path(struct object_id *oid, const char *path, struct stat *st, unsigned flags)
36563656
{
36573657
int fd;
36583658
struct strbuf sb = STRBUF_INIT;
@@ -3662,22 +3662,22 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned
36623662
fd = open(path, O_RDONLY);
36633663
if (fd < 0)
36643664
return error_errno("open(\"%s\")", path);
3665-
if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0)
3665+
if (index_fd(oid, fd, st, OBJ_BLOB, path, flags) < 0)
36663666
return error("%s: failed to insert into database",
36673667
path);
36683668
break;
36693669
case S_IFLNK:
36703670
if (strbuf_readlink(&sb, path, st->st_size))
36713671
return error_errno("readlink(\"%s\")", path);
36723672
if (!(flags & HASH_WRITE_OBJECT))
3673-
hash_sha1_file(sb.buf, sb.len, blob_type, sha1);
3674-
else if (write_sha1_file(sb.buf, sb.len, blob_type, sha1))
3673+
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash);
3674+
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
36753675
return error("%s: failed to insert into database",
36763676
path);
36773677
strbuf_release(&sb);
36783678
break;
36793679
case S_IFDIR:
3680-
return resolve_gitlink_ref(path, "HEAD", sha1);
3680+
return resolve_gitlink_ref(path, "HEAD", oid->hash);
36813681
default:
36823682
return error("%s: unsupported file type", path);
36833683
}

0 commit comments

Comments
 (0)