git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] read_sha1_file(): get rid of read_sha1_file_repl() madness

From
Junio C Hamano <gitster@pobox.com>
Date
May 15, 2011, 19:54 UTC
Message-ID
<1305489294-14341-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1305489294-14341-1-git-send-email-gitster@pobox.com>

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>
---
 builtin/mktag.c |    4 ++--
 cache.h         |    6 +-----
 object.c        |    4 ++--
 sha1_file.c     |   12 ++++--------
 4 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 324a267..640ab64 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -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))
diff --git a/cache.h b/cache.h
index e09cf75..a9ae100 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
diff --git a/object.c b/object.c
index 7e1f2bb..31976b5 100644
--- a/object.c
+++ b/object.c
@@ -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;
diff --git a/sha1_file.c b/sha1_file.c
index 889fe71..5d80feb 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;
@@ -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));
-- 
1.7.5.1.334.gdfd07
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 6 in “Updates to replace-object API”
  1. 0/5 Updates to replace-object APIJunio C Hamano, May 15, 2011
  2. 1/5 Declare lookup_replace_object() in cache.h, not in commit.hJunio C Hamano, May 15, 2011
  3. 2/5 t6050: make sure we test not just commit replacementJunio C Hamano, May 15, 2011
  4. 3/5 read_sha1_file(): get rid of read_sha1_file_repl() madnessJunio C Hamano, May 15, 2011
  5. 4/5 inline lookup_replace_object() callsJunio C Hamano, May 15, 2011
  6. 5/5 read_sha1_file(): allow selective bypassing of replacement mechanismJunio C Hamano, May 15, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.