From eab8bf292b9616772245717ce8069ec1a4354bd4 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 20 Aug 2017 22:09:26 +0200 Subject: [PATCH 1/6] builtin/hash-object: convert to struct object_id Signed-off-by: Patryk Obara Signed-off-by: Junio C Hamano --- builtin/hash-object.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/hash-object.c b/builtin/hash-object.c index d04baf999a..1c0f0f3327 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -16,7 +16,7 @@ * needs to bypass the data conversion performed by, and the type * limitation imposed by, index_fd() and its callees. */ -static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigned flags) +static int hash_literally(struct object_id *oid, int fd, const char *type, unsigned flags) { struct strbuf buf = STRBUF_INIT; int ret; @@ -24,7 +24,7 @@ static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigne if (strbuf_read(&buf, fd, 4096) < 0) ret = -1; else - ret = hash_sha1_file_literally(buf.buf, buf.len, type, sha1, flags); + ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid->hash, flags); strbuf_release(&buf); return ret; } @@ -33,16 +33,16 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags, int literally) { struct stat st; - unsigned char sha1[20]; + struct object_id oid; if (fstat(fd, &st) < 0 || (literally - ? hash_literally(sha1, fd, type, flags) - : index_fd(sha1, fd, &st, type_from_string(type), path, flags))) + ? hash_literally(&oid, fd, type, flags) + : index_fd(oid.hash, fd, &st, type_from_string(type), path, flags))) die((flags & HASH_WRITE_OBJECT) ? "Unable to add %s to database" : "Unable to hash %s", path); - printf("%s\n", sha1_to_hex(sha1)); + printf("%s\n", oid_to_hex(&oid)); maybe_flush_or_die(stdout, "hash to stdout"); } From bebfecb94c5c71091a07ebbd300740990d3266c7 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 20 Aug 2017 22:09:27 +0200 Subject: [PATCH 2/6] read-cache: convert to struct object_id Replace hashcmp with oidcmp. Signed-off-by: Patryk Obara Signed-off-by: Junio C Hamano --- read-cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/read-cache.c b/read-cache.c index acfb028f48..72856085f2 100644 --- a/read-cache.c +++ b/read-cache.c @@ -160,9 +160,9 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st) int fd = git_open_cloexec(ce->name, O_RDONLY); if (fd >= 0) { - unsigned char sha1[20]; - if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0)) - match = hashcmp(sha1, ce->oid.hash); + struct object_id oid; + if (!index_fd(oid.hash, fd, st, OBJ_BLOB, ce->name, 0)) + match = oidcmp(&oid, &ce->oid); /* index_fd() closed the file descriptor already */ } return match; From 98e019b067ac8a34e06f9c412f14a080c7c4dc0d Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 20 Aug 2017 22:09:28 +0200 Subject: [PATCH 3/6] sha1_file: convert index_path to struct object_id Convert all remaining callers as well. Signed-off-by: Patryk Obara Signed-off-by: Junio C Hamano --- builtin/update-index.c | 2 +- cache.h | 2 +- diff.c | 2 +- notes-merge.c | 2 +- read-cache.c | 2 +- sha1_file.c | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 56721cf03d..d562f2ec69 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -280,7 +280,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len fill_stat_cache_info(ce, st); ce->ce_mode = ce_mode_from_stat(old, st->st_mode); - if (index_path(ce->oid.hash, path, st, + if (index_path(&ce->oid, path, st, info_only ? 0 : HASH_WRITE_OBJECT)) { free(ce); return -1; diff --git a/cache.h b/cache.h index 1c69d2a05a..380868ddb2 100644 --- a/cache.h +++ b/cache.h @@ -685,7 +685,7 @@ extern int ie_modified(const struct index_state *, const struct cache_entry *, s #define HASH_WRITE_OBJECT 1 #define HASH_FORMAT_CHECK 2 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); -extern int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags); +extern int index_path(struct object_id *oid, const char *path, struct stat *st, unsigned flags); /* * Record to sd the data from st that we use to check whether a file diff --git a/diff.c b/diff.c index 9c38258030..65f8d13670 100644 --- a/diff.c +++ b/diff.c @@ -3246,7 +3246,7 @@ static void diff_fill_oid_info(struct diff_filespec *one) } if (lstat(one->path, &st) < 0) die_errno("stat '%s'", one->path); - if (index_path(one->oid.hash, one->path, &st, 0)) + if (index_path(&one->oid, one->path, &st, 0)) die("cannot hash %s", one->path); } } diff --git a/notes-merge.c b/notes-merge.c index c12b354f10..744c685576 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -709,7 +709,7 @@ int notes_merge_commit(struct notes_merge_options *o, /* write file as blob, and add to partial_tree */ if (stat(path.buf, &st)) die_errno("Failed to stat '%s'", path.buf); - if (index_path(blob_oid.hash, path.buf, &st, HASH_WRITE_OBJECT)) + if (index_path(&blob_oid, path.buf, &st, HASH_WRITE_OBJECT)) die("Failed to write blob object from '%s'", path.buf); if (add_note(partial_tree, &obj_oid, &blob_oid, NULL)) die("Failed to add resolved note '%s' to notes tree", diff --git a/read-cache.c b/read-cache.c index 72856085f2..17f19a11ff 100644 --- a/read-cache.c +++ b/read-cache.c @@ -689,7 +689,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, return 0; } if (!intent_only) { - if (index_path(ce->oid.hash, path, st, HASH_WRITE_OBJECT)) { + if (index_path(&ce->oid, path, st, HASH_WRITE_OBJECT)) { free(ce); return error("unable to index file %s", path); } diff --git a/sha1_file.c b/sha1_file.c index b60ae15f70..6a2a48ba20 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3686,7 +3686,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, return ret; } -int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags) +int index_path(struct object_id *oid, const char *path, struct stat *st, unsigned flags) { int fd; struct strbuf sb = STRBUF_INIT; @@ -3696,7 +3696,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned fd = open(path, O_RDONLY); if (fd < 0) return error_errno("open(\"%s\")", path); - if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0) + if (index_fd(oid->hash, fd, st, OBJ_BLOB, path, flags) < 0) return error("%s: failed to insert into database", path); break; @@ -3704,14 +3704,14 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned if (strbuf_readlink(&sb, path, st->st_size)) return error_errno("readlink(\"%s\")", path); if (!(flags & HASH_WRITE_OBJECT)) - hash_sha1_file(sb.buf, sb.len, blob_type, sha1); - else if (write_sha1_file(sb.buf, sb.len, blob_type, sha1)) + hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash); + else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash)) return error("%s: failed to insert into database", path); strbuf_release(&sb); break; case S_IFDIR: - return resolve_gitlink_ref(path, "HEAD", sha1); + return resolve_gitlink_ref(path, "HEAD", oid->hash); default: return error("%s: unsupported file type", path); } From e3506559d476ccf94c923c30a15500b46204e146 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 20 Aug 2017 22:09:29 +0200 Subject: [PATCH 4/6] sha1_file: convert index_fd to struct object_id Convert all remaining callers as well. Signed-off-by: Patryk Obara Signed-off-by: Junio C Hamano --- builtin/difftool.c | 2 +- builtin/hash-object.c | 2 +- builtin/replace.c | 2 +- cache.h | 2 +- read-cache.c | 2 +- sha1_file.c | 12 ++++++------ 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index 8864d846f8..b2d3ba7539 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -111,7 +111,7 @@ static int use_wt_file(const char *workdir, const char *name, int fd = open(buf.buf, O_RDONLY); if (fd >= 0 && - !index_fd(wt_oid.hash, fd, &st, OBJ_BLOB, name, 0)) { + !index_fd(&wt_oid, fd, &st, OBJ_BLOB, name, 0)) { if (is_null_oid(oid)) { oidcpy(oid, &wt_oid); use = 1; diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 1c0f0f3327..8a58ce085a 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -38,7 +38,7 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags, if (fstat(fd, &st) < 0 || (literally ? hash_literally(&oid, fd, type, flags) - : index_fd(oid.hash, fd, &st, type_from_string(type), path, flags))) + : index_fd(&oid, fd, &st, type_from_string(type), path, flags))) die((flags & HASH_WRITE_OBJECT) ? "Unable to add %s to database" : "Unable to hash %s", path); diff --git a/builtin/replace.c b/builtin/replace.c index f4a85a165b..3e71a77152 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -269,7 +269,7 @@ static void import_object(struct object_id *oid, enum object_type type, if (fstat(fd, &st) < 0) die_errno("unable to fstat %s", filename); - if (index_fd(oid->hash, fd, &st, type, NULL, flags) < 0) + if (index_fd(oid, fd, &st, type, NULL, flags) < 0) die("unable to write object to database"); /* index_fd close()s fd for us */ } diff --git a/cache.h b/cache.h index 380868ddb2..eaf3603777 100644 --- a/cache.h +++ b/cache.h @@ -684,7 +684,7 @@ extern int ie_modified(const struct index_state *, const struct cache_entry *, s #define HASH_WRITE_OBJECT 1 #define HASH_FORMAT_CHECK 2 -extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); +extern int index_fd(struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); extern int index_path(struct object_id *oid, const char *path, struct stat *st, unsigned flags); /* diff --git a/read-cache.c b/read-cache.c index 17f19a11ff..9b41058569 100644 --- a/read-cache.c +++ b/read-cache.c @@ -161,7 +161,7 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st) if (fd >= 0) { struct object_id oid; - if (!index_fd(oid.hash, fd, st, OBJ_BLOB, ce->name, 0)) + if (!index_fd(&oid, fd, st, OBJ_BLOB, ce->name, 0)) match = oidcmp(&oid, &ce->oid); /* index_fd() closed the file descriptor already */ } diff --git a/sha1_file.c b/sha1_file.c index 6a2a48ba20..132b25bd74 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3662,7 +3662,7 @@ static int index_stream(unsigned char *sha1, int fd, size_t size, return index_bulk_checkin(sha1, fd, size, type, path, flags); } -int index_fd(unsigned char *sha1, int fd, struct stat *st, +int index_fd(struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags) { int ret; @@ -3672,15 +3672,15 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, * die() for large files. */ if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path)) - ret = index_stream_convert_blob(sha1, fd, path, flags); + ret = index_stream_convert_blob(oid->hash, fd, path, flags); else if (!S_ISREG(st->st_mode)) - ret = index_pipe(sha1, fd, type, path, flags); + ret = index_pipe(oid->hash, fd, type, path, flags); else if (st->st_size <= big_file_threshold || type != OBJ_BLOB || (path && would_convert_to_git(&the_index, path))) - ret = index_core(sha1, fd, xsize_t(st->st_size), type, path, + ret = index_core(oid->hash, fd, xsize_t(st->st_size), type, path, flags); else - ret = index_stream(sha1, fd, xsize_t(st->st_size), type, path, + ret = index_stream(oid->hash, fd, xsize_t(st->st_size), type, path, flags); close(fd); return ret; @@ -3696,7 +3696,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne fd = open(path, O_RDONLY); if (fd < 0) return error_errno("open(\"%s\")", path); - if (index_fd(oid->hash, fd, st, OBJ_BLOB, path, flags) < 0) + if (index_fd(oid, fd, st, OBJ_BLOB, path, flags) < 0) return error("%s: failed to insert into database", path); break; From da77611d73f3173aa49d362bd7b12a608fb34b94 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 20 Aug 2017 22:09:30 +0200 Subject: [PATCH 5/6] sha1_file: convert hash_sha1_file_literally to struct object_id Convert all remaining callers as well. Signed-off-by: Patryk Obara Signed-off-by: Junio C Hamano --- builtin/hash-object.c | 2 +- cache.h | 2 +- sha1_file.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 8a58ce085a..c532ff9320 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -24,7 +24,7 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig if (strbuf_read(&buf, fd, 4096) < 0) ret = -1; else - ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid->hash, flags); + ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid, flags); strbuf_release(&buf); return ret; } diff --git a/cache.h b/cache.h index eaf3603777..237adb59d4 100644 --- a/cache.h +++ b/cache.h @@ -1199,7 +1199,7 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh 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 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, unsigned char *sha1, unsigned flags); +extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, struct object_id *oid, unsigned flags); extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int force_object_loose(const unsigned char *sha1, time_t mtime); extern int git_open_cloexec(const char *name, int flags); diff --git a/sha1_file.c b/sha1_file.c index 132b25bd74..c9a230a1e2 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3437,7 +3437,7 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign } int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, - unsigned char *sha1, unsigned flags) + struct object_id *oid, unsigned flags) { char *header; int hdrlen, status = 0; @@ -3445,13 +3445,13 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ /* type string, SP, %lu of the length plus NUL must fit this */ hdrlen = strlen(type) + 32; header = xmalloc(hdrlen); - write_sha1_file_prepare(buf, len, type, sha1, header, &hdrlen); + write_sha1_file_prepare(buf, len, type, oid->hash, header, &hdrlen); if (!(flags & HASH_WRITE_OBJECT)) goto cleanup; - if (freshen_packed_object(sha1) || freshen_loose_object(sha1)) + if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash)) goto cleanup; - status = write_loose_object(sha1, header, hdrlen, buf, len, 0); + status = write_loose_object(oid->hash, header, hdrlen, buf, len, 0); cleanup: free(header); From 7d5e1dc333e9dc2493405c7c6d74f0c0d8b93455 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sun, 20 Aug 2017 22:09:31 +0200 Subject: [PATCH 6/6] sha1_file: convert index_stream to struct object_id Signed-off-by: Patryk Obara Signed-off-by: Junio C Hamano --- sha1_file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index c9a230a1e2..103acfcb77 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3655,11 +3655,11 @@ static int index_core(unsigned char *sha1, int fd, size_t size, * binary blobs, they generally do not want to get any conversion, and * callers should avoid this code path when filters are requested. */ -static int index_stream(unsigned char *sha1, int fd, size_t size, +static int index_stream(struct object_id *oid, int fd, size_t size, enum object_type type, const char *path, unsigned flags) { - return index_bulk_checkin(sha1, fd, size, type, path, flags); + return index_bulk_checkin(oid->hash, fd, size, type, path, flags); } int index_fd(struct object_id *oid, int fd, struct stat *st, @@ -3680,7 +3680,7 @@ int index_fd(struct object_id *oid, int fd, struct stat *st, ret = index_core(oid->hash, fd, xsize_t(st->st_size), type, path, flags); else - ret = index_stream(oid->hash, fd, xsize_t(st->st_size), type, path, + ret = index_stream(oid, fd, xsize_t(st->st_size), type, path, flags); close(fd); return ret;