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
Junio C Hamano <gitster@pobox.com>
Date
Mar 6, 2015, 19:28 UTC
Message-ID
<xmqq1tl2ylfo.fsf@gitster.dls.corp.google.com>
In-Reply-To
<54F9E6B6.4070105@gmail.com>
karthik nayak <karthik.188@gmail.com> writes:
Show 30 quoted lines
>> ... I suspect that the caller should supply a pointer to struct
>> object_info, i.e. something along these lines:
>>
>>      struct object_info oi = { NULL };
>>      struct strbuf sb = STRBUF_INIT;
>>      enum object_type type;
>>
>>      ...
>>
>>      oi.typename = &sb;
>>      sha1_object_info_literally(sha1, &oi);
>>      if (!sb.len)
>>          that is an error;
>>      else
>>          use sb.buf as the name;
>>
>>      strbuf_release(&sb);
> I thought I could get the calling function "cat_one_file()" to send
> the address to a struct strbuf. Like this ..
>
> struct strbuf sb = STRBUF_INIT;
> length = sha1_object_info_literally(sha1, &sb);
> if (length < 0)
> die("git cat-file --literally -t %s: failed",
>             obj_name);
> printf("%s\n", sb.buf);
> strbuf_release(&sb);
> return 0;
>
> What do you think? Is this ok?
When I gave you $gmane/264420, I was actually hoping that we do not
have to have "object-info-literally" helper at all, and instead the
caller in cat-file that deals with "-t" option can become something
like this:
	
	struct object_info oi = { NULL };
	struct strbuf typename = STRBUF_INIT;
	unsigned flags = LOOKUP_REPLACE_OBJECT;
        if (doing the --literally stuff)
		flags |= LOOKUP_LITERALLY;
	...
	switch (...) {
	case 't':
        	oi.typename = &typename;
                sha1_object_info_extended(sha1, &oi, flags);
		if (typename.len) {
                	printf("%s\n", typename.buf);
			return 0;
		}
                break;
	...

The change illustrated in $gmane/264420 is probably incomplete and some calls from the sha1_object_info_extended() after that change may still need to be tweaked to pay attention to LOOKUP_LITERALLY bit (e.g. parse_sha1_header() may want to learn not to barf when seeing an unexpected typename in the header when the caller asks to look up "literally").

Previous: karthik nayakNext: karthik nayak
Message 8 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.