summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e1111ce)
raw | patch | inline | side by side (parent: e1111ce)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 15 May 2011 19:54:54 +0000 (12:54 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 15 May 2011 22:23:34 +0000 (15:23 -0700) |
The way "object replacement" mechanism was tucked to the read_sha1_file()
interface was suboptimal in a couple of ways:
- Callers that want it to die with useful diagnosis upon seeing a corrupt
object does not have a way to say that they do not want any object
replacement.
- Callers who do not want it to die but want to handle the errors
themselves are told to arrange to call read_object(), but the function
does not use the replacement mechanism, and also it is a file scope
static function that not many callers can call to begin with.
This adds a read_sha1_file_extended() that takes a set of flags; the
callers of read_sha1_file() passes a flag READ_SHA1_FILE_REPLACE to ask
for object replacement mechanism to kick in.
Later, we could add another flag bit to tell the function to return an
error instead of dying and then remove the misguided "call read_object()
yourself".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
interface was suboptimal in a couple of ways:
- Callers that want it to die with useful diagnosis upon seeing a corrupt
object does not have a way to say that they do not want any object
replacement.
- Callers who do not want it to die but want to handle the errors
themselves are told to arrange to call read_object(), but the function
does not use the replacement mechanism, and also it is a file scope
static function that not many callers can call to begin with.
This adds a read_sha1_file_extended() that takes a set of flags; the
callers of read_sha1_file() passes a flag READ_SHA1_FILE_REPLACE to ask
for object replacement mechanism to kick in.
Later, we could add another flag bit to tell the function to return an
error instead of dying and then remove the misguided "call read_object()
yourself".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
sha1_file.c | patch | blob | history |
index c10a91d90a58f9926a8eb6972337d154d12714cd..5f1f5c33953510bbdc7d31139b5e33bd1aaa7a4c 100644 (file)
--- a/cache.h
+++ b/cache.h
int offset_1st_component(const char *path);
/* object replacement */
-extern void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size);
+#define READ_SHA1_FILE_REPLACE 1
+extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
+static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+{
+ return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE);
+}
extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
{
diff --git a/sha1_file.c b/sha1_file.c
index 5d80febde24ebf4e8cf72923a3fb684942a82e75..7e6e976c23024c575a1eba73ed8dd70424ec09ff 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
* deal with them should arrange to call read_object() and give error
* messages themselves.
*/
-void *read_sha1_file(const unsigned char *sha1,
- enum object_type *type,
- unsigned long *size)
+void *read_sha1_file_extended(const unsigned char *sha1,
+ enum object_type *type,
+ unsigned long *size,
+ unsigned flag)
{
- const unsigned char *repl = lookup_replace_object(sha1);
void *data;
char *path;
const struct packed_git *p;
+ const unsigned char *repl = (flag & READ_SHA1_FILE_REPLACE)
+ ? lookup_replace_object(sha1) : sha1;
errno = 0;
data = read_object(repl, type, size);