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

[PATCH 1/2] sha1_file: silence sha1_loose_object_info

From
Thomas Rast <trast@inf.ethz.ch>
Date
May 30, 2013, 20:00 UTC
Message-ID
<2d926e4dbd218b2305f50652c00a5c1d87e81208.1369943791.git.trast@inf.ethz.ch>
In-Reply-To
<87bo7sbeoc.fsf@linux-k42r.v.cablecom.net>

sha1_object_info() returns -1 (OBJ_BAD) if it cannot find the object for some reason, which suggests that it wants the _caller_ to report this error. However, part of its work happens in sha1_loose_object_info, which _does_ report errors itself. This is doubly strange because:

* packed_object_info(), which is the other half of the duo, does _not_
  report this.
* In the event that an object is packed and pruned while
  sha1_object_info_extended() goes looking for it, we would
  erroneously show the error -- even though the code of the latter
  function purports to handle this case gracefully.
* A caller might invoke sha1_object_info() to find the type of an
  object even if that object is not known to exist.

Silence this error. The others remain untouched as a corrupt object is a much more grave error than it merely being absent.

Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
---
 sha1_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1_file.c b/sha1_file.c
index 67e815b..c0f6a0e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2348,7 +2348,7 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size
 
 	map = map_sha1_file(sha1, &mapsize);
 	if (!map)
-		return error("unable to find %s", sha1_to_hex(sha1));
+		return -1;
 	if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
 		status = error("unable to unpack %s header",
 			       sha1_to_hex(sha1));
-- 
1.8.3.506.g4fdeee5
Next: Thomas Rast
Message 1 of 8 in “sha1_file: silence sha1_loose_object_info”
  1. 1/2 sha1_file: silence sha1_loose_object_infoThomas Rast, May 30, 2013
  2. 2/2 lookup_commit_reference_gently: do not read non-{tag,commit}Thomas Rast, May 30, 2013
  3. Jeff KingMay 30, 2013
  4. Duy NguyenMay 31, 2013
  5. Thomas RastMay 31, 2013
  6. Jeff KingMay 31, 2013
  7. Ramkumar RamachandraMay 31, 2013
  8. Thomas RastMay 31, 2013

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.