{"thread":{"id":"46847","subject":"What's the idea of specifying binary=true together with textconv?","startedAt":"2017-09-27T19:06:51Z","lastAt":"2017-09-27T19:18:37Z","messageCount":2,"participants":["Ilya Kantor","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"329051","messageId":"CAFU8umg2cgmmCvGYbu0P3M02AMcttUfTCFGTUcsF7shd80XwSw@mail.gmail.com","threadId":"46847","inReplyTo":null,"subject":"What's the idea of specifying binary=true together with textconv?","fromName":"Ilya Kantor","fromEmail":"iliakan@gmail.com","sentAt":"2017-09-27T19:06:25Z","receivedAt":"2017-09-27T19:06:51Z","isPatch":false,"sender":{"key":"iliakan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349336?v=4"},"body":"Hello,\n\nWhen textconv is specified, the program is always used for conversion.\n\nE.g. consider this:\n[diff \"png\"]\n  textconv = wc\n\nEven if a png file is ASCII (manually created), wc gets called, and\nthe result is made of its output.\n\nSo, the question is: why should one specify binary = true together\nwith textconv?\n\nThere is an example in docs:\n[diff \"ps\"]\n  textconv = ps2ascii\n  binary = true\n\n...But what binary = true does here?\nEven if we remove it, textconv is called for all ps-files.\n\n---\nBest Regards,\nIlya Kantor\n"},{"id":"329053","messageId":"20170927191830.qegbaoxtcxzbfkoe@sigill.intra.peff.net","threadId":"46847","inReplyTo":"CAFU8umg2cgmmCvGYbu0P3M02AMcttUfTCFGTUcsF7shd80XwSw@mail.gmail.com","subject":"Re: What's the idea of specifying binary=true together with textconv?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-09-27T19:18:30Z","receivedAt":"2017-09-27T19:18:37Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 27, 2017 at 10:06:25PM +0300, Ilya Kantor wrote:\n\n> When textconv is specified, the program is always used for conversion.\n\nNot always. It's enabled by default for the git-diff and git-log\"\nporcelain, but not for plumbing commands, nor for git-format-patch\n(which needs to create a patch that can be applied). And it can be\ndisabled with --no-textconv.\n\n> E.g. consider this:\n> [diff \"png\"]\n>   textconv = wc\n> \n> Even if a png file is ASCII (manually created), wc gets called, and\n> the result is made of its output.\n> \n> So, the question is: why should one specify binary = true together\n> with textconv?\n> \n> There is an example in docs:\n> [diff \"ps\"]\n>   textconv = ps2ascii\n>   binary = true\n> \n> ...But what binary = true does here?\n> Even if we remove it, textconv is called for all ps-files.\n\nSetting binary=true overrides Git's binary-detection heuristics. When\ntextconv is in effect, those heuristics aren't used at all. But when\nit's disabled, if you want to make sure a file is marked as binary, it\nwould kick in then. For example:\n\n  $ git init\n  $ echo fake-binary >foo.png\n  $ echo \"*.png diff=png\" >.git/info/attributes\n  $ git config diff.png.textconv \"sed s/^/converted:/\"\n  $ git add .\n  $ git commit -m foo\n\n  $ git show\n  ...\n  --- /dev/null\n  +++ b/foo.png\n  @@ -0,0 +1 @@\n  +converted:fake-binary\n\n  $ git format-patch --stdout -1\n  ...\n  --- /dev/null\n  +++ b/foo.png\n  @@ -0,0 +1 @@\n  +fake-binary\n\n  $ git config diff.png.binary true\n  $ git format-patch --stdout -1\n  diff --git a/foo.png b/foo.png\n  new file mode 100644\n  index 0000000000000000000000000000000000000000..96060daf0866dbaf9538b76587f0da801bed4a5f\n  GIT binary patch\n  literal 12\n  TcmYdG%udx!%FIhFs^kIy9YO?D\n  \n  literal 0\n  HcmV?d00001\n\nIt's a pretty rare corner case where this is useful. After all, if your\nfile really isn't binary, then a text patch is actually preferable. But\nyou could imagine cases where the heuristics are wrong (e.g., a single\nNUL very far into the file).\n\n-Peff\n"}]}