{"thread":{"id":"17116","subject":"[RFC/PATCH 4/7] sha1_file: add a \"read_sha1_file_repl\" function","startedAt":"2009-01-12T17:51:00Z","lastAt":"2009-01-12T17:51:00Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"100145","messageId":"20090112185100.67c4a40e.chriscool@tuxfamily.org","threadId":"17116","inReplyTo":null,"subject":"[RFC/PATCH 4/7] sha1_file: add a \"read_sha1_file_repl\" function","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-01-12T17:51:00Z","receivedAt":"2009-01-12T17:51:00Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This new function will replace \"read_sha1_file\". This latter function\nbecoming just a stub to call the former will a NULL \"replacement\"\nargument.\n\nThis new function is needed because sometimes we need to use the\nreplacement sha1.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n cache.h     |    6 +++++-\n sha1_file.c |    9 +++++++--\n 2 files changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 8e1af26..1b34381 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -625,7 +625,11 @@ int longest_ancestor_length(const char *path, const char *prefix_list);\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n extern int sha1_object_info(const unsigned char *, unsigned long *);\n-extern void * read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size);\n+extern void *read_sha1_file_repl(const unsigned char *sha1, enum object_type *type, unsigned long *size, const unsigned char **replacement);\n+static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n+{\n+\treturn read_sha1_file_repl(sha1, type, size, NULL);\n+}\n extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);\n extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);\n extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 4f2fd10..ea89ce5 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2160,8 +2160,10 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,\n \treturn read_packed_sha1(sha1, type, size);\n }\n \n-void *read_sha1_file(const unsigned char *sha1, enum object_type *type,\n-\t\t     unsigned long *size)\n+void *read_sha1_file_repl(const unsigned char *sha1,\n+\t\t\t  enum object_type *type,\n+\t\t\t  unsigned long *size,\n+\t\t\t  const unsigned char **replacement)\n {\n \tconst unsigned char *repl = lookup_replace_object(sha1);\n \tvoid *data = read_object(repl, type, size);\n@@ -2175,6 +2177,9 @@ void *read_sha1_file(const unsigned char *sha1, enum object_type *type,\n \tif (!data && (has_loose_object(repl) || has_packed_and_bad(repl)))\n \t\tdie(\"object %s is corrupted\", sha1_to_hex(repl));\n \n+\tif (replacement)\n+\t\t*replacement = repl;\n+\n \treturn data;\n }\n \n-- \n1.6.1.83.g16e5\n"}]}