From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, sunshine@sunshineco.com
Subject: Re: [PATCH v6 1/4] sha1_file.c: support reading from a loose object of unknown type
Date: Thu, 02 Apr 2015 12:12:34 -0700 [thread overview]
Message-ID: <xmqqbnj6jqe5.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1427972288-15298-1-git-send-email-karthik.188@gmail.com> (Karthik Nayak's message of "Thu, 2 Apr 2015 16:28:08 +0530")
Karthik Nayak <karthik.188@gmail.com> writes:
> +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;
> + }
> + 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.
> @@ -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?
> * 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
next prev parent reply other threads:[~2015-04-02 19:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-02 10:53 [PATCH v6 0/4] cat-file: add a '--literally' option karthik nayak
2015-04-02 10:58 ` [PATCH v6 1/4] sha1_file.c: support reading from a loose object of unknown type Karthik Nayak
2015-04-02 19:12 ` Junio C Hamano [this message]
2015-04-02 10:59 ` [PATCH v6 2/4] cat-file: teach cat-file a '--literally' option Karthik Nayak
2015-04-02 19:08 ` Junio C Hamano
2015-04-03 16:25 ` karthik nayak
2015-04-02 11:00 ` [PATCH v6 3/4] cat-file: add documentation for " Karthik Nayak
2015-04-02 11:00 ` [PATCH v6 4/4] t1006: add tests for git cat-file --literally Karthik Nayak
2015-04-02 20:35 ` [PATCH v6 0/4] cat-file: add a '--literally' option Junio C Hamano
2015-04-04 4:13 ` karthik nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbnj6jqe5.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.