sha1_file: rename LOOKUP_REPLACE_OBJECT

The LOOKUP_REPLACE_OBJECT flag controls whether the lookup_replace_object() function is invoked by sha1_object_info_extended(), read_sha1_file_extended(), and lookup_replace_object_extended(), but it is not immediately clear which functions accept that flag. Therefore restrict this flag to only sha1_object_info_extended(), renaming it appropriately to OBJECT_INFO_LOOKUP_REPLACE and adding some documentation. Update read_sha1_file_extended() to have a boolean parameter instead, and delete lookup_replace_object_extended(). parse_sha1_header() also passes this flag to parse_sha1_header_extended() since commit 46f0344 ("sha1_file: support reading from a loose object of unknown type", 2015-05-03), but that has had no effect since that commit. Therefore this patch also removes this flag from that invocation. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jun 21, 2017 at 17:40 UTC 1f0c0d36c1567f5cc8c10141fd4e70b871e809fd
3 files changed +18 -18
builtin/cat-file.c
+3 -2
@@ -56,7 +56,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
56 struct object_context obj_context;
57 struct object_info oi = OBJECT_INFO_INIT;
58 struct strbuf sb = STRBUF_INIT;
59 - unsigned flags = LOOKUP_REPLACE_OBJECT;
59 + unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
60 const char *path = force_path;
61
62 if (unknown_type)
@@ -337,7 +337,8 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
337 struct strbuf buf = STRBUF_INIT;
338
339 if (!data->skip_object_info &&
340 - sha1_object_info_extended(data->oid.hash, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
340 + sha1_object_info_extended(data->oid.hash, &data->info,
341 + OBJECT_INFO_LOOKUP_REPLACE) < 0) {
342 printf("%s missing\n",
343 obj_name ? obj_name : oid_to_hex(&data->oid));
344 fflush(stdout);
cache.h
+6 -11
@@ -1205,12 +1205,12 @@ extern char *xdg_config_home(const char *filename);
1205 */
1206 extern char *xdg_cache_home(const char *filename);
1207
1208 -/* object replacement */
1209 -#define LOOKUP_REPLACE_OBJECT 1
1210 -extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
1208 +extern void *read_sha1_file_extended(const unsigned char *sha1,
1209 + enum object_type *type,
1210 + unsigned long *size, int lookup_replace);
1211 static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
1212 {
1213 - return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT);
1213 + return read_sha1_file_extended(sha1, type, size, 1);
1214 }
1215
1216 /*
@@ -1232,13 +1232,6 @@ static inline const unsigned char *lookup_replace_object(const unsigned char *sh
1232 return do_lookup_replace_object(sha1);
1233 }
1234
1235 -static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag)
1236 -{
1237 - if (!(flag & LOOKUP_REPLACE_OBJECT))
1238 - return sha1;
1239 - return lookup_replace_object(sha1);
1240 -}
1241 -
1235 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
1236 extern int sha1_object_info(const unsigned char *, unsigned long *);
1237 extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
@@ -1865,6 +1858,8 @@ struct object_info {
1858 */
1859 #define OBJECT_INFO_INIT {NULL}
1860
1861 +/* Invoke lookup_replace_object() on the given hash */
1862 +#define OBJECT_INFO_LOOKUP_REPLACE 1
1863 /* Allow reading from a loose object file of unknown/bogus type */
1864 #define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
1865 extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags);
sha1_file.c
+9 -5
@@ -2002,7 +2002,7 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
2002 struct object_info oi = OBJECT_INFO_INIT;
2003
2004 oi.sizep = sizep;
2005 - return parse_sha1_header_extended(hdr, &oi, LOOKUP_REPLACE_OBJECT);
2005 + return parse_sha1_header_extended(hdr, &oi, 0);
2006 }
2007
2008 static void *unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size, const unsigned char *sha1)
@@ -2969,7 +2969,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
2969 struct cached_object *co;
2970 struct pack_entry e;
2971 int rtype;
2972 - const unsigned char *real = lookup_replace_object_extended(sha1, flags);
2972 + const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
2973 + lookup_replace_object(sha1) :
2974 + sha1;
2975
2976 co = find_cached_object(real);
2977 if (co) {
@@ -3025,7 +3027,8 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
3027
3028 oi.typep = &type;
3029 oi.sizep = sizep;
3028 - if (sha1_object_info_extended(sha1, &oi, LOOKUP_REPLACE_OBJECT) < 0)
3030 + if (sha1_object_info_extended(sha1, &oi,
3031 + OBJECT_INFO_LOOKUP_REPLACE) < 0)
3032 return -1;
3033 return type;
3034 }
@@ -3107,13 +3110,14 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
3110 void *read_sha1_file_extended(const unsigned char *sha1,
3111 enum object_type *type,
3112 unsigned long *size,
3110 - unsigned flag)
3113 + int lookup_replace)
3114 {
3115 void *data;
3116 const struct packed_git *p;
3117 const char *path;
3118 struct stat st;
3116 - const unsigned char *repl = lookup_replace_object_extended(sha1, flag);
3119 + const unsigned char *repl = lookup_replace ? lookup_replace_object(sha1)
3120 + : sha1;
3121
3122 errno = 0;
3123 data = read_object(repl, type, size);