Skip to content

Commit

Permalink
read_sha1_file(): get rid of read_sha1_file_repl() madness
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed May 15, 2011
1 parent abb25ac commit 4bbf5a2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions builtin/mktag.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
int ret = -1;
enum object_type type;
unsigned long size;
const unsigned char *repl;
void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
void *buffer = read_sha1_file(sha1, &type, &size);
const unsigned char *repl = lookup_replace_object(sha1);

if (buffer) {
if (type == type_from_string(expected_type))
Expand Down
6 changes: 1 addition & 5 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,7 @@ int offset_1st_component(const char *path);

/* 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 void *read_sha1_file_repl(const unsigned char *sha1, enum object_type *type, unsigned long *size, const unsigned char **replacement);
static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
{
return read_sha1_file_repl(sha1, type, size, NULL);
}
extern void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size);
extern const unsigned char *lookup_replace_object(const unsigned char *sha1);
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);
Expand Down
4 changes: 2 additions & 2 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ struct object *parse_object(const unsigned char *sha1)
unsigned long size;
enum object_type type;
int eaten;
const unsigned char *repl;
void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
const unsigned char *repl = lookup_replace_object(sha1);
void *buffer = read_sha1_file(sha1, &type, &size);

if (buffer) {
struct object *obj;
Expand Down
12 changes: 4 additions & 8 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2206,10 +2206,9 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
* deal with them should arrange to call read_object() and give error
* messages themselves.
*/
void *read_sha1_file_repl(const unsigned char *sha1,
enum object_type *type,
unsigned long *size,
const unsigned char **replacement)
void *read_sha1_file(const unsigned char *sha1,
enum object_type *type,
unsigned long *size)
{
const unsigned char *repl = lookup_replace_object(sha1);
void *data;
Expand All @@ -2218,11 +2217,8 @@ void *read_sha1_file_repl(const unsigned char *sha1,

errno = 0;
data = read_object(repl, type, size);
if (data) {
if (replacement)
*replacement = repl;
if (data)
return data;
}

if (errno && errno != ENOENT)
die_errno("failed to read object %s", sha1_to_hex(sha1));
Expand Down

0 comments on commit 4bbf5a2

Please sign in to comment.