* PostScript files: textconv and "git add -p" @ 2011-01-04 15:50 Matthieu Moy 2011-01-05 5:18 ` Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Matthieu Moy @ 2011-01-04 15:50 UTC (permalink / raw) To: git Hi (and happy new year everybody !), I have trouble setting up a comfortable configuration to version PostScript files. The particularity they have is that they are "text files" (i.e. git does not detect them as binary files by default, and neither do tools like less, diff, ...), but not meant to be human-readable. If I do this: ,----[ .gitattributes ] | *.ps diff=ps `---- ,----[ .gitconfig ] | [diff "ps"] | textconv=ps2ascii `---- then I get the textconv niceness when running "git diff", which is cool, but "git add -p" still proposes me to stage hunks one by one, which isn't. If I set "*.ps binary" in .gitattributes, "git add -p" becomes quiet, but textconv is disabled. I want "git diff" to run the textconv filter, and "git add -p" to consider the file as binary. Is there a way to do this? Thanks, -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PostScript files: textconv and "git add -p" 2011-01-04 15:50 PostScript files: textconv and "git add -p" Matthieu Moy @ 2011-01-05 5:18 ` Jeff King 2011-01-09 18:55 ` Matthieu Moy 0 siblings, 1 reply; 7+ messages in thread From: Jeff King @ 2011-01-05 5:18 UTC (permalink / raw) To: Matthieu Moy; +Cc: git On Tue, Jan 04, 2011 at 04:50:44PM +0100, Matthieu Moy wrote: > If I do this: > > ,----[ .gitattributes ] > | *.ps diff=ps > `---- > > ,----[ .gitconfig ] > | [diff "ps"] > | textconv=ps2ascii > `---- > > then I get the textconv niceness when running "git diff", which is > cool, but "git add -p" still proposes me to stage hunks one by one, > which isn't. > > If I set "*.ps binary" in .gitattributes, "git add -p" becomes quiet, > but textconv is disabled. Yeah the "binary" attribute (which is a synonym for !diff along with some crlf stuff) and "diff" are mutually exclusive. One says "don't diff this" and the other says "diff this according to some special rules". But fortunately, those special rules can contain "this is binary". So you can get what you want with: echo '*.ps diff=ps' >.gitattributes git config diff.ps.textconv ps2ascii git config diff.ps.binary true which will textconv the file in the usual places, but consider it binary in all other circumstances (like "add -p"). -Peff PS Your question made me very happy. I implemented "diff.*.binary" the way I did out of a vague sense of orthogonality, but I never quite came up with a concrete example where it was useful to set both. Thanks for providing one. :) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PostScript files: textconv and "git add -p" 2011-01-05 5:18 ` Jeff King @ 2011-01-09 18:55 ` Matthieu Moy 2011-01-09 20:10 ` [PATCH] docs: explain diff.*.binary option Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Matthieu Moy @ 2011-01-09 18:55 UTC (permalink / raw) To: Jeff King; +Cc: git Jeff King <peff@peff.net> writes: > you can get what you want with: > > echo '*.ps diff=ps' >.gitattributes > git config diff.ps.textconv ps2ascii > git config diff.ps.binary true Yes, this works great. Thanks. Did I miss something, or is this undocumented? I can't find that in either man gitattributes or man git-config. > PS Your question made me very happy. I implemented "diff.*.binary" the > way I did out of a vague sense of orthogonality, but I never quite > came up with a concrete example where it was useful to set both. > Thanks for providing one. :) I vaguely remember such discussions, and may well have thought "hmm, yet another overkill stuff that nobody'll ever use" at that time ;-). -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] docs: explain diff.*.binary option 2011-01-09 18:55 ` Matthieu Moy @ 2011-01-09 20:10 ` Jeff King 2011-01-09 20:31 ` Matthieu Moy 2011-01-10 17:59 ` Junio C Hamano 0 siblings, 2 replies; 7+ messages in thread From: Jeff King @ 2011-01-09 20:10 UTC (permalink / raw) To: Matthieu Moy; +Cc: Junio C Hamano, git This was added long ago as part of the userdiff refactoring for textconv, as internally it made the code simpler and cleaner. However, there was never a concrete use case for actually using the config variable. Now that Matthieu Moy has provided such a use case, it's easy to explain it using his example. Signed-off-by: Jeff King <peff@peff.net> --- On Sun, Jan 09, 2011 at 07:55:43PM +0100, Matthieu Moy wrote: > Jeff King <peff@peff.net> writes: > > > you can get what you want with: > > > > echo '*.ps diff=ps' >.gitattributes > > git config diff.ps.textconv ps2ascii > > git config diff.ps.binary true > > Yes, this works great. Thanks. > > Did I miss something, or is this undocumented? I can't find that in > either man gitattributes or man git-config. Nope, it was never documented, probably because I never figured out what it was good for. :) Documentation/gitattributes.txt | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 22b8582..a282adb 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -591,6 +591,39 @@ and now produces better output), you can remove the cache manually with `git update-ref -d refs/notes/textconv/jpg` (where "jpg" is the name of the diff driver, as in the example above). +Marking files as binary +^^^^^^^^^^^^^^^^^^^^^^^ + +Git usually guesses correctly whether a blob contains text or binary +data by examining the beginning of the contents. However, sometimes you +may want to override its decision, either because a blob contains binary +data later in the file, or because the content, while technically +composed of text characters, is opaque to a human reader. For example, +many postscript files contain only ascii characters, but produce noisy +and meaningless diffs. + +The simplest way to mark a file as binary is to unset the diff +attribute in the `.gitattributes` file: + +------------------------ +*.ps -diff +------------------------ + +This will cause git to generate `Binary files differ` (or a binary +patch, if binary patches are enabled) instead of a regular diff. + +However, one may also want to specify other diff driver attributes. For +example, you might want to use `textconv` to convert postscript files to +an ascii representation for human viewing, but otherwise treat them as +binary files. You cannot specify both `-diff` and `diff=ps` attributes. +The solution is to use the `diff.*.binary` config option: + +------------------------ +[diff "ps"] + textconv = ps2ascii + binary = true +------------------------ + Performing a three-way merge ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 1.7.3.5.4.g0dc52 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] docs: explain diff.*.binary option 2011-01-09 20:10 ` [PATCH] docs: explain diff.*.binary option Jeff King @ 2011-01-09 20:31 ` Matthieu Moy 2011-01-10 17:59 ` Junio C Hamano 1 sibling, 0 replies; 7+ messages in thread From: Matthieu Moy @ 2011-01-09 20:31 UTC (permalink / raw) To: Jeff King; +Cc: Junio C Hamano, git Jeff King <peff@peff.net> writes: > This was added long ago as part of the userdiff refactoring > for textconv, as internally it made the code simpler and > cleaner. However, there was never a concrete use case for > actually using the config variable. > > Now that Matthieu Moy has provided such a use case, it's > easy to explain it using his example. > > Signed-off-by: Jeff King <peff@peff.net> Acked-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> Thanks, -- Matthieu Moy http://www-verimag.imag.fr/~moy/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] docs: explain diff.*.binary option 2011-01-09 20:10 ` [PATCH] docs: explain diff.*.binary option Jeff King 2011-01-09 20:31 ` Matthieu Moy @ 2011-01-10 17:59 ` Junio C Hamano 2011-01-11 6:11 ` Jeff King 1 sibling, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2011-01-10 17:59 UTC (permalink / raw) To: Jeff King; +Cc: Matthieu Moy, git Jeff King <peff@peff.net> writes: > This was added long ago as part of the userdiff refactoring > for textconv, as internally it made the code simpler and > cleaner. However, there was never a concrete use case for > actually using the config variable. > > Now that Matthieu Moy has provided such a use case, it's > easy to explain it using his example. Thanks. I take it that this documents 122aa6f (diff: introduce diff.<driver>.binary, 2008-10-05) where you said... This patch introduces a "binary" config option for a diff driver, so that one can explicitly set diff.foo.binary. We default this value to "don't know". That is, setting a diff attribute to "foo" and using "diff.foo.funcname" will have no effect on the binaryness of a file. To get the current behavior, one can set diff.foo.binary to true. I am scratching my head about the last sentence, though. Shouldn't that be "false"? In the olden days, setting diff.foo.funcname made it text but with this change it no longer is the case and instead binaryness is determined by content inspection, so forcing "text" needs to be done by saying "this is _not_ binary", no? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] docs: explain diff.*.binary option 2011-01-10 17:59 ` Junio C Hamano @ 2011-01-11 6:11 ` Jeff King 0 siblings, 0 replies; 7+ messages in thread From: Jeff King @ 2011-01-11 6:11 UTC (permalink / raw) To: Junio C Hamano; +Cc: Matthieu Moy, git On Mon, Jan 10, 2011 at 09:59:07AM -0800, Junio C Hamano wrote: > Thanks. I take it that this documents 122aa6f (diff: introduce > diff.<driver>.binary, 2008-10-05) where you said... > > This patch introduces a "binary" config option for a diff > driver, so that one can explicitly set diff.foo.binary. We > default this value to "don't know". That is, setting a diff > attribute to "foo" and using "diff.foo.funcname" will have > no effect on the binaryness of a file. To get the current > behavior, one can set diff.foo.binary to true. > > I am scratching my head about the last sentence, though. Shouldn't that > be "false"? In the olden days, setting diff.foo.funcname made it text but > with this change it no longer is the case and instead binaryness is > determined by content inspection, so forcing "text" needs to be done by > saying "this is _not_ binary", no? Yeah, that definitely should be "false". I think it was simply a think-o when typing the commit message (and I just did a quick test to double check that the behavior described by the message is in fact what happens). Reading that thread, too, I think I was a little confused at first back then about how diff.*.binary would be used with respect to textconv, but between some thinking and JSixt beating some sense into me, it came out with at least the correct semantics, if not an accurate commit message. :) -Peff ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-01-11 6:11 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-01-04 15:50 PostScript files: textconv and "git add -p" Matthieu Moy 2011-01-05 5:18 ` Jeff King 2011-01-09 18:55 ` Matthieu Moy 2011-01-09 20:10 ` [PATCH] docs: explain diff.*.binary option Jeff King 2011-01-09 20:31 ` Matthieu Moy 2011-01-10 17:59 ` Junio C Hamano 2011-01-11 6:11 ` Jeff King
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).