Re: git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc.

From: Randal L. Schwartz <hidden>
Date: 2016-06-15 22:43:09

quoted
quoted
quoted
quoted
"Jim" == Jim Meyering [off-list ref] 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
[off-list ref] <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!

Re: git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc.

From: Jan Hudec <hidden>
Date: 2016-06-15 22:43:09

On Tue, May 08, 2007 at 13:51:01 -0700, Randal L. Schwartz wrote:
quoted
quoted
quoted
quoted
quoted
"Jim" == Jim Meyering [off-list ref] 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 [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help