{"thread":{"id":"18199","subject":"git am --rebasing clobbers commit encoding","startedAt":"2009-03-07T16:38:02Z","lastAt":"2009-03-07T16:38:02Z","messageCount":1,"participants":["Nikolaus Schulz"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"107309","messageId":"20090307163802.GA25501@luigi.zusammrottung.local","threadId":"18199","inReplyTo":null,"subject":"git am --rebasing clobbers commit encoding","fromName":"Nikolaus Schulz","fromEmail":"microschulz@web.de","sentAt":"2009-03-07T16:38:02Z","receivedAt":"2009-03-07T16:38:02Z","isPatch":false,"sender":{"key":"microschulz@web.de","avatar":null},"body":"Hi,\n\ncommit 5e835cac \"rebase: do not munge commit log message\", aiming to fix\nrebasing of commits with multiple lines in the first paragraph of the\ncommit message, has broken rebasing of commits which are not encoded in\ni18n.commitEncoding.\n\nHere's the patch from 5e835cac:\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 245e1db..5a7695e 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -327,11 +327,20 @@ do\n \t\t\techo \"Patch is empty.  Was it split wrong?\"\n \t\t\tstop_here $this\n \t\t}\n-\t\tSUBJECT=\"$(sed -n '/^Subject/ s/Subject: //p' \"$dotest/info\")\"\n-\t\tcase \"$keep_subject\" in -k)  SUBJECT=\"[PATCH] $SUBJECT\" ;; esac\n-\n-\t\t(echo \"$SUBJECT\" ; echo ; cat \"$dotest/msg\") |\n-\t\t\tgit stripspace > \"$dotest/msg-clean\"\n+\t\tif test -f \"$dotest/rebasing\" &&\n+\t\t\tcommit=$(sed -e 's/^From \\([0-9a-f]*\\) .*/\\1/' \\\n+\t\t\t\t-e q \"$dotest/$msgnum\") &&\n+\t\t\ttest \"$(git cat-file -t \"$commit\")\" = commit\n+\t\tthen\n+\t\t\tgit cat-file commit \"$commit\" |\n+\t\t\tsed -e '1,/^$/d' >\"$dotest/msg-clean\"\n+\t\telse\n+\t\t\tSUBJECT=\"$(sed -n '/^Subject/ s/Subject: //p' \"$dotest/info\")\"\n+\t\t\tcase \"$keep_subject\" in -k)  SUBJECT=\"[PATCH] $SUBJECT\" ;; esac\n+\n+\t\t\t(echo \"$SUBJECT\" ; echo ; cat \"$dotest/msg\") |\n+\t\t\t\tgit stripspace > \"$dotest/msg-clean\"\n+\t\tfi\n \t\t;;\n \tesac\n \nThe problem is, that \"git cat-file commit .. | sed -e '1,/^$/d'\"\ndiscards the commit encoding header.  The commit message is taken as-is,\nbut later committed with the current i18n.commitEncoding.\n\nI'm working on several machines, some of which use the legacy latin1\nencoding; if I push a latin1-encoded commit to a machine using utf-8,\nand rebase it there, the commits messages are corrupted.\n\nThis is particularly unlucky since with correct commit messages (no\nmultiple lines in first paragraph), \"$dotest/msg\" is perfectly fine, and\nthe above patch is not needed anyway.\n\nUnfortunately, I don't see an easy way to fix this.  It seems to me that\nrecoding commit messages isn't really supported: commits are _always_\ndone with the configured i18n.commitencoding, and the only place where\nrecoding takes place is processing of patches sent by email, where\ngit-mailinfo recodes the commit message.  And commit 5e835cac has\nbypassed git-mailinfo in git-am for rebasing.\n\nI guess we cannot call iconv(1) after git cat-file because that's not\nportable, and there is no plumbing command that can be used from a shell\nscript to convert the encoding of a commit; the functionality is in\nutf8.c:reencode_string(), so only C code can use it.\n\nNikolaus\n"}]}