pathattr: path based configuration of various attributes.
PATCH 1/2 pathattr: path based configuration of various attributes.
This still does not actually add per-directory "configuration" files nor reading from the global configuration via git_config() yet, but lays the groundwork for implementing them.
The idea is to have sections like these in the configuration files and .gitattributes files in each directory:
[pathattr "text/plain"]
conv_i = crlf
path = "*.txt"
path = "*.c"
path = "*.h"
[pathattr "binary"]
; conv_i = none
; conv_o = none
path = "*.png"
path = "*.mov"
path = "*.mp3"These sections can contain "path", and other variables (let's call the latter "traits").
"path" specifications are used as fnmatch(3) patterns to determine if the traits in the section applies to a given path. Traits give attributes to paths that match the section, and there are currently two traits defined: conv_i and conv_o. These are to specify how to convert what's read from the filesystem before making a blob object out of it, and how to convert a blob object data before writing it out to the filesystem.
These configuration sections are grouped by the directory they were read from, and arranged in a stack, so that we can apply the ones read from the most specific configuration file,just like what we do with the current .gitignore mechanism. In fact, we might want to add "ignore" as the third trait.
---
* This is relative to 'next'; you can cherry pick b875e71 from 'next' on top of 'master' to apply this if you do not want to slurp the remainder of 'next'.
Makefile | 4 +- convert.c | 43 ++++++---------- convert.h | 10 ++++ pathattr.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pathattr.h | 18 +++++++ 5 files changed, 206 insertions(+), 29 deletions(-) create mode 100644 convert.h create mode 100644 pathattr.c create mode 100644 pathattr.h
Makefile +2 -2
@@ -247,7 +247,7 @@ LIB_H = \ diff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h sideband.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \ - utf8.h reflog-walk.h + utf8.h reflog-walk.h pathattr.h DIFF_OBJS = \ diff.o diff-lib.o diffcore-break.o diffcore-order.o \
@@ -260,7 +260,7 @@ LIB_OBJS = \ interpolate.o \ lockfile.o \ object.o pack-check.o patch-delta.o path.o pkt-line.o sideband.o \ - reachable.o reflog-walk.o \ + reachable.o reflog-walk.o pathattr.o \ quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
convert.c +16 -27
77 lines not on this page · raw message
convert.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef CONVERT_H +#define CONVERT_H + +typedef int (*convi_fn )(const char *,char **,unsigned long *); +typedef int (*convo_fn )(const char *,char **,unsigned long *); + +int convi_crlf (const char *path,char **bufp,unsigned long *sizep); +int convo_crlf (const char *path,char **bufp,unsigned long *sizep); + +#endif /* CONVERT_H */
pathattr.c new file +160 -0
160 lines not on this page · raw message
pathattr.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef PATHATTR_H +#define PATHATTR_H + +#include "convert.h" + +/* +* Data in one section of [pathattr "name"], except +* the path match specification. +*/ +struct pathattr { +char *name; +convi_fn conv_i; +convo_fn conv_o; +}; + +const struct pathattr *pathattr_lookup (const char *); + +#endif /* PATHATTR_H */
Signature · 1 line
1.5.0.2.809.g0f936
Quoted 5 lines · Junio C Hamano
[pathattr "text/plain"]
conv_i = crlf
path = "*.txt"
path = "*.c"
path = "*.h"Can I suggest that "crlf" is not the right name for something like this? What you actually want is to say
conv_i = convert_from_local_lineendings
conv_o = convert_to_local_lineendings
(Obviously I'm not really suggesting such long names). "crlf" implies that you want to convert to crlf endings /whatever/ the local line ending. Given that exactly the same .gitattributes would be in use on both windows and linux for the same repository, it's got to be an attribute name that makes sense in both cases. How about:
conv_i = eol_to_lf
conv_o = eol_to_local
I'm not sure about "conv" either. "filter" would be more accurate.
infilter = eol_to_lf
outfilter = eol_to_local
--- Wild rantings start here, ignore at will ---
Also; for things like Ted's example of OpenDocument files, you might want
infilter = gunzip
outfilter = gzip
Then of course, order has to be significant:
infilter = gunzip eol_to_lf
outfilter = eol_to_local gzip
(That's probably a crazy thing to want to do, but it would make git spectacularly impressive). Here's another idea, what about making the filters configurable, with some builtin (and overridable)
[infilter "perfectpatch"]
exec = hooks/perfectpatch
[infilter "codingstandards"]
exec = scripts/check-for-spaces-in-the-wrong-place
[pathattr "text/c"]
infilter = perfectpatch
path = *.cc
path = *.cpp
path = *.c
path = *.C
path = *.h
We could also support a prettyfilter for getting your display example from patch 2/2 in the right place.
[prettyfilter]
exec = display -
[pathattr "image/"]
prettyfilter = rundisplay
path = *.png
Which would be equally good for fixing line endings for display; prettyfilter could, I suppose, default to be the same as outfilter, which would be correct in most cases.
[pathattr "text/c"]
prettyfilter = eol_to_local
Sorry for the long rambling email, it's very exciting this attribute stuff. I already love it.
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Quoted 8 lines · Andy Parkins
Quoted 5 lines · Junio C Hamano
[pathattr "text/plain"] conv_i = crlf path = "*.txt" path = "*.c" path = "*.h"
Quoted 5 lines
Can I suggest that "crlf" is not the right name for something like this? What you actually want is to say
conv_i=convert_from_local_lineendings
conv_o=convert_to_local_lineendings
The sample traits' value "crlf" is probably a misnomer. As you noticed, they are to _force_ the conversion. You can add one that honors core.autocrlf (which would be set to true on Windows and to false on UNIX).
Quoted 2 lines
conv_i=eol_to_lf
conv_o=eol_to_local
Probably.
Quoted 1 line
--- Wild rantings start here, ignore at will ---
Will ignore for now, since I have more interesting patches coming for your enjoyment ;-).