Re: [PATCH 2/7] sha1_file, link: write link objects to the database
- From
Ramkumar Ramachandra <artagnon@gmail.com>
- Date
- Apr 5, 2013, 07:11 UTC
- Message-ID
- <CALkWK0k=XYPJXEEx8CMYRx_k0d9Z=b_W=wGGvbZsXJEe8K99EA@mail.gmail.com>
- In-Reply-To
- <1365100243-13676-3-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra wrote:
Show 35 quoted lines
> diff --git a/link.c b/link.c
> index bb20a51..349646d 100644
> --- a/link.c
> +++ b/link.c
> @@ -20,8 +20,30 @@ struct link *lookup_link(const unsigned char *sha1)
>
> int parse_link_buffer(struct link *item, void *buffer, unsigned long size)
> {
> + char *bufptr = buffer;
> + char *tail = buffer + size;
> + char *eol;
> +
> if (item->object.parsed)
> return 0;
> item->object.parsed = 1;
> + while (bufptr < tail) {
> + eol = strchr(bufptr, '\n');
> + *eol = '\0';
> + if (!prefixcmp(bufptr, "upstream_url = "))
> + item->upstream_url = xstrdup(bufptr + 15);
> + else if (!prefixcmp(bufptr, "checkout_rev = "))
> + item->checkout_rev = xstrdup(bufptr + 15);
> + else if (!prefixcmp(bufptr, "ref_name = "))
> + item->ref_name = xstrdup(bufptr + 11);
> + else if (!prefixcmp(bufptr, "floating = "))
> + item->floating = atoi(bufptr + 11);
> + else if (!prefixcmp(bufptr, "statthrough = "))
> + item->statthrough = atoi(bufptr + 14);
> + else
> + return error("Parse error in link buffer");
> +
> + bufptr = eol + 1;
> + }
> return 0;
> }This needs to be replaced by a .git/config parser. However, I can't use the parser from config.c as-it-is, because it expects a section like [core] to be present. So, we have to refactor it to optionally parse section-less configs.