{"thread":{"id":"7","subject":"[PATCH] teach ls-tree how to handle names with embedded LF","startedAt":"2005-04-13T23:43:03Z","lastAt":"2005-04-14T00:20:37Z","messageCount":4,"participants":["Junio C Hamano","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"22","messageId":"7vd5sytf94.fsf@assigned-by-dhcp.cox.net","threadId":"7","inReplyTo":null,"subject":"[PATCH] teach ls-tree how to handle names with embedded LF","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-04-13T23:43:03Z","receivedAt":"2005-04-13T23:43:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"GIT dircache can represent filenames with embedded newline.\nGive ls-tree an option to terminate its output with '\\0', so that\nits output can be further processed with tools like \"sort -z\"\n(and custom perl/python scripts).\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n ls-tree.c |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletion(-)\n\nls-tree.c:  3e2a6c7d183a42e41f1073dfec6794e8f8a5e75c\n--- ls-tree.c\n+++ ls-tree.c\t2005-04-13 16:17:29.000000000 -0700\n@@ -5,6 +5,8 @@\n  */\n #include \"cache.h\"\n \n+int line_termination = '\\n';\n+\n static int list(unsigned char *sha1)\n {\n \tvoid *buffer;\n@@ -31,7 +33,8 @@\n \t\t * It seems not worth it to read each file just to get this\n \t\t * and the file size. -- pasky@ucw.cz */\n \t\ttype = S_ISDIR(mode) ? \"tree\" : \"blob\";\n-\t\tprintf(\"%03o\\t%s\\t%s\\t%s\\n\", mode, type, sha1_to_hex(sha1), path);\n+\t\tprintf(\"%03o\\t%s\\t%s\\t%s%c\", mode, type, sha1_to_hex(sha1),\n+\t\t       path, line_termination);\n \t}\n \treturn 0;\n }\n@@ -40,6 +43,10 @@\n {\n \tunsigned char sha1[20];\n \n+\tif (argc == 3 && !strcmp(argv[1], \"-z\")) {\n+\t  line_termination = 0;\n+\t  argc--; argv++;\n+\t}\n \tif (argc != 2)\n \t\tusage(\"ls-tree <key>\");\n \tif (get_sha1_hex(argv[1], sha1) < 0)\n\n---\nhead before this patch: f6803ddd4e97a8b0cc090c546d1ff085ed0a4316\ntree after  this patch: 0aa0af6254226f0811c72282c46e7e4d9438371c\nhead after  this patch: 63582e5e8c40790d6255206d6bde65f4ce3820bf\n\n"},{"id":"23","messageId":"20050413235018.GQ25711@pasky.ji.cz","threadId":"7","inReplyTo":"7vd5sytf94.fsf@assigned-by-dhcp.cox.net","subject":"Re: teach ls-tree how to handle names with embedded LF","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-04-13T23:50:18Z","receivedAt":"2005-04-13T23:50:18Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Thu, Apr 14, 2005 at 01:43:03AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> told me that...\n> GIT dircache can represent filenames with embedded newline.\n> Give ls-tree an option to terminate its output with '\\0', so that\n> its output can be further processed with tools like \"sort -z\"\n> (and custom perl/python scripts).\n\nActually, what about just making it consistent with diff-tree and making\nit always terminate the records with '\\0'?\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"24","messageId":"7v7jj6tdq9.fsf@assigned-by-dhcp.cox.net","threadId":"7","inReplyTo":"20050413235018.GQ25711@pasky.ji.cz","subject":"Re: teach ls-tree how to handle names with embedded LF","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-04-14T00:15:58Z","receivedAt":"2005-04-14T00:15:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"PB\" == Petr Baudis <pasky@ucw.cz> writes:\n\nPB> Actually, what about just making it consistent with diff-tree and making\nPB> it always terminate the records with '\\0'?\n\nSounds good to me.  I need '-z' for a script I am working on to\ngenerate data for incremental updates of object database.\n\n"},{"id":"25","messageId":"20050414002037.GS25711@pasky.ji.cz","threadId":"7","inReplyTo":"7v7jj6tdq9.fsf@assigned-by-dhcp.cox.net","subject":"Re: Re: teach ls-tree how to handle names with embedded LF","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-04-14T00:20:37Z","receivedAt":"2005-04-14T00:20:37Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Thu, Apr 14, 2005 at 02:15:58AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> told me that...\n> >>>>> \"PB\" == Petr Baudis <pasky@ucw.cz> writes:\n> \n> PB> Actually, what about just making it consistent with diff-tree and making\n> PB> it always terminate the records with '\\0'?\n> \n> Sounds good to me.  I need '-z' for a script I am working on to\n> generate data for incremental updates of object database.\n\nI actually use ls-tree only in various one-shot hacks, so it's not an\nissue for me neither.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"}]}