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

Re: [PATCH v3 2/3] sha1_file: implement changes for "cat-file --literally -t"

From
karthik nayak <karthik.188@gmail.com>
Date
Mar 8, 2015, 08:48 UTC
Message-ID
<54FC0CCE.70009@gmail.com>
In-Reply-To
<xmqqpp8jsyel.fsf@gitster.dls.corp.google.com>
On 03/08/2015 01:39 PM, Junio C Hamano wrote:
Show 33 quoted lines
> karthik nayak <karthik.188@gmail.com> writes:
>
>> On 03/07/2015 12:58 AM, Junio C Hamano wrote:
>>
>> case 't':
>> 	oi.typep = &type;
>> 	oi.typename = &sb;
>> 	sha1_object_info_extended(sha1, &oi, flags);
>> 	if (sb.len) {
>> 		printf("%s\n", sb.buf);
>> 		strbuf_release(&sb);
>> 		return 0;
>> 	} else if (type) {
>> 		printf("%s\n", typename(type));
>> 		return 0;
>> 	}
>> 	break;
>>
>> This works but I need an else statement to check the type if not
>> getting the type literally, which is because if not called literally
>> the oi.typename is not set,...
>
> Hmph, when I outlined that change to object-info-extended, I meant
> to do it in such a way that when the optional oi->typename is set,
> it is always filled whether "literally" is asked for andr whether
> the object is a kosher one or a bogus one.
>
> Without parsing the header, we wouldn't know how long the object
> would be, so I do not know if not doing some variant of parse_header
> is an option.
>
> Thanks.
>

What parse_sha1_header() does to get the type is just find the first occurrence of a " " manually and store everything before it as the type. Then it finds the size of the object if needed. And finally returns the type by calling type_from_string(). This is where we get the undefined type error. When getting the type "literally" we could just find the first occurrence of a " " using strcspn() copy the type to oi->typename and avoid calling parse_sha1_header(). Even your code went along these lines. If "literally" is not set we could call parse_sha1_header() like we regularly would.

Thanks Karthik

Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 18 in “cat-file: add "--literally" option”
  1. 0/3 cat-file: add "--literally" optionkarthik nayak, Mar 5, 2015
  2. 1/3 cache: modify for "cat-file --literally -t"Karthik Nayak, Mar 5, 2015
  3. Eric SunshineMar 8, 2015
  4. karthik nayakMar 9, 2015
  5. 2/3 sha1_file: implement changes for "cat-file --literally -t"Karthik Nayak, Mar 5, 2015
  6. Junio C HamanoMar 5, 2015
  7. karthik nayakMar 6, 2015
  8. Junio C HamanoMar 6, 2015
  9. karthik nayakMar 7, 2015
  10. Junio C HamanoMar 8, 2015
  11. karthik nayakMar 8, 2015
  12. Junio C HamanoMar 8, 2015
  13. karthik nayakMar 8, 2015
  14. Junio C HamanoMar 8, 2015
  15. karthik nayakMar 9, 2015
  16. 3/3 cat-file: add "--literally" optionKarthik Nayak, Mar 5, 2015
  17. Eric SunshineMar 8, 2015
  18. karthik nayakMar 9, 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.