{"thread":{"id":"489","subject":"[PATCH] cogito: allow filenames with spaces in cg-commit","startedAt":"2005-05-05T15:40:04Z","lastAt":"2005-05-05T15:40:04Z","messageCount":1,"participants":["Jan Veldeman"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2628","messageId":"20050505154004.GA20329@fanta","threadId":"489","inReplyTo":null,"subject":"[PATCH] cogito: allow filenames with spaces in cg-commit","fromName":"Jan Veldeman","fromEmail":"jan.veldeman@advalvas.be","sentAt":"2005-05-05T15:40:04Z","receivedAt":"2005-05-05T15:40:04Z","isPatch":true,"sender":{"key":"jan.veldeman@advalvas.be","avatar":null},"body":"Fixes the filename handling in cg-commit.\n\nTo allow spaces in the filenames, the filenames are kept in an array.\n(The trick with zero bytes is harder to do when storing the filenames in\na variable).\n\"${commitfiles[@]}\" is used where the filenames are needed as separate\narguments, this expands into \"file 1\" \"file 2\" ...\n\"${commitfiles[*]}\" is used when a check is made for the existence of the\nparameter, this expands into \"file1 file 2 ...\"\n\nThe eval changedfiles=($(... | sed ...)) is used to place the result of\ngit-diff-cache into the array. (I couldn't find a cleaner solution to do\nthis)\n\nSigned-off-by: Jan Veldeman <Jan.Veldeman@advalvas.be>\n\nIndex: cogito/cg-commit\n===================================================================\n--- cogito.orig/cg-commit\t2005-05-05 17:13:44.000000000 +0200\n+++ cogito/cg-commit\t2005-05-05 17:34:37.000000000 +0200\n@@ -22,8 +22,8 @@\n fi\n \n if [ \"$1\" ]; then\n-\tcommitfiles=\"$@\"\n-\tcustomfiles=$commitfiles\n+\tcommitfiles=(\"$@\")\n+\tcustomfiles=\"${commitfiles[*]}\"\n \n \t[ \"$ignorecache\" ] && die \"-C and listing files to commit does not make sense\"\n \t[ -s .git/merging ] && die \"cannot commit individual files when merging\"\n@@ -37,8 +37,9 @@\n \t# be committed along automagically as well.\n \n \tif [ ! \"$ignorecache\" ]; then\n-\t\tchangedfiles=$(git-diff-cache $(tree-id) | cut -f 4-)\n-\t\tcommitfiles=\"$addedfiles $remfiles $changedfiles\"\n+\t\teval changedfiles=($(git-diff-cache $(tree-id) | cut -f 4- | \\\n+\t\t\tsed -e 's/^/\"/' -e 's/$/\"/'))\n+\t\tcommitfiles=($addedfiles $remfiles \"${changedfiles[@]}\")\n \tfi\n \n \tmerging=\n@@ -46,11 +47,11 @@\n fi\n \n if [ ! \"$ignorecache\" ]; then\n-\tif [ ! \"$commitfiles\" ]; then\n+\tif [ ! \"${commitfiles[*]}\" ]; then\n \t\techo 'Nothing to commit.' >&2\n \t\texit 2\n \tfi\n-\tfor file in $commitfiles; do\n+\tfor file in \"${commitfiles[@]}\"; do\n \t\t# Prepend a letter describing whether it's addition,\n \t\t# removal or update. Or call git status on those files.\n \t\techo $file;\n@@ -76,13 +77,13 @@\n \n if [ ! \"$ignorecache\" ]; then\n \tif [ \"$customfiles\" ]; then\n-\t\techo $commitfiles | xargs git-update-cache --add --remove \\\n+\t\tgit-update-cache --add --remove \"${commitfiles[@]}\" \\\n \t\t\t|| die \"update-cache failed\"\n \t\texport GIT_INDEX_FILE=$(mktemp -t gitci.XXXXXX)\n \t\tgit-read-tree $(tree-id)\n \tfi\n \t# TODO: Do the proper separation of adds, removes, and changes.\n-\techo $commitfiles | xargs git-update-cache --add --remove \\\n+\tgit-update-cache --add --remove \"${commitfiles[@]}\" \\\n \t\t|| die \"update-cache failed\"\n fi\n \n"}]}