Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
* [Question] git cat-file --batch cannot handle irregular path
@ 2021-04-20  3:48 lilinchao
  2021-04-20  4:23 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: lilinchao @ 2021-04-20  3:48 UTC (permalink / raw)
  To: git

Hi, all

When I use "git cat-file --batch" command, with the form
<tree-ish>:path, here path is the working tree in my repository,
but it is irregular, such as "法律\(Law\)/民法\(civil\ law$'\n'\)\",
this kind of path is unintentionally created.  
The process cannot correctly handle this kind of case:

$ git cat-file --batch
d071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law)
d071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law) missing

How can I deal with this case when irregular paths cannot be avoided?

Thanks in advance.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] git cat-file --batch cannot handle irregular path
  2021-04-20  3:48 [Question] git cat-file --batch cannot handle irregular path lilinchao
@ 2021-04-20  4:23 ` Junio C Hamano
  2021-04-23 13:07   ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2021-04-20  4:23 UTC (permalink / raw)
  To: lilinchao; +Cc: git

"lilinchao@oschina.cn" <lilinchao@oschina.cn> writes:

> but it is irregular, such as "法律\(Law\)/民法\(civil\ law$'\n'\)\",
> ...
> d071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law)
> d071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law) missing

I may be misreading what you wrote, but if you mean that there is a
LF in the pathname, I do not think cat-file --batch is prepared to
handle it; as we can see in builtin/cat-cile.c:

static int batch_objects(struct batch_options *opt)
{
	...
	while (strbuf_getline(&input, stdin) != EOF) {
		if (data.split_on_whitespace) {
		...
		}

		batch_one_object(input.buf, &output, opt, &data);
	}

it always treats what strbuf_getline() returns as a single record.

If properly designed, it would have

 - supported "-z" to take NUL-delimited input, and

 - when "-z" is not in effect, after reading a single line of input,
   we would have called quote API to un-cquote the string, so that
   we can express LF and other special characters in the pathname.

but those who worked on "cat-file --batch" didn't.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] git cat-file --batch cannot handle irregular path
  2021-04-20  4:23 ` Junio C Hamano
@ 2021-04-23 13:07   ` Jeff King
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff King @ 2021-04-23 13:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: lilinchao, git

On Mon, Apr 19, 2021 at 09:23:31PM -0700, Junio C Hamano wrote:

> If properly designed, it would have
> 
>  - supported "-z" to take NUL-delimited input, and
> 
>  - when "-z" is not in effect, after reading a single line of input,
>    we would have called quote API to un-cquote the string, so that
>    we can express LF and other special characters in the pathname.
> 
> but those who worked on "cat-file --batch" didn't.

Yeah, this has been a long-standing pain.

It would be easy to add "-z" now, and probably worth doing.

It is too late to do the unquoting thing by default now. We could add an
option to enable it, but once "-z" exists, it hardly seems worth it.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20  3:48 [Question] git cat-file --batch cannot handle irregular path lilinchao
2021-04-20  4:23 ` Junio C Hamano
2021-04-23 13:07   ` Jeff King

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git