{"thread":{"id":"55526","subject":"[Question] git cat-file --batch cannot handle irregular path","startedAt":"2021-04-20T03:49:02Z","lastAt":"2021-04-23T13:07:04Z","messageCount":3,"participants":["lilinchao@oschina.cn","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"422365","messageId":"54526f48a18b11ebad130024e87935e7@oschina.cn","threadId":"55526","inReplyTo":null,"subject":"[Question] git cat-file --batch cannot handle irregular path","fromName":"lilinchao@oschina.cn","fromEmail":"lilinchao@oschina.cn","sentAt":"2021-04-20T03:48:56Z","receivedAt":"2021-04-20T03:49:02Z","isPatch":false,"sender":{"key":"lilinchao@oschina.cn","avatar":null},"body":"Hi, all\n\nWhen I use \"git cat-file --batch\" command, with the form\n<tree-ish>:path, here path is the working tree in my repository,\nbut it is irregular, such as \"法律\\(Law\\)/民法\\(civil\\ law$'\\n'\\)\\\",\nthis kind of path is unintentionally created.  \nThe process cannot correctly handle this kind of case:\n\n$ git cat-file --batch\nd071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law)\nd071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law) missing\n\nHow can I deal with this case when irregular paths cannot be avoided?\n\nThanks in advance."},{"id":"422366","messageId":"xmqqim4h7fek.fsf@gitster.g","threadId":"55526","inReplyTo":"54526f48a18b11ebad130024e87935e7@oschina.cn","subject":"Re: [Question] git cat-file --batch cannot handle irregular path","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-04-20T04:23:31Z","receivedAt":"2021-04-20T04:23:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"lilinchao@oschina.cn\" <lilinchao@oschina.cn> writes:\n\n> but it is irregular, such as \"法律\\(Law\\)/民法\\(civil\\ law$'\\n'\\)\\\",\n> ...\n> d071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law)\n> d071ea971fb93ebc937517736c2a63d64ddbe0d9:法律(Law)/民法(civil law) missing\n\nI may be misreading what you wrote, but if you mean that there is a\nLF in the pathname, I do not think cat-file --batch is prepared to\nhandle it; as we can see in builtin/cat-cile.c:\n\nstatic int batch_objects(struct batch_options *opt)\n{\n\t...\n\twhile (strbuf_getline(&input, stdin) != EOF) {\n\t\tif (data.split_on_whitespace) {\n\t\t...\n\t\t}\n\n\t\tbatch_one_object(input.buf, &output, opt, &data);\n\t}\n\nit always treats what strbuf_getline() returns as a single record.\n\nIf properly designed, it would have\n\n - supported \"-z\" to take NUL-delimited input, and\n\n - when \"-z\" is not in effect, after reading a single line of input,\n   we would have called quote API to un-cquote the string, so that\n   we can express LF and other special characters in the pathname.\n\nbut those who worked on \"cat-file --batch\" didn't.\n\n"},{"id":"422752","messageId":"YILGdNkvyG2im6mk@coredump.intra.peff.net","threadId":"55526","inReplyTo":"xmqqim4h7fek.fsf@gitster.g","subject":"Re: [Question] git cat-file --batch cannot handle irregular path","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-04-23T13:07:00Z","receivedAt":"2021-04-23T13:07:04Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Apr 19, 2021 at 09:23:31PM -0700, Junio C Hamano wrote:\n\n> If properly designed, it would have\n> \n>  - supported \"-z\" to take NUL-delimited input, and\n> \n>  - when \"-z\" is not in effect, after reading a single line of input,\n>    we would have called quote API to un-cquote the string, so that\n>    we can express LF and other special characters in the pathname.\n> \n> but those who worked on \"cat-file --batch\" didn't.\n\nYeah, this has been a long-standing pain.\n\nIt would be easy to add \"-z\" now, and probably worth doing.\n\nIt is too late to do the unquoting thing by default now. We could add an\noption to enable it, but once \"-z\" exists, it hardly seems worth it.\n\n-Peff\n"}]}