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

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

From
karthik nayak <karthik.188@gmail.com>
Date
Apr 18, 2015, 09:03 UTC
Message-ID
<55321DCA.8030801@gmail.com>
In-Reply-To
<CAPig+cSiYsF6ioi+-P_BP=1bs-EAtNdAGjSqw6KmZyE39rKWBA@mail.gmail.com>
On 04/18/2015 05:01 AM, Eric Sunshine wrote:
Show 67 quoted lines
> On Wed, Apr 15, 2015 at 12:59 PM, Karthik Nayak <karthik.188@gmail.com> wrote:
>> Update sha1_loose_object_info() to optionally allow it to read
>> from a loose object file of unknown/bogus type; as the function
>> usually returns the type of the object it read in the form of enum
>> for known types, add an optional "typename" field to receive the
>> name of the type in textual form and a flag to indicate the reading
>> of a loose object file of unknown/bogus type.
>> [...]
>> ---
>> diff --git a/sha1_file.c b/sha1_file.c
>> index 980ce6b..267399d 100644
>> --- a/sha1_file.c
>> +++ b/sha1_file.c
>> @@ -2522,13 +2575,15 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
>>   }
>>
>>   static int sha1_loose_object_info(const unsigned char *sha1,
>> -                                 struct object_info *oi)
>> +                                 struct object_info *oi,
>> +                                 int flags)
>>   {
>> -       int status;
>> -       unsigned long mapsize, size;
>> +       int status = 0;
>> +       unsigned long mapsize;
>>          void *map;
>>          git_zstream stream;
>>          char hdr[32];
>> +       struct strbuf hdrbuf = STRBUF_INIT;
>>
>>          if (oi->delta_base_sha1)
>>                  hashclr(oi->delta_base_sha1);
>> @@ -2555,17 +2610,26 @@ static int sha1_loose_object_info(const unsigned char *sha1,
>>                  return -1;
>>          if (oi->disk_sizep)
>>                  *oi->disk_sizep = mapsize;
>> -       if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
>> -               status = error("unable to unpack %s header",
>> -                              sha1_to_hex(sha1));
>> -       else if ((status = parse_sha1_header(hdr, &size)) < 0)
>> -               status = error("unable to parse %s header", sha1_to_hex(sha1));
>> -       else if (oi->sizep)
>> -               *oi->sizep = size;
>> +       if ((flags & LOOKUP_LITERALLY)) {
>> +               if (unpack_sha1_header_to_strbuf(&stream, map, mapsize, &hdrbuf) < 0)
>> +                       status = error("unable to unpack %s header with --literally",
>> +                                      sha1_to_hex(sha1));
>> +               else if ((status = parse_sha1_header_extended(hdrbuf.buf, oi, flags)) < 0)
>> +                       status = error("unable to parse %s header with --literally",
>> +                                      sha1_to_hex(sha1));
>> +       } else {
>> +               if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
>> +                       status = error("unable to unpack %s header",
>> +                                      sha1_to_hex(sha1));
>> +               else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
>> +                       status = error("unable to parse %s header", sha1_to_hex(sha1));
>> +       }
>>          git_inflate_end(&stream);
>>          munmap(map, mapsize);
>> -       if (oi->typep)
>> +       if (status && oi->typep)
>>                  *oi->typep = status;
>> +       if (hdrbuf.buf)
>> +               strbuf_release(&hdrbuf);
>
> Why is strbuf_release() protected by a conditional rather than being
> called unconditionally? Am I missing something obvious?
No, you're right.
>
>>          return 0;
>>   }
>>
Previous: Eric SunshineNext: Karthik Nayak
Message 19 of 44 in “cat-file: teach cat-file a '--literally' option”
  1. 0/4 cat-file: teach cat-file a '--literally' optionkarthik nayak, Apr 15, 2015
  2. 1/4 sha1_file.c: support reading from a loose object of unknown typeKarthik Nayak, Apr 15, 2015
  3. Junio C HamanoApr 15, 2015
  4. Jeff KingApr 15, 2015
  5. Jeff KingApr 17, 2015
  6. Junio C HamanoApr 17, 2015
  7. Jeff KingApr 17, 2015
  8. Junio C HamanoApr 17, 2015
  9. karthik nayakApr 20, 2015
  10. Jeff KingApr 20, 2015
  11. karthik nayakApr 21, 2015
  12. Jeff KingApr 21, 2015
  13. karthik nayakApr 17, 2015
  14. Jeff KingApr 17, 2015
  15. karthik nayakApr 18, 2015
  16. Junio C HamanoApr 17, 2015
  17. karthik nayakApr 18, 2015
  18. Eric SunshineApr 17, 2015
  19. karthik nayakApr 18, 2015
  20. 2/4 cat-file: teach cat-file a '--literally' optionKarthik Nayak, Apr 15, 2015
  21. Junio C HamanoApr 15, 2015
  22. Junio C HamanoApr 15, 2015
  23. karthik nayakApr 16, 2015
  24. Junio C HamanoApr 16, 2015
  25. Karthik NayakApr 17, 2015
  26. Junio C HamanoApr 17, 2015
  27. Charles BaileyApr 19, 2015
  28. Junio C HamanoApr 20, 2015
  29. Charles BaileyApr 20, 2015
  30. Karthik NayakApr 20, 2015
  31. Charles BaileyApr 20, 2015
  32. karthik nayakApr 20, 2015
  33. Charles BaileyApr 21, 2015
  34. Eric SunshineApr 21, 2015
  35. Junio C HamanoApr 21, 2015
  36. karthik nayakApr 25, 2015
  37. Junio C HamanoApr 25, 2015
  38. karthik nayakApr 27, 2015
  39. Eric SunshineApr 27, 2015
  40. karthik nayakApr 28, 2015
  41. 3/4 cat-file: add documentation for '--literally' option.Karthik Nayak, Apr 15, 2015
  42. 4/4 t1006: add tests for git cat-file --literallyKarthik Nayak, Apr 15, 2015
  43. Eric SunshineApr 18, 2015
  44. karthik nayakApr 18, 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.