{"thread":{"id":"26189","subject":"PostScript files: textconv and \"git add -p\"","startedAt":"2011-01-04T15:50:44Z","lastAt":"2011-01-11T06:11:14Z","messageCount":7,"participants":["Matthieu Moy","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"158894","messageId":"vpqy670brcb.fsf@bauges.imag.fr","threadId":"26189","inReplyTo":null,"subject":"PostScript files: textconv and \"git add -p\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-01-04T15:50:44Z","receivedAt":"2011-01-04T15:50:44Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Hi (and happy new year everybody !),\n\nI have trouble setting up a comfortable configuration to version\nPostScript files. The particularity they have is that they are \"text\nfiles\" (i.e. git does not detect them as binary files by default, and\nneither do tools like less, diff, ...), but not meant to be\nhuman-readable.\n\nIf I do this:\n\n,----[ .gitattributes ]\n| *.ps diff=ps\n`----\n\n,----[ .gitconfig ]\n| [diff \"ps\"]\n|       textconv=ps2ascii\n`----\n\nthen I get the textconv niceness when running \"git diff\", which is\ncool, but \"git add -p\" still proposes me to stage hunks one by one,\nwhich isn't.\n\nIf I set \"*.ps binary\" in .gitattributes, \"git add -p\" becomes quiet,\nbut textconv is disabled.\n\nI want \"git diff\" to run the textconv filter, and \"git add -p\" to\nconsider the file as binary. Is there a way to do this?\n\nThanks,\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"158942","messageId":"20110105051807.GB5884@sigill.intra.peff.net","threadId":"26189","inReplyTo":"vpqy670brcb.fsf@bauges.imag.fr","subject":"Re: PostScript files: textconv and \"git add -p\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-01-05T05:18:07Z","receivedAt":"2011-01-05T05:18:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 04, 2011 at 04:50:44PM +0100, Matthieu Moy wrote:\n\n> If I do this:\n> \n> ,----[ .gitattributes ]\n> | *.ps diff=ps\n> `----\n> \n> ,----[ .gitconfig ]\n> | [diff \"ps\"]\n> |       textconv=ps2ascii\n> `----\n> \n> then I get the textconv niceness when running \"git diff\", which is\n> cool, but \"git add -p\" still proposes me to stage hunks one by one,\n> which isn't.\n> \n> If I set \"*.ps binary\" in .gitattributes, \"git add -p\" becomes quiet,\n> but textconv is disabled.\n\nYeah the \"binary\" attribute (which is a synonym for !diff along with\nsome crlf stuff) and \"diff\" are mutually exclusive. One says \"don't diff\nthis\" and the other says \"diff this according to some special rules\".\nBut fortunately, those special rules can contain \"this is binary\". So\nyou can get what you want with:\n\n  echo '*.ps diff=ps' >.gitattributes\n  git config diff.ps.textconv ps2ascii\n  git config diff.ps.binary true\n\nwhich will textconv the file in the usual places, but consider it binary\nin all other circumstances (like \"add -p\").\n\n-Peff\n\nPS Your question made me very happy. I implemented \"diff.*.binary\" the\n   way I did out of a vague sense of orthogonality, but I never quite\n   came up with a concrete example where it was useful to set both.\n   Thanks for providing one. :)\n"},{"id":"159251","messageId":"vpqr5clsy8g.fsf@bauges.imag.fr","threadId":"26189","inReplyTo":"20110105051807.GB5884@sigill.intra.peff.net","subject":"Re: PostScript files: textconv and \"git add -p\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-01-09T18:55:43Z","receivedAt":"2011-01-09T18:55:43Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jeff King <peff@peff.net> writes:\n\n> you can get what you want with:\n>\n>   echo '*.ps diff=ps' >.gitattributes\n>   git config diff.ps.textconv ps2ascii\n>   git config diff.ps.binary true\n\nYes, this works great. Thanks.\n\nDid I miss something, or is this undocumented? I can't find that in\neither man gitattributes or man git-config.\n\n> PS Your question made me very happy. I implemented \"diff.*.binary\" the\n>    way I did out of a vague sense of orthogonality, but I never quite\n>    came up with a concrete example where it was useful to set both.\n>    Thanks for providing one. :)\n\nI vaguely remember such discussions, and may well have thought \"hmm,\nyet another overkill stuff that nobody'll ever use\" at that time ;-).\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"159254","messageId":"20110109201003.GA4406@sigill.intra.peff.net","threadId":"26189","inReplyTo":"vpqr5clsy8g.fsf@bauges.imag.fr","subject":"[PATCH] docs: explain diff.*.binary option","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-01-09T20:10:04Z","receivedAt":"2011-01-09T20:10:04Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This was added long ago as part of the userdiff refactoring\nfor textconv, as internally it made the code simpler and\ncleaner. However, there was never a concrete use case for\nactually using the config variable.\n\nNow that Matthieu Moy has provided such a use case, it's\neasy to explain it using his example.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nOn Sun, Jan 09, 2011 at 07:55:43PM +0100, Matthieu Moy wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > you can get what you want with:\n> >\n> >   echo '*.ps diff=ps' >.gitattributes\n> >   git config diff.ps.textconv ps2ascii\n> >   git config diff.ps.binary true\n> \n> Yes, this works great. Thanks.\n> \n> Did I miss something, or is this undocumented? I can't find that in\n> either man gitattributes or man git-config.\n\nNope, it was never documented, probably because I never figured out what\nit was good for. :)\n\n Documentation/gitattributes.txt |   33 +++++++++++++++++++++++++++++++++\n 1 files changed, 33 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex 22b8582..a282adb 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -591,6 +591,39 @@ and now produces better output), you can remove the cache\n manually with `git update-ref -d refs/notes/textconv/jpg` (where\n \"jpg\" is the name of the diff driver, as in the example above).\n \n+Marking files as binary\n+^^^^^^^^^^^^^^^^^^^^^^^\n+\n+Git usually guesses correctly whether a blob contains text or binary\n+data by examining the beginning of the contents. However, sometimes you\n+may want to override its decision, either because a blob contains binary\n+data later in the file, or because the content, while technically\n+composed of text characters, is opaque to a human reader. For example,\n+many postscript files contain only ascii characters, but produce noisy\n+and meaningless diffs.\n+\n+The simplest way to mark a file as binary is to unset the diff\n+attribute in the `.gitattributes` file:\n+\n+------------------------\n+*.ps -diff\n+------------------------\n+\n+This will cause git to generate `Binary files differ` (or a binary\n+patch, if binary patches are enabled) instead of a regular diff.\n+\n+However, one may also want to specify other diff driver attributes. For\n+example, you might want to use `textconv` to convert postscript files to\n+an ascii representation for human viewing, but otherwise treat them as\n+binary files. You cannot specify both `-diff` and `diff=ps` attributes.\n+The solution is to use the `diff.*.binary` config option:\n+\n+------------------------\n+[diff \"ps\"]\n+  textconv = ps2ascii\n+  binary = true\n+------------------------\n+\n Performing a three-way merge\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n \n-- \n1.7.3.5.4.g0dc52\n"},{"id":"159255","messageId":"vpq7hedsttb.fsf@bauges.imag.fr","threadId":"26189","inReplyTo":"20110109201003.GA4406@sigill.intra.peff.net","subject":"Re: [PATCH] docs: explain diff.*.binary option","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-01-09T20:31:12Z","receivedAt":"2011-01-09T20:31:12Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jeff King <peff@peff.net> writes:\n\n> This was added long ago as part of the userdiff refactoring\n> for textconv, as internally it made the code simpler and\n> cleaner. However, there was never a concrete use case for\n> actually using the config variable.\n>\n> Now that Matthieu Moy has provided such a use case, it's\n> easy to explain it using his example.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n\nAcked-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>\n\nThanks,\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"159280","messageId":"7vpqs463o4.fsf@alter.siamese.dyndns.org","threadId":"26189","inReplyTo":"20110109201003.GA4406@sigill.intra.peff.net","subject":"Re: [PATCH] docs: explain diff.*.binary option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-10T17:59:07Z","receivedAt":"2011-01-10T17:59:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> This was added long ago as part of the userdiff refactoring\n> for textconv, as internally it made the code simpler and\n> cleaner. However, there was never a concrete use case for\n> actually using the config variable.\n>\n> Now that Matthieu Moy has provided such a use case, it's\n> easy to explain it using his example.\n\nThanks.  I take it that this documents 122aa6f (diff: introduce\ndiff.<driver>.binary, 2008-10-05) where you said...\n\n    This patch introduces a \"binary\" config option for a diff\n    driver, so that one can explicitly set diff.foo.binary. We\n    default this value to \"don't know\". That is, setting a diff\n    attribute to \"foo\" and using \"diff.foo.funcname\" will have\n    no effect on the binaryness of a file. To get the current\n    behavior, one can set diff.foo.binary to true.\n\nI am scratching my head about the last sentence, though.  Shouldn't that\nbe \"false\"?  In the olden days, setting diff.foo.funcname made it text but\nwith this change it no longer is the case and instead binaryness is\ndetermined by content inspection, so forcing \"text\" needs to be done by\nsaying \"this is _not_ binary\", no?\n"},{"id":"159303","messageId":"20110111061114.GE10094@sigill.intra.peff.net","threadId":"26189","inReplyTo":"7vpqs463o4.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] docs: explain diff.*.binary option","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-01-11T06:11:14Z","receivedAt":"2011-01-11T06:11:14Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 10, 2011 at 09:59:07AM -0800, Junio C Hamano wrote:\n\n> Thanks.  I take it that this documents 122aa6f (diff: introduce\n> diff.<driver>.binary, 2008-10-05) where you said...\n> \n>     This patch introduces a \"binary\" config option for a diff\n>     driver, so that one can explicitly set diff.foo.binary. We\n>     default this value to \"don't know\". That is, setting a diff\n>     attribute to \"foo\" and using \"diff.foo.funcname\" will have\n>     no effect on the binaryness of a file. To get the current\n>     behavior, one can set diff.foo.binary to true.\n> \n> I am scratching my head about the last sentence, though.  Shouldn't that\n> be \"false\"?  In the olden days, setting diff.foo.funcname made it text but\n> with this change it no longer is the case and instead binaryness is\n> determined by content inspection, so forcing \"text\" needs to be done by\n> saying \"this is _not_ binary\", no?\n\nYeah, that definitely should be \"false\". I think it was simply a think-o\nwhen typing the commit message (and I just did a quick test to double\ncheck that the behavior described by the message is in fact what\nhappens).\n\nReading that thread, too, I think I was a little confused at first back\nthen about how diff.*.binary would be used with respect to textconv, but\nbetween some thinking and JSixt beating some sense into me, it came out\nwith at least the correct semantics, if not an accurate commit message.\n:)\n\n-Peff\n"}]}