{"thread":{"id":"22469","subject":"Bug in git-filter-branch example","startedAt":"2010-02-01T11:48:27Z","lastAt":"2010-02-01T12:57:29Z","messageCount":3,"participants":["Ivo Anjo","Jeff King","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"133241","messageId":"557ea2711002010348m57aa31fesd1047cbe3f01cb0b@mail.gmail.com","threadId":"22469","inReplyTo":null,"subject":"Bug in git-filter-branch example","fromName":"Ivo Anjo","fromEmail":"knuckles@gmail.com","sentAt":"2010-02-01T11:48:27Z","receivedAt":"2010-02-01T11:48:27Z","isPatch":false,"sender":{"key":"knuckles@gmail.com","avatar":null},"body":"I've been working on importing my svn repo into git, and while moving\nsome things around using git-filter-branch I ran into a bug in the\nexample provided on the manpage:\n\n    To move the whole tree into a subdirectory, or remove it from there:\n\n    git filter-branch --index-filter \\\n            'git ls-files -s | sed \"s-\\t-&newsubdir/-\" |\n                    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n                            git update-index --index-info &&\n             mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n\n\nThe problem is with filenames that use complex utf8 (non-ascii?) chars:\n\n> ls -lah Papers/*Lea*\n-rw-r--r-- 1 knuckles users 109K 2010-01-31 18:57 Papers/A Java Fork ⁄\nJoin Framework -- Lea.pdf\n\nas you can see, I'm using '⁄' as a replacement for '/' on that\nfilename, since I obviously can't use '/' on a filename. The problem\nis, git ls-files -s lists that file wrapped in quotes and with the\nchar value escaped\n\n100644 c09309342037fa7d91f37651e2f16e981e4d739a 0    \"Papers/A Java\nFork \\342\\201\\204 Join Framework -- Lea.pdf\"\n\nwhile other files aren't, so the simple sed line provided won't work,\nas it will output the new filename as newsubdir/\"Papers...\n\nI ended up using git filter-branch to remove the offending file (\"if\nall you have is a hammer...\"), and re-adding it after the move.\n\nI'm also left wondering how many uses of git ls-files out there on the\n\"internets\" survive working on a filename such as this one. Maybe git\nls-files should have an option to output the real utf8 file name\ninstead of escaping the bytes...?\n\nIvo Anjo\n"},{"id":"133244","messageId":"20100201124345.GA32532@coredump.intra.peff.net","threadId":"22469","inReplyTo":"557ea2711002010348m57aa31fesd1047cbe3f01cb0b@mail.gmail.com","subject":"Re: Bug in git-filter-branch example","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-02-01T12:43:45Z","receivedAt":"2010-02-01T12:43:45Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 01, 2010 at 11:48:27AM +0000, Ivo Anjo wrote:\n\n>     To move the whole tree into a subdirectory, or remove it from there:\n> \n>     git filter-branch --index-filter \\\n>             'git ls-files -s | sed \"s-\\t-&newsubdir/-\" |\n>                     GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n>                             git update-index --index-info &&\n>              mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n> \n> \n> The problem is with filenames that use complex utf8 (non-ascii?) chars:\n\nYes, that is definitely the problem. update-index unquotes its input, as\nyou would expect, but the sed munging does not take the quote into\naccount. You can fix it by doing:\n\n  sed \"s-\\t\\\"*-&newsubdir/-\"\n\ninstead. Here is a patch to fix the documentation. I am slightly unsure\nof whether it should be applied. These examples are supposed to be\nsimple and readable to help the user understand what the filters can do.\nAnd this makes it somewhat less simple for the sake of a special case.\nBut at the same time, users are going to cut-and-paste these examples (I\nknow I have), and the special case is not _that_ special, especially for\nnon-English speakers. And having it in the example helps make people\naware that quoted paths are a reality.\n\nSo I think on balance it is probably better to fix it.\n\nNote also that another way of \"fixing\" this would be to set\ncore.quotepath to false (which is something you probably want to do\nanyway if you are using utf8 characters in your filenames). And I put\n\"fix\" in quotes because you still may run across quoted paths, but they\nwill be much less common; you will only see them if you have control\ncharacters or other insanity in your paths.\n\n-- >8 --\nSubject: [PATCH] docs: fix filter-branch example for quoted paths\n\nIf there is a quoted path, update-index will correctly\nunquote it. However, we must take care to put our new prefix\ninside the double-quote.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/git-filter-branch.txt |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt\nindex cfaba2a..020028c 100644\n--- a/Documentation/git-filter-branch.txt\n+++ b/Documentation/git-filter-branch.txt\n@@ -358,7 +358,7 @@ To move the whole tree into a subdirectory, or remove it from there:\n \n ---------------------------------------------------------------\n git filter-branch --index-filter \\\n-\t'git ls-files -s | sed \"s-\\t-&newsubdir/-\" |\n+\t'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n \t\tGIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n \t\t\tgit update-index --index-info &&\n \t mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n-- \n1.7.0.rc1.16.g21332.dirty\n"},{"id":"133247","messageId":"4B66CFB9.2060603@viscovery.net","threadId":"22469","inReplyTo":"557ea2711002010348m57aa31fesd1047cbe3f01cb0b@mail.gmail.com","subject":"Re: Bug in git-filter-branch example","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-02-01T12:57:29Z","receivedAt":"2010-02-01T12:57:29Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Ivo Anjo schrieb:\n> I've been working on importing my svn repo into git, and while moving\n> some things around using git-filter-branch I ran into a bug in the\n> example provided on the manpage:\n\nThanks for the report, but: Examples are just that: examples. IMO, it is\nOK that there are implicit assumptions (such as that only \"common\" file\nnames are used in the repo).\n\nMaking the example universally applicable would greatly obfuscate the\nimportant messages.\n\n> I ended up using git filter-branch to remove the offending file (\"if\n> all you have is a hammer...\"), and re-adding it after the move.\n\nIt seems that the example has met its objective: It showed you how to use\nthe hammer, and with your creativity mixed in, it enabled you to use the\nhammer in new ways.\n\n-- Hannes\n"}]}