Merge branch 'sb/object-store'
authorJunio C Hamano <gitster@pobox.com>
Wed, 11 Apr 2018 04:09:55 +0000 (13:09 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Apr 2018 04:09:55 +0000 (13:09 +0900)
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
...

27 files changed:
1  2 
builtin/am.c
builtin/fetch.c
builtin/fsck.c
builtin/gc.c
builtin/grep.c
builtin/index-pack.c
builtin/merge.c
builtin/pack-objects.c
builtin/pack-redundant.c
builtin/receive-pack.c
builtin/submodule--helper.c
cache.h
environment.c
fast-import.c
http-push.c
http-walker.c
http.c
object.c
pack-check.c
packfile.c
packfile.h
reachable.c
sha1_file.c
sha1_name.c
streaming.c
submodule.c
transport.c
diff --cc builtin/am.c
Simple merge
diff --cc builtin/fetch.c
Simple merge
diff --cc builtin/fsck.c
Simple merge
diff --cc builtin/gc.c
Simple merge
diff --cc builtin/grep.c
Simple merge
Simple merge
diff --cc builtin/merge.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc cache.h
index 6e45c1b5377cfca2e0621d529f69daac304e3f12,720664e394510ee0194d8dccf42d5ee5a003903b..bbaf5c349ab893a6f0f4549b61bcc70eff50745f
+++ 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 21565c3c525c64793282d8c3f029733615a87fc2,93c9fbb0ba29479f33ccab7808b11eb60cd373ec..39b3d906c89048cd094f352fa2ea81d873deb31a
@@@ -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
Simple merge
diff --cc http-push.c
Simple merge
diff --cc http-walker.c
Simple merge
diff --cc http.c
Simple merge
diff --cc object.c
Simple merge
diff --cc pack-check.c
Simple merge
diff --cc packfile.c
Simple merge
diff --cc packfile.h
Simple merge
diff --cc reachable.c
Simple merge
diff --cc sha1_file.c
index aea9124a78fce21eb4cb756af29823493274e581,0989bbd948dcd025c89c73bbfe72ab7c735e3211..aab3b58e0330531efa8a442eafb18840b1f212f3
  #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 sha1_name.c
Simple merge
diff --cc streaming.c
index 46fabee3aa43840fbe93dfd0e12eff85d5e81cb2,22d27df55ebb0926967c1b1afe027d6c112820ae..7d55ba64c7551de0f3be1dfcf56cd3344ebd8f59
@@@ -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 submodule.c
Simple merge
diff --cc transport.c
Simple merge