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

Re: [PATCH] Produce a nicer output in case of sha1_object_info failures in ls-tree -l

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2009, 23:08 UTC
Message-ID
<7v4oxp6rgk.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090319225429.GC8433@blimp.localdomain>
Alex Riesen <raa.lkml@gmail.com> writes:
> How about this patch instead? I chose "BAD" for the marker, as any
> automatic processing trying blindly to convert it into a number will
> get a 0, which seems safe to me.

Such a broken automatic processing won't mind getting any garbage; the choice among this patch, your original "say 0 when we do not know" patch, or unpatched "size is undefined when an entry is corrupt" git wouldn't make a whit of difference to it.

An automatic processing that does validate its input will notice BAD is not a number, and can handle such a corrupt entry more sanely, which is potentially a big plus.

I think this round is a big improvement.
Show 47 quoted lines
>  builtin-ls-tree.c |   22 ++++++++++++----------
>  1 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
> index fca4631..22008df 100644
> --- a/builtin-ls-tree.c
> +++ b/builtin-ls-tree.c
> @@ -60,7 +60,6 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
>  {
>  	int retval = 0;
>  	const char *type = blob_type;
> -	unsigned long size;
>  
>  	if (S_ISGITLINK(mode)) {
>  		/*
> @@ -90,17 +89,20 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
>  
>  	if (!(ls_options & LS_NAME_ONLY)) {
>  		if (ls_options & LS_SHOW_SIZE) {
> +			char size_text[24];
>  			if (!strcmp(type, blob_type)) {
> -				sha1_object_info(sha1, &size);
> -				printf("%06o %s %s %7lu\t", mode, type,
> -				       abbrev ? find_unique_abbrev(sha1, abbrev)
> -				              : sha1_to_hex(sha1),
> -				       size);
> +				unsigned long size;
> +				if (sha1_object_info(sha1, &size) == OBJ_BAD)
> +					strcpy(size_text, "BAD");
> +				else
> +					snprintf(size_text, sizeof(size_text),
> +						 "%lu", size);
>  			} else
> -				printf("%06o %s %s %7c\t", mode, type,
> -				       abbrev ? find_unique_abbrev(sha1, abbrev)
> -				              : sha1_to_hex(sha1),
> -				       '-');
> +				strcpy(size_text, "-");
> +			printf("%06o %s %s %7s\t", mode, type,
> +			       abbrev ? find_unique_abbrev(sha1, abbrev)
> +				      : sha1_to_hex(sha1),
> +			       size_text);
>  		} else
>  			printf("%06o %s %s\t", mode, type,
>  			       abbrev ? find_unique_abbrev(sha1, abbrev)
> -- 
> 1.6.2.1.237.g7206c6
Previous: Alex Riesen
Message 6 of 6 in “Produce a nicer output in case of sha1_object_info failures in ls-tree -l”
  1. Produce a nicer output in case of sha1_object_info failures in ls-tree -lAlex Riesen, Mar 19, 2009
  2. Junio C HamanoMar 19, 2009
  3. Alex RiesenMar 19, 2009
  4. Junio C HamanoMar 19, 2009
  5. Produce a nicer output in case of sha1_object_info failures in ls-tree -lAlex Riesen, Mar 19, 2009
  6. Junio C HamanoMar 19, 2009

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.