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

Re: git cat-file -e behavior

From
Jeff King <peff@peff.net>
Date
Feb 29, 2016, 12:40 UTC
Message-ID
<20160229124032.GA21158@sigill.intra.peff.net>
In-Reply-To
<20160229114455.GD29769@sigill.intra.peff.net>
On Mon, Feb 29, 2016 at 06:44:55AM -0500, Jeff King wrote:
Show 26 quoted lines
> [...]but it would be easy to change:
> 
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index 54db118..afde169 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -35,6 +35,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
>  	if (unknown_type)
>  		flags |= LOOKUP_UNKNOWN_OBJECT;
>  
> +	if (opt == 'e')
> +		return !has_sha1_file(sha1);
> +
>  	if (get_sha1_with_context(obj_name, 0, sha1, &obj_context))
>  		die("Not a valid object name %s", obj_name);
>  
> @@ -58,9 +61,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
>  		printf("%lu\n", size);
>  		return 0;
>  
> -	case 'e':
> -		return !has_sha1_file(sha1);
> -
>  	case 'c':
>  		if (!obj_context.path[0])
>  			die("git cat-file --textconv %s: <object> must be <sha1:path>",

This is wrong, of course. We still need to call get_sha1, but just need to not die. So it's more like this (totally untested, naturally):

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 54db118..44add8c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -35,8 +35,11 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 	if (unknown_type)
 		flags |= LOOKUP_UNKNOWN_OBJECT;
 
-	if (get_sha1_with_context(obj_name, 0, sha1, &obj_context))
+	if (get_sha1_with_context(obj_name, 0, sha1, &obj_context)) {
+		if (opt == 'e')
+			return 1;
 		die("Not a valid object name %s", obj_name);
+	}
 
 	buf = NULL;
 	switch (opt) {

-Peff
Previous: Jeff King
Message 5 of 5 in “git cat-file -e behavior”
  1. Michal ČihařFeb 29, 2016
  2. Jeff KingFeb 29, 2016
  3. Michal ČihařFeb 29, 2016
  4. Jeff KingFeb 29, 2016
  5. Jeff KingFeb 29, 2016

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.