]> granicus.if.org Git - git/commitdiff
Merge branch 'jk/loose-object-cache-oid'
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2019 06:05:27 +0000 (22:05 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2019 06:05:27 +0000 (22:05 -0800)
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

15 files changed:
1  2 
apply.c
builtin/cat-file.c
builtin/fetch.c
builtin/pack-objects.c
builtin/reflog.c
cache-tree.c
cache.h
http-push.c
http.c
http.h
object-store.h
object.c
send-pack.c
sha1-file.c
streaming.c

diff --cc apply.c
Simple merge
Simple merge
diff --cc builtin/fetch.c
Simple merge
Simple merge
index 1f1010e2d9aec2b95487007ec30509fcbda605d6,45e9e15006d4e8417b51c8649823c2dd878d9f69..4d3430900d06d82e8e06441f8fdfea00f7aecf78
@@@ -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 cache-tree.c
Simple merge
diff --cc cache.h
Simple merge
diff --cc http-push.c
Simple merge
diff --cc http.c
Simple merge
diff --cc http.h
Simple merge
diff --cc object-store.h
index ba57630677fac412c6f8a771ed64eccf6000e833,a7808bb6244b2c74cbf28aab86ba9291c4b0b477..14fc935bd1bf8b4fec70489825661dd7f6f2255c
@@@ -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 5dc5eec367354ae4817b813b181423e096179a8a,df72914bdc54292b8e0fad722c3eefd238496ec7..59ea24c4aab6e58ac64ef55598182da460acd6ad
+++ 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 send-pack.c
Simple merge
diff --cc sha1-file.c
index c8da9f34752c4d8f6518c8ed8c42164368e973a3,23564598f2bc17c6bc55b97e6a64ee356652045b..494606f7716923468e6f838dae0486a61b454101
@@@ -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;
  
                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);
        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;
  }
  
-       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);
 +int repo_has_object_file(struct repository *r,
 +                       const struct object_id *oid)
 +{
++      return repo_has_object_file_with_flags(r, oid, 0);
 +}
 +
  static void check_tree(const void *buf, size_t size)
  {
        struct tree_desc desc;
diff --cc streaming.c
Simple merge