From: Junio C Hamano Date: Wed, 11 Apr 2018 04:09:55 +0000 (+0900) Subject: Merge branch 'sb/object-store' X-Git-Tag: v2.18.0-rc0~144 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf0b1793ead9428d88e6592e624c7cb222913c58;p=thirdparty%2Fgit.git Merge branch 'sb/object-store' Refactoring the internal global data structure to make it possible to open multiple repositories, work with and then close them. Rerolled by Duy on top of a separate preliminary clean-up topic. The resulting structure of the topics looked very sensible. * sb/object-store: (27 commits) sha1_file: allow sha1_loose_object_info to handle arbitrary repositories sha1_file: allow map_sha1_file to handle arbitrary repositories sha1_file: allow map_sha1_file_1 to handle arbitrary repositories sha1_file: allow open_sha1_file to handle arbitrary repositories sha1_file: allow stat_sha1_file to handle arbitrary repositories sha1_file: allow sha1_file_name to handle arbitrary repositories sha1_file: add repository argument to sha1_loose_object_info sha1_file: add repository argument to map_sha1_file sha1_file: add repository argument to map_sha1_file_1 sha1_file: add repository argument to open_sha1_file sha1_file: add repository argument to stat_sha1_file sha1_file: add repository argument to sha1_file_name sha1_file: allow prepare_alt_odb to handle arbitrary repositories sha1_file: allow link_alt_odb_entries to handle arbitrary repositories sha1_file: add repository argument to prepare_alt_odb sha1_file: add repository argument to link_alt_odb_entries sha1_file: add repository argument to read_info_alternates sha1_file: add repository argument to link_alt_odb_entry sha1_file: add raw_object_store argument to alt_odb_usable pack: move approximate object count to object store ... --- cf0b1793ead9428d88e6592e624c7cb222913c58 diff --cc cache.h index 6e45c1b537,720664e394..bbaf5c349a --- a/cache.h +++ b/cache.h @@@ -1209,34 -1226,22 +1203,33 @@@ extern const struct object_id *do_looku * either sha1 or a pointer to a permanently-allocated value. When * object replacement is suppressed, always return sha1. */ -static inline const unsigned char *lookup_replace_object(const unsigned char *sha1) +static inline const struct object_id *lookup_replace_object(const struct object_id *oid) { if (!check_replace_refs) - return sha1; - return do_lookup_replace_object(sha1); + return oid; + return do_lookup_replace_object(oid); } -/* Read and unpack a sha1 file into memory, write memory to a sha1 file */ -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, 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); +/* Read and unpack an object file into memory, write memory to an object file */ +extern int oid_object_info(const struct object_id *, unsigned long *); + +extern int hash_object_file(const void *buf, unsigned long len, + const char *type, struct object_id *oid); + +extern int write_object_file(const void *buf, unsigned long len, + const char *type, struct object_id *oid); + +extern int hash_object_file_literally(const void *buf, unsigned long len, + const char *type, struct object_id *oid, + unsigned flags); + +extern int pretend_object_file(void *, unsigned long, enum object_type, + struct object_id *oid); + +extern int force_object_loose(const struct object_id *oid, time_t mtime); + extern int git_open_cloexec(const char *name, int flags); #define git_open(name) git_open_cloexec(name, O_RDONLY) - extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size); extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); extern int parse_sha1_header(const char *hdr, unsigned long *sizep); diff --cc environment.c index 21565c3c52,93c9fbb0ba..39b3d906c8 --- a/environment.c +++ b/environment.c @@@ -270,12 -271,12 +271,12 @@@ const char *get_git_work_tree(void char *get_object_directory(void) { - if (!the_repository->objectdir) + if (!the_repository->objects->objectdir) BUG("git environment hasn't been setup"); - return the_repository->objectdir; + return the_repository->objects->objectdir; } -int odb_mkstemp(struct strbuf *template, const char *pattern) +int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) { int fd; /* diff --cc sha1_file.c index aea9124a78,0989bbd948..aab3b58e03 --- a/sha1_file.c +++ b/sha1_file.c @@@ -29,10 -30,8 +30,11 @@@ #include "quote.h" #include "packfile.h" #include "fetch-object.h" + #include "object-store.h" +/* The maximum size for an object header. */ +#define MAX_HEADER_LEN 32 + const unsigned char null_sha1[GIT_MAX_RAWSZ]; const struct object_id null_oid; const struct object_id empty_tree_oid = { @@@ -1164,10 -1172,10 +1173,10 @@@ static int sha1_loose_object_info(struc * return value implicitly indicates whether the * object even exists. */ - if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) { + if (!oi->typep && !oi->type_name && !oi->sizep && !oi->contentp) { const char *path; struct stat st; - if (stat_sha1_file(sha1, &st, &path) < 0) + if (stat_sha1_file(r, sha1, &st, &path) < 0) return -1; if (oi->disk_sizep) *oi->disk_sizep = st.st_size; @@@ -1259,14 -1266,11 +1268,14 @@@ int oid_object_info_extended(const stru } while (1) { - if (find_pack_entry(real, &e)) + if (find_pack_entry(real->hash, &e)) break; + if (flags & OBJECT_INFO_IGNORE_LOOSE) + return -1; + /* Most likely it's a loose object. */ - if (!sha1_loose_object_info(real->hash, oi, flags)) - if (!sha1_loose_object_info(the_repository, real, oi, flags)) ++ if (!sha1_loose_object_info(the_repository, real->hash, oi, flags)) return 0; /* Not a loose object; someone else may have just packed it. */ @@@ -1383,20 -1382,20 +1392,20 @@@ void *read_object_file_extended(const s return data; if (errno && errno != ENOENT) - die_errno("failed to read object %s", sha1_to_hex(sha1)); + die_errno("failed to read object %s", oid_to_hex(oid)); /* die if we replaced an object with one that does not exist */ - if (repl != sha1) + if (repl != oid) die("replacement %s not found for %s", - sha1_to_hex(repl), sha1_to_hex(sha1)); + oid_to_hex(repl), oid_to_hex(oid)); - if (!stat_sha1_file(repl->hash, &st, &path)) - if (!stat_sha1_file(the_repository, repl, &st, &path)) ++ if (!stat_sha1_file(the_repository, repl->hash, &st, &path)) die("loose object %s (stored in %s) is corrupt", - sha1_to_hex(repl), path); + oid_to_hex(repl), path); - if ((p = has_packed_and_bad(repl)) != NULL) + if ((p = has_packed_and_bad(repl->hash)) != NULL) die("packed object %s (stored in %s) is corrupt", - sha1_to_hex(repl), p->pack_name); + oid_to_hex(repl), p->pack_name); return NULL; } @@@ -1591,7 -1589,7 +1600,7 @@@ static int write_loose_object(const str static struct strbuf filename = STRBUF_INIT; strbuf_reset(&filename); - sha1_file_name(&filename, oid->hash); - sha1_file_name(the_repository, &filename, sha1); ++ sha1_file_name(the_repository, &filename, oid->hash); fd = create_tmpfile(&tmp_file, filename.buf); if (fd < 0) { diff --cc streaming.c index 46fabee3aa,22d27df55e..7d55ba64c7 --- a/streaming.c +++ b/streaming.c @@@ -335,7 -337,8 +337,8 @@@ static struct stream_vtbl loose_vtbl = static open_method_decl(loose) { - st->u.loose.mapped = map_sha1_file(oid->hash, &st->u.loose.mapsize); + st->u.loose.mapped = map_sha1_file(the_repository, - sha1, &st->u.loose.mapsize); ++ oid->hash, &st->u.loose.mapsize); if (!st->u.loose.mapped) return -1; if ((unpack_sha1_header(&st->z,