git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Ivo Anjo <knuckles@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: Bug in git-filter-branch example
Date: Mon, 1 Feb 2010 07:43:45 -0500	[thread overview]
Message-ID: <20100201124345.GA32532@coredump.intra.peff.net> (raw)
In-Reply-To: <557ea2711002010348m57aa31fesd1047cbe3f01cb0b@mail.gmail.com>

On Mon, Feb 01, 2010 at 11:48:27AM +0000, Ivo Anjo wrote:

>     To move the whole tree into a subdirectory, or remove it from there:
> 
>     git filter-branch --index-filter \
>             'git ls-files -s | sed "s-\t-&newsubdir/-" |
>                     GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>                             git update-index --index-info &&
>              mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
> 
> 
> The problem is with filenames that use complex utf8 (non-ascii?) chars:

Yes, that is definitely the problem. update-index unquotes its input, as
you would expect, but the sed munging does not take the quote into
account. You can fix it by doing:

  sed "s-\t\"*-&newsubdir/-"

instead. Here is a patch to fix the documentation. I am slightly unsure
of whether it should be applied. These examples are supposed to be
simple and readable to help the user understand what the filters can do.
And this makes it somewhat less simple for the sake of a special case.
But at the same time, users are going to cut-and-paste these examples (I
know I have), and the special case is not _that_ special, especially for
non-English speakers. And having it in the example helps make people
aware that quoted paths are a reality.

So I think on balance it is probably better to fix it.

Note also that another way of "fixing" this would be to set
core.quotepath to false (which is something you probably want to do
anyway if you are using utf8 characters in your filenames). And I put
"fix" in quotes because you still may run across quoted paths, but they
will be much less common; you will only see them if you have control
characters or other insanity in your paths.

-- >8 --
Subject: [PATCH] docs: fix filter-branch example for quoted paths

If there is a quoted path, update-index will correctly
unquote it. However, we must take care to put our new prefix
inside the double-quote.

Signed-off-by: Jeff King <peff@peff.net>
---
 Documentation/git-filter-branch.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index cfaba2a..020028c 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -358,7 +358,7 @@ To move the whole tree into a subdirectory, or remove it from there:
 
 ---------------------------------------------------------------
 git filter-branch --index-filter \
-	'git ls-files -s | sed "s-\t-&newsubdir/-" |
+	'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
 		GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
 			git update-index --index-info &&
 	 mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
-- 
1.7.0.rc1.16.g21332.dirty

  reply	other threads:[~2010-02-01 12:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 11:48 Bug in git-filter-branch example Ivo Anjo
2010-02-01 12:43 ` Jeff King [this message]
2010-02-01 12:57 ` Johannes Sixt

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=20100201124345.GA32532@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=knuckles@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).