From: Junio C Hamano Date: Thu, 7 Feb 2019 06:05:27 +0000 (-0800) Subject: Merge branch 'jk/loose-object-cache-oid' X-Git-Tag: v2.21.0-rc0~12 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cba595ab1a7764aecfde2e8e59994f89b2cd2f2e Merge branch 'jk/loose-object-cache-oid' Code clean-up. * jk/loose-object-cache-oid: prefer "hash mismatch" to "sha1 mismatch" sha1-file: avoid "sha1 file" for generic use in messages sha1-file: prefer "loose object file" to "sha1 file" in messages sha1-file: drop has_sha1_file() convert has_sha1_file() callers to has_object_file() sha1-file: convert pass-through functions to object_id sha1-file: modernize loose header/stream functions sha1-file: modernize loose object file functions http: use struct object_id instead of bare sha1 update comment references to sha1_object_info() sha1-file: fix outdated sha1 comment references --- cba595ab1a7764aecfde2e8e59994f89b2cd2f2e diff --cc builtin/reflog.c index 1f1010e2d9,45e9e15006..4d3430900d --- a/builtin/reflog.c +++ b/builtin/reflog.c @@@ -94,8 -94,8 +94,8 @@@ static int tree_is_complete(const struc init_tree_desc(&desc, tree->buffer, tree->size); complete = 1; while (tree_entry(&desc, &entry)) { - if (!has_sha1_file(entry.oid.hash) || - if (!has_object_file(entry.oid) || - (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) { ++ if (!has_object_file(&entry.oid) || + (S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) { tree->object.flags |= INCOMPLETE; complete = 0; } diff --cc object-store.h index ba57630677,a7808bb624..14fc935bd1 --- a/object-store.h +++ b/object-store.h @@@ -154,26 -154,21 +154,28 @@@ void raw_object_store_clear(struct raw_ /* * Put in `buf` the name of the file in the local object database that - * would be used to store a loose object with the specified sha1. + * would be used to store a loose object with the specified oid. */ - const char *loose_object_path(struct repository *r, struct strbuf *buf, const unsigned char *sha1); + const char *loose_object_path(struct repository *r, struct strbuf *buf, + const struct object_id *oid); - void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size); + void *map_loose_object(struct repository *r, const struct object_id *oid, + unsigned long *size); -extern void *read_object_file_extended(const struct object_id *oid, +extern void *read_object_file_extended(struct repository *r, + const struct object_id *oid, enum object_type *type, unsigned long *size, int lookup_replace); -static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size) +static inline void *repo_read_object_file(struct repository *r, + const struct object_id *oid, + enum object_type *type, + unsigned long *size) { - return read_object_file_extended(oid, type, size, 1); + return read_object_file_extended(r, oid, type, size, 1); } +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#define read_object_file(oid, type, size) repo_read_object_file(the_repository, oid, type, size) +#endif /* Read and unpack an object file into memory, write memory to an object file */ int oid_object_info(struct repository *r, const struct object_id *, unsigned long *); @@@ -206,32 -201,16 +208,19 @@@ int read_loose_object(const char *path unsigned long *size, void **contents); --/* - * Convenience for sha1_object_info_extended() with a NULL struct - * Convenience for oid_object_info_extended() with a NULL struct -- * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass -- * nonzero flags to also set other flags. -- */ - int repo_has_sha1_file_with_flags(struct repository *r, - const unsigned char *sha1, int flags); - static inline int repo_has_sha1_file(struct repository *r, - const unsigned char *sha1) -int has_object_file_with_flags(const struct object_id *oid, int flags); -static inline int has_object_file(const struct object_id *oid) --{ - return repo_has_sha1_file_with_flags(r, sha1, 0); - return has_object_file_with_flags(oid, 0); --} - +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#define has_sha1_file_with_flags(sha1, flags) repo_has_sha1_file_with_flags(the_repository, sha1, flags) +#define has_sha1_file(sha1) repo_has_sha1_file(the_repository, sha1) +#endif + +/* Same as the above, except for struct object_id. */ +int repo_has_object_file(struct repository *r, const struct object_id *oid); +int repo_has_object_file_with_flags(struct repository *r, + const struct object_id *oid, int flags); +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#define has_object_file(oid) repo_has_object_file(the_repository, oid) +#define has_object_file_with_flags(oid, flags) repo_has_object_file_with_flags(the_repository, oid, flags) +#endif /* * Return true iff an alternate object database has a loose object diff --cc object.c index 5dc5eec367,df72914bdc..59ea24c4aa --- a/object.c +++ b/object.c @@@ -260,11 -259,11 +260,11 @@@ struct object *parse_object(struct repo if (obj && obj->parsed) return obj; - if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) || - (!obj && has_object_file(oid) && + if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) || + (!obj && repo_has_object_file(r, oid) && oid_object_info(r, oid, NULL) == OBJ_BLOB)) { if (check_object_signature(repl, NULL, 0, NULL) < 0) { - error(_("sha1 mismatch %s"), oid_to_hex(oid)); + error(_("hash mismatch %s"), oid_to_hex(oid)); return NULL; } parse_blob_buffer(lookup_blob(r, oid), NULL, 0); diff --cc sha1-file.c index c8da9f3475,23564598f2..494606f771 --- a/sha1-file.c +++ b/sha1-file.c @@@ -169,30 -122,9 +169,30 @@@ const char *empty_blob_oid_hex(void return oid_to_hex_r(buf, the_hash_algo->empty_blob); } +int hash_algo_by_name(const char *name) +{ + int i; + if (!name) + return GIT_HASH_UNKNOWN; + for (i = 1; i < GIT_HASH_NALGOS; i++) + if (!strcmp(name, hash_algos[i].name)) + return i; + return GIT_HASH_UNKNOWN; +} + +int hash_algo_by_id(uint32_t format_id) +{ + int i; + for (i = 1; i < GIT_HASH_NALGOS; i++) + if (format_id == hash_algos[i].format_id) + return i; + return GIT_HASH_UNKNOWN; +} + + /* * This is meant to hold a *small* number of objects that you would - * want read_sha1_file() to be able to return, but yet you do not want + * want read_object_file() to be able to return, but yet you do not want * to write them into the object store (e.g. a browse-only * application). */ @@@ -1421,21 -1352,16 +1421,17 @@@ int oid_object_info(struct repository * return type; } -static void *read_object(const struct object_id *oid, enum object_type *type, +static void *read_object(struct repository *r, - const unsigned char *sha1, - enum object_type *type, ++ const struct object_id *oid, enum object_type *type, unsigned long *size) { - struct object_id oid; struct object_info oi = OBJECT_INFO_INIT; void *content; oi.typep = type; oi.sizep = size; oi.contentp = &content; - hashcpy(oid.hash, sha1); - - if (oid_object_info_extended(r, &oid, &oi, 0) < 0) - if (oid_object_info_extended(the_repository, oid, &oi, 0) < 0) ++ if (oid_object_info_extended(r, oid, &oi, 0) < 0) return NULL; return content; } @@@ -1474,10 -1399,10 +1470,10 @@@ void *read_object_file_extended(struct const char *path; struct stat st; const struct object_id *repl = lookup_replace ? - lookup_replace_object(the_repository, oid) : oid; + lookup_replace_object(r, oid) : oid; errno = 0; - data = read_object(r, repl->hash, type, size); - data = read_object(repl, type, size); ++ data = read_object(r, repl, type, size); if (data) return data; @@@ -1489,7 -1414,7 +1485,7 @@@ die(_("replacement %s not found for %s"), oid_to_hex(repl), oid_to_hex(oid)); - if (!stat_sha1_file(r, repl->hash, &st, &path)) - if (!stat_loose_object(the_repository, repl, &st, &path)) ++ if (!stat_loose_object(r, repl, &st, &path)) die(_("loose object %s (stored in %s) is corrupt"), oid_to_hex(repl), path); @@@ -1817,9 -1742,9 +1813,9 @@@ int force_object_loose(const struct obj if (has_loose_object(oid)) return 0; - buf = read_object(the_repository, oid->hash, &type, &len); - buf = read_object(oid, &type, &len); ++ buf = read_object(the_repository, oid, &type, &len); if (!buf) - return error(_("cannot read sha1_file for %s"), oid_to_hex(oid)); + return error(_("cannot read object for %s"), oid_to_hex(oid)); hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1; ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime); free(buf); @@@ -1827,29 -1752,14 +1823,21 @@@ return ret; } - int repo_has_sha1_file_with_flags(struct repository *r, - const unsigned char *sha1, int flags) -int has_object_file_with_flags(const struct object_id *oid, int flags) ++int repo_has_object_file_with_flags(struct repository *r, ++ const struct object_id *oid, int flags) { - struct object_id oid; if (!startup_info->have_repository) return 0; - hashcpy(oid.hash, sha1); - return oid_object_info_extended(r, &oid, NULL, - return oid_object_info_extended(the_repository, oid, NULL, ++ return oid_object_info_extended(r, oid, NULL, flags | OBJECT_INFO_SKIP_CACHED) >= 0; } +int repo_has_object_file(struct repository *r, + const struct object_id *oid) +{ - return repo_has_sha1_file(r, oid->hash); - } - - int repo_has_object_file_with_flags(struct repository *r, - const struct object_id *oid, int flags) - { - return repo_has_sha1_file_with_flags(r, oid->hash, flags); ++ return repo_has_object_file_with_flags(r, oid, 0); +} + static void check_tree(const void *buf, size_t size) { struct tree_desc desc;