Git development
 help / color / mirror / Atom feed
* git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc.
@ 2007-05-08 20:32 Jim Meyering
  2007-05-08 20:51 ` Randal L. Schwartz
  0 siblings, 1 reply; 8+ messages in thread
From: Jim Meyering @ 2007-05-08 20:32 UTC (permalink / raw)
  To: git

Not that it matters (or maybe this is a feature :-), because people
who create such files in their working directory deserve what they
get, Eh? :-)

But if leaving it, then perhaps git-clean should at least warn
that it's not doing its job (i.e. remove the uses of rm's "-f").

To reproduce, run these commands:

nl='
'
git-init > /dev/null && touch "x\\n\"$nl" && git-clean && ls -b

Here's the output I get:

    Removing "x\\n\"\n"
    .git/  x\\n"\n

git-clean.sh needs to strip off leading and trailing double quotes (easy)
as well as convert escapees back to originals (not easy as you might
think, in sh) before running rm.  Good excuse to rewrite it in perl.

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

* Re: git-clean fails to remove a file whose name contains \\, ", or  \n, TAB, etc.
  2007-05-08 20:32 git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc Jim Meyering
@ 2007-05-08 20:51 ` Randal L. Schwartz
  2007-05-08 20:53   ` Junio C Hamano
  2007-05-08 23:11   ` Jan Hudec
  0 siblings, 2 replies; 8+ messages in thread
From: Randal L. Schwartz @ 2007-05-08 20:51 UTC (permalink / raw)
  To: Jim Meyering; +Cc: git

>>>>> "Jim" == Jim Meyering <jim@meyering.net> writes:

Jim> Not that it matters (or maybe this is a feature :-), because people
Jim> who create such files in their working directory deserve what they
Jim> get, Eh? :-)

The problem is the newline in the string, since

  git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
  while read -r file; do

is using newline as a delimiter.  Any file with a newline would mess this up.

Not being a shell programming expert, is there a way we could use -z and xargs
-0 here instead?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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

* Re: git-clean fails to remove a file whose name contains \\, ", or  \n, TAB, etc.
  2007-05-08 20:51 ` Randal L. Schwartz
@ 2007-05-08 20:53   ` Junio C Hamano
  2007-05-08 23:11   ` Jan Hudec
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2007-05-08 20:53 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: Jim Meyering, git

merlyn@stonehenge.com (Randal L. Schwartz) writes:

>>>>>> "Jim" == Jim Meyering <jim@meyering.net> writes:
>
> Jim> Not that it matters (or maybe this is a feature :-), because people
> Jim> who create such files in their working directory deserve what they
> Jim> get, Eh? :-)
>
> The problem is the newline in the string, since
>
>   git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
>   while read -r file; do
>
> is using newline as a delimiter.  Any file with a newline would mess this up.
>
> Not being a shell programming expert, is there a way we could use -z and xargs
> -0 here instead?

Funny that we had this discussed on this list a few days ago
;-).

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

* Re: git-clean fails to remove a file whose name contains \\, ", or  \n, TAB, etc.
  2007-05-08 20:51 ` Randal L. Schwartz
  2007-05-08 20:53   ` Junio C Hamano
@ 2007-05-08 23:11   ` Jan Hudec
  2007-05-08 23:18     ` Randal L. Schwartz
  1 sibling, 1 reply; 8+ messages in thread
From: Jan Hudec @ 2007-05-08 23:11 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: Jim Meyering, git

[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]

On Tue, May 08, 2007 at 13:51:01 -0700, Randal L. Schwartz wrote:
> >>>>> "Jim" == Jim Meyering <jim@meyering.net> writes:
> 
> Jim> Not that it matters (or maybe this is a feature :-), because people
> Jim> who create such files in their working directory deserve what they
> Jim> get, Eh? :-)
> 
> The problem is the newline in the string, since
> 
>   git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
>   while read -r file; do
> 
> is using newline as a delimiter.  Any file with a newline would mess this up.
> 
> Not being a shell programming expert, is there a way we could use -z and xargs
> -0 here instead?

Unfortunately read does not have zero-delimited mode (at all). Unfortunately
the backquote expansion does not preserve whitespace correctly, so it's not
possible to use something like head.

Unfortunately there does not seem to be a way to feed newline to read
(without -r flag), because the rules say that '\<NL>' => '' and
'\<something>' => '<something>'.

Than I can't think of anything other than xargs -0. Unfortunately that is an
external command, which only handles simple commands. So the question becomes
how to give it a simple command. Well, there would be two ways:

 - A simple command might be:
	sh -c 'arbitrarily complex command' dummy arguments...
   (the "dummy" will become $0),
   so you can simply put the whole loop in single quotes, use for file; do
   instead of while read -r file; do and be done.

 - Reinvoke the program with special argument meaning it should run the inner
   loop. Ie. add an option --inner-loop option, that would run the
   inner loop and terminate and use xargs -0 "$0" --inner-loop

Both solutions require exporting all the necessary variables.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: git-clean fails to remove a file whose name contains \\, ",  or  \n, TAB, etc.
  2007-05-08 23:11   ` Jan Hudec
@ 2007-05-08 23:18     ` Randal L. Schwartz
  2007-05-08 23:27       ` Karl Hasselström
  0 siblings, 1 reply; 8+ messages in thread
From: Randal L. Schwartz @ 2007-05-08 23:18 UTC (permalink / raw)
  To: Jan Hudec; +Cc: Jim Meyering, git

>>>>> "Jan" == Jan Hudec <bulb@ucw.cz> writes:

Jan> Than I can't think of anything other than xargs -0.

git-ls-files -z .... |
perl -0lne '
   $_ is each name here
'

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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

* Re: git-clean fails to remove a file whose name contains \\, ",  or  \n, TAB, etc.
  2007-05-08 23:18     ` Randal L. Schwartz
@ 2007-05-08 23:27       ` Karl Hasselström
  2007-05-08 23:29         ` Randal L. Schwartz
  0 siblings, 1 reply; 8+ messages in thread
From: Karl Hasselström @ 2007-05-08 23:27 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: Jan Hudec, Jim Meyering, git

On 2007-05-08 16:18:40 -0700, Randal L. Schwartz wrote:

> >>>>> "Jan" == Jan Hudec <bulb@ucw.cz> writes:
>
> Jan> Than I can't think of anything other than xargs -0.
>
> git-ls-files -z .... |
> perl -0lne '
>    $_ is each name here
> '

Have you seen this?

  http://xkcd.com/c224.html

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

* Re: git-clean fails to remove a file whose name contains \\, ",   or  \n, TAB, etc.
  2007-05-08 23:27       ` Karl Hasselström
@ 2007-05-08 23:29         ` Randal L. Schwartz
  2007-05-08 23:38           ` Karl Hasselström
  0 siblings, 1 reply; 8+ messages in thread
From: Randal L. Schwartz @ 2007-05-08 23:29 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: Jan Hudec, Jim Meyering, git

>>>>> "Karl" == Karl Hasselström <kha@treskal.com> writes:

Karl> Have you seen this?

Karl>   http://xkcd.com/c224.html

Yes.  You would be, oh, the 92nd person to point that out to me. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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

* Re: git-clean fails to remove a file whose name contains \\, ",   or  \n, TAB, etc.
  2007-05-08 23:29         ` Randal L. Schwartz
@ 2007-05-08 23:38           ` Karl Hasselström
  0 siblings, 0 replies; 8+ messages in thread
From: Karl Hasselström @ 2007-05-08 23:38 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: Jan Hudec, Jim Meyering, git

On 2007-05-08 16:29:07 -0700, Randal L. Schwartz wrote:

> >>>>> "Karl" == Karl Hasselström <kha@treskal.com> writes:
>
> Karl> Have you seen this?
> Karl>   http://xkcd.com/c224.html
>
> Yes. You would be, oh, the 92nd person to point that out to me. :)

Ah well. At least I sent it to the list too, so everyone can have
their choice of snickering at the comic, or me, whichever seems
silliest. :-)

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

end of thread, other threads:[~2007-05-08 23:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-08 20:32 git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc Jim Meyering
2007-05-08 20:51 ` Randal L. Schwartz
2007-05-08 20:53   ` Junio C Hamano
2007-05-08 23:11   ` Jan Hudec
2007-05-08 23:18     ` Randal L. Schwartz
2007-05-08 23:27       ` Karl Hasselström
2007-05-08 23:29         ` Randal L. Schwartz
2007-05-08 23:38           ` Karl Hasselström

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox