All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Hudec <bulb@ucw.cz>
To: "Randal L. Schwartz" <merlyn@stonehenge.com>
Cc: Jim Meyering <jim@meyering.net>, git@vger.kernel.org
Subject: Re: git-clean fails to remove a file whose name contains \\, ", or  \n, TAB, etc.
Date: Wed, 9 May 2007 01:11:15 +0200	[thread overview]
Message-ID: <20070508231115.GA14900@efreet.light.src> (raw)
In-Reply-To: <86k5vj9gzu.fsf@blue.stonehenge.com>

[-- 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 --]

  parent reply	other threads:[~2007-05-08 23:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070508231115.GA14900@efreet.light.src \
    --to=bulb@ucw.cz \
    --cc=git@vger.kernel.org \
    --cc=jim@meyering.net \
    --cc=merlyn@stonehenge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.