{"thread":{"id":"8043","subject":"git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","startedAt":"2007-05-08T20:32:50Z","lastAt":"2007-05-08T23:38:19Z","messageCount":8,"participants":["Jim Meyering","Randal L. Schwartz","Junio C Hamano","Jan Hudec","Karl Hasselström"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"41495","messageId":"87ps5bhx8t.fsf@rho.meyering.net","threadId":"8043","inReplyTo":null,"subject":"git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2007-05-08T20:32:50Z","receivedAt":"2007-05-08T20:32:50Z","isPatch":false,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Not that it matters (or maybe this is a feature :-), because people\nwho create such files in their working directory deserve what they\nget, Eh? :-)\n\nBut if leaving it, then perhaps git-clean should at least warn\nthat it's not doing its job (i.e. remove the uses of rm's \"-f\").\n\nTo reproduce, run these commands:\n\nnl='\n'\ngit-init > /dev/null && touch \"x\\\\n\\\"$nl\" && git-clean && ls -b\n\nHere's the output I get:\n\n    Removing \"x\\\\n\\\"\\n\"\n    .git/  x\\\\n\"\\n\n\ngit-clean.sh needs to strip off leading and trailing double quotes (easy)\nas well as convert escapees back to originals (not easy as you might\nthink, in sh) before running rm.  Good excuse to rewrite it in perl.\n"},{"id":"41496","messageId":"86k5vj9gzu.fsf@blue.stonehenge.com","threadId":"8043","inReplyTo":"87ps5bhx8t.fsf@rho.meyering.net","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2007-05-08T20:51:01Z","receivedAt":"2007-05-08T20:51:01Z","isPatch":false,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Jim\" == Jim Meyering <jim@meyering.net> writes:\n\nJim> Not that it matters (or maybe this is a feature :-), because people\nJim> who create such files in their working directory deserve what they\nJim> get, Eh? :-)\n\nThe problem is the newline in the string, since\n\n  git-ls-files --others --directory $excl ${excl_info:+\"$excl_info\"} -- \"$@\" |\n  while read -r file; do\n\nis using newline as a delimiter.  Any file with a newline would mess this up.\n\nNot being a shell programming expert, is there a way we could use -z and xargs\n-0 here instead?\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"41497","messageId":"7vbqgv2g1h.fsf@assigned-by-dhcp.cox.net","threadId":"8043","inReplyTo":"86k5vj9gzu.fsf@blue.stonehenge.com","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-08T20:53:30Z","receivedAt":"2007-05-08T20:53:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"merlyn@stonehenge.com (Randal L. Schwartz) writes:\n\n>>>>>> \"Jim\" == Jim Meyering <jim@meyering.net> writes:\n>\n> Jim> Not that it matters (or maybe this is a feature :-), because people\n> Jim> who create such files in their working directory deserve what they\n> Jim> get, Eh? :-)\n>\n> The problem is the newline in the string, since\n>\n>   git-ls-files --others --directory $excl ${excl_info:+\"$excl_info\"} -- \"$@\" |\n>   while read -r file; do\n>\n> is using newline as a delimiter.  Any file with a newline would mess this up.\n>\n> Not being a shell programming expert, is there a way we could use -z and xargs\n> -0 here instead?\n\nFunny that we had this discussed on this list a few days ago\n;-).\n"},{"id":"41508","messageId":"20070508231115.GA14900@efreet.light.src","threadId":"8043","inReplyTo":"86k5vj9gzu.fsf@blue.stonehenge.com","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-05-08T23:11:15Z","receivedAt":"2007-05-08T23:11:15Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Tue, May 08, 2007 at 13:51:01 -0700, Randal L. Schwartz wrote:\n> >>>>> \"Jim\" == Jim Meyering <jim@meyering.net> writes:\n> \n> Jim> Not that it matters (or maybe this is a feature :-), because people\n> Jim> who create such files in their working directory deserve what they\n> Jim> get, Eh? :-)\n> \n> The problem is the newline in the string, since\n> \n>   git-ls-files --others --directory $excl ${excl_info:+\"$excl_info\"} -- \"$@\" |\n>   while read -r file; do\n> \n> is using newline as a delimiter.  Any file with a newline would mess this up.\n> \n> Not being a shell programming expert, is there a way we could use -z and xargs\n> -0 here instead?\n\nUnfortunately read does not have zero-delimited mode (at all). Unfortunately\nthe backquote expansion does not preserve whitespace correctly, so it's not\npossible to use something like head.\n\nUnfortunately there does not seem to be a way to feed newline to read\n(without -r flag), because the rules say that '\\<NL>' => '' and\n'\\<something>' => '<something>'.\n\nThan I can't think of anything other than xargs -0. Unfortunately that is an\nexternal command, which only handles simple commands. So the question becomes\nhow to give it a simple command. Well, there would be two ways:\n\n - A simple command might be:\n\tsh -c 'arbitrarily complex command' dummy arguments...\n   (the \"dummy\" will become $0),\n   so you can simply put the whole loop in single quotes, use for file; do\n   instead of while read -r file; do and be done.\n\n - Reinvoke the program with special argument meaning it should run the inner\n   loop. Ie. add an option --inner-loop option, that would run the\n   inner loop and terminate and use xargs -0 \"$0\" --inner-loop\n\nBoth solutions require exporting all the necessary variables.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"41509","messageId":"86wszi9a5r.fsf@blue.stonehenge.com","threadId":"8043","inReplyTo":"20070508231115.GA14900@efreet.light.src","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2007-05-08T23:18:40Z","receivedAt":"2007-05-08T23:18:40Z","isPatch":false,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Jan\" == Jan Hudec <bulb@ucw.cz> writes:\n\nJan> Than I can't think of anything other than xargs -0.\n\ngit-ls-files -z .... |\nperl -0lne '\n   $_ is each name here\n'\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"41511","messageId":"20070508232702.GB5866@diana.vm.bytemark.co.uk","threadId":"8043","inReplyTo":"86wszi9a5r.fsf@blue.stonehenge.com","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-05-08T23:27:02Z","receivedAt":"2007-05-08T23:27:02Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-05-08 16:18:40 -0700, Randal L. Schwartz wrote:\n\n> >>>>> \"Jan\" == Jan Hudec <bulb@ucw.cz> writes:\n>\n> Jan> Than I can't think of anything other than xargs -0.\n>\n> git-ls-files -z .... |\n> perl -0lne '\n>    $_ is each name here\n> '\n\nHave you seen this?\n\n  http://xkcd.com/c224.html\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"41512","messageId":"86sla699oc.fsf@blue.stonehenge.com","threadId":"8043","inReplyTo":"20070508232702.GB5866@diana.vm.bytemark.co.uk","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2007-05-08T23:29:07Z","receivedAt":"2007-05-08T23:29:07Z","isPatch":false,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Karl\" == Karl Hasselström <kha@treskal.com> writes:\n\nKarl> Have you seen this?\n\nKarl>   http://xkcd.com/c224.html\n\nYes.  You would be, oh, the 92nd person to point that out to me. :)\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"41514","messageId":"20070508233819.GC5866@diana.vm.bytemark.co.uk","threadId":"8043","inReplyTo":"86sla699oc.fsf@blue.stonehenge.com","subject":"Re: git-clean fails to remove a file whose name contains \\\\, \", or \\n, TAB, etc.","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-05-08T23:38:19Z","receivedAt":"2007-05-08T23:38:19Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-05-08 16:29:07 -0700, Randal L. Schwartz wrote:\n\n> >>>>> \"Karl\" == Karl Hasselström <kha@treskal.com> writes:\n>\n> Karl> Have you seen this?\n> Karl>   http://xkcd.com/c224.html\n>\n> Yes. You would be, oh, the 92nd person to point that out to me. :)\n\nAh well. At least I sent it to the list too, so everyone can have\ntheir choice of snickering at the comic, or me, whichever seems\nsilliest. :-)\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}