From: Junio C Hamano Date: Fri, 30 Mar 2018 19:42:07 +0000 (-0700) Subject: Merge branch 'sb/object-store' into next X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/93e347517807e8310607e4ca241d747ebff3ff62?hp=--cc Merge branch 'sb/object-store' into next 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 ... --- 93e347517807e8310607e4ca241d747ebff3ff62 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 fast-import.c index 0aa148ea47,b3492fce5c..5eea3cc9d2 --- a/fast-import.c +++ b/fast-import.c @@@ -168,7 -169,7 +169,8 @@@ Format of STDIN stream #include "dir.h" #include "run-command.h" #include "packfile.h" + #include "object-store.h" +#include "mem-pool.h" #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<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, diff --cc transport.c index 90a9eb518d,3afc632472..16b2f54f22 --- a/transport.c +++ b/transport.c @@@ -18,7 -18,7 +18,8 @@@ #include "sha1-array.h" #include "sigchain.h" #include "transport-internal.h" +#include "protocol.h" + #include "object-store.h" static void set_upstreams(struct transport *transport, struct ref *refs, int pretend)