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

Re: [PATCH v6 1/4] sha1_file.c: support reading from a loose object of unknown type

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 2, 2015, 19:12 UTC
Message-ID
<xmqqbnj6jqe5.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1427972288-15298-1-git-send-email-karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 9 quoted lines
> +static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
> +					unsigned long mapsize,
> +					struct strbuf *header)
> +{
> +	unsigned char buffer[32], *cp;
> +	unsigned long bufsiz = sizeof(buffer);
> +	int status;
> +
> +	status = unpack_sha1_header(stream, map, mapsize, buffer, bufsiz);

I briefly wondered if this can return Z_BUF_ERROR, but it is OK because we do not call inflate with Z_FINISH in unpack_sha1_header() for obvious reasons ;-)

> +	if (status) {
> +		strbuf_add(header, buffer, stream->next_out - buffer);
> +		return status;
> +	}
Show 12 quoted lines
> +	do {
> +		status = git_inflate(stream, 0);
> +		strbuf_add(header, buffer, stream->next_out - buffer);
> +		for (cp = buffer; cp < stream->next_out; cp++)
> +			if (!*cp)
> +				/* Found the NUL at the end of the header */
> +				return 0;
> +		stream->next_out = buffer;
> +		stream->avail_out = bufsiz;
> +	} while (status != Z_STREAM_END);
> +	return -1;
> +}
OK.
Show 16 quoted lines
> @@ -1614,27 +1642,24 @@ static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long s
>   * too permissive for what we want to check. So do an anal
>   * object header parse by hand.
>   */
> -int parse_sha1_header(const char *hdr, unsigned long *sizep)
> +int parse_sha1_header_extended(const char *hdr, struct object_info *oi,
> +			       unsigned int flags)
>  {
> -	char type[10];
> -	int i;
> +	struct strbuf typename = STRBUF_INIT;
>  	unsigned long size;
> +	int type;
>  
>  	/*
>  	 * The type can be at most ten bytes (including the
Is this still a valid comment?
Show 17 quoted lines
>  	 * terminating '\0' that we add), and is followed by
>  	 * a space.
>  	 */
> -	i = 0;
>  	for (;;) {
>  		char c = *hdr++;
>  		if (c == ' ')
>  			break;
> -		type[i++] = c;
> -		if (i >= sizeof(type))
> -			return -1;
> +		strbuf_addch(&typename, c);
>  	}
> -	type[i] = 0;
>  
>  	/*
>  	 * The length must follow immediately, and be in canonical
Previous: Karthik NayakNext: Karthik Nayak
Message 3 of 10 in “cat-file: add a '--literally' option”
  1. 0/4 cat-file: add a '--literally' optionkarthik nayak, Apr 2, 2015
  2. 1/4 sha1_file.c: support reading from a loose object of unknown typeKarthik Nayak, Apr 2, 2015
  3. Junio C HamanoApr 2, 2015
  4. 2/4 cat-file: teach cat-file a '--literally' optionKarthik Nayak, Apr 2, 2015
  5. Junio C HamanoApr 2, 2015
  6. karthik nayakApr 3, 2015
  7. 3/4 cat-file: add documentation for '--literally' option.Karthik Nayak, Apr 2, 2015
  8. 4/4 t1006: add tests for git cat-file --literallyKarthik Nayak, Apr 2, 2015
  9. Junio C HamanoApr 2, 2015
  10. karthik nayakApr 4, 2015

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.