read_sha1_file(): get rid of read_sha1_file_repl() madness

Most callers want to silently get a replacement object, and they do not care what the real name of the replacement object is. Worse yet, no sane interface to return the underlying object without replacement is provided. Remove the function and make only the few callers that want the name of the replacement object find it themselves. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 15, 2011 at 12:54 UTC 4bbf5a2615420ac50c696b72dc303727e6218562
4 files changed +9 -17
builtin/mktag.c
+2 -2
@@ -23,8 +23,8 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
23 int ret = -1;
24 enum object_type type;
25 unsigned long size;
26 - const unsigned char *repl;
27 - void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
26 + void *buffer = read_sha1_file(sha1, &type, &size);
27 + const unsigned char *repl = lookup_replace_object(sha1);
28
29 if (buffer) {
30 if (type == type_from_string(expected_type))
cache.h
+1 -5
@@ -758,11 +758,7 @@ int offset_1st_component(const char *path);
758
759 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
760 extern int sha1_object_info(const unsigned char *, unsigned long *);
761 -extern void *read_sha1_file_repl(const unsigned char *sha1, enum object_type *type, unsigned long *size, const unsigned char **replacement);
762 -static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
763 -{
764 - return read_sha1_file_repl(sha1, type, size, NULL);
765 -}
761 +extern void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size);
762 extern const unsigned char *lookup_replace_object(const unsigned char *sha1);
763 extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
764 extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
object.c
+2 -2
@@ -188,8 +188,8 @@ struct object *parse_object(const unsigned char *sha1)
188 unsigned long size;
189 enum object_type type;
190 int eaten;
191 - const unsigned char *repl;
192 - void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
191 + const unsigned char *repl = lookup_replace_object(sha1);
192 + void *buffer = read_sha1_file(sha1, &type, &size);
193
194 if (buffer) {
195 struct object *obj;
sha1_file.c
+4 -8
@@ -2206,10 +2206,9 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
2206 * deal with them should arrange to call read_object() and give error
2207 * messages themselves.
2208 */
2209 -void *read_sha1_file_repl(const unsigned char *sha1,
2210 - enum object_type *type,
2211 - unsigned long *size,
2212 - const unsigned char **replacement)
2209 +void *read_sha1_file(const unsigned char *sha1,
2210 + enum object_type *type,
2211 + unsigned long *size)
2212 {
2213 const unsigned char *repl = lookup_replace_object(sha1);
2214 void *data;
@@ -2218,11 +2217,8 @@ void *read_sha1_file_repl(const unsigned char *sha1,
2217
2218 errno = 0;
2219 data = read_object(repl, type, size);
2221 - if (data) {
2222 - if (replacement)
2223 - *replacement = repl;
2220 + if (data)
2221 return data;
2225 - }
2222
2223 if (errno && errno != ENOENT)
2224 die_errno("failed to read object %s", sha1_to_hex(sha1));