Add global and system-wide gitattributes
Subsystems (2)
Allow gitattributes to be set globally and system wide in ~/.giattributes and $(prefix)/etc/gitattributes files, respectively. This way, settings for particular file types can be set in one place and apply for all user's repositories.
Contents of those two files are added to the attr_stack struct that contains content of info/attributes, so that prepare_attr_stack() keeps working as is and doesn't have to pop and then put back two more structs (in addition to the "info" one).
Some parts of the code were copied from the implementation of the same functionality in config.c.
---
Hi,
I thought this feature would be useful for me, so I coded it up. What do you think? Is it ready to be included to the official repository as is?
Documentation/gitattributes.txt | 5 ++- Makefile | 6 +++++ attr.c | 43 ++++++++++++++++++++++++++++++++------ configure.ac | 7 ++++++ 4 files changed, 52 insertions(+), 9 deletions(-)
Documentation/gitattributes.txt +3 -2
@@ -7,7 +7,7 @@ gitattributes - defining attributes per path SYNOPSIS -------- -$GIT_DIR/info/attributes, .gitattributes +$GIT_DIR/info/attributes, /etc/gitattributes, ~/.gitattributes, .gitattributes DESCRIPTION
@@ -58,7 +58,8 @@ attribute. The rules how the pattern matches paths are the same as in `.gitignore` files; see linkgit:gitignore[5]. When deciding what attributes are assigned to a path, git -consults `$GIT_DIR/info/attributes` file (which has the highest +consults `$GIT_DIR/info/attributes`, `~/.gitattributes` +and `$(prefix)/etc/gitconfig` files (in order of decreasing precedence), `.gitattributes` file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains `.gitattributes`
Makefile +6 -0
@@ -268,6 +268,7 @@ STRIP ?= strip # infodir # htmldir # ETC_GITCONFIG (but not sysconfdir) +# ETC_GITATTRIBUTES # can be specified as a relative path some/where/else; # this is interpreted as relative to $(prefix) and "git" at # runtime figures out where they are based on the path to the executable.
@@ -286,9 +287,11 @@ htmldir = share/doc/git-doc ifeq ($(prefix),/usr) sysconfdir = /etc ETC_GITCONFIG = $(sysconfdir)/gitconfig +ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes else sysconfdir = $(prefix)/etc ETC_GITCONFIG = etc/gitconfig +ETC_GITATTRIBUTES = etc/gitattributes endif lib = lib # DESTDIR=
@@ -1502,6 +1505,7 @@ endif SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) +ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir))
@@ -1872,6 +1876,8 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' +attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"' + http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' ifdef NO_EXPAT
attr.c +36 -7
82 lines not on this page · raw message
configure.ac +7 -0
@@ -285,6 +285,13 @@ GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, If VALUE is not fully qualified it will be interpretted as a path relative to the computed prefix at runtime.) +# Allow user to set ETC_GITATTRIBUTS variable +GIT_PARSE_WITH_SET_MAKE_VAR(gitattributes, ETC_GITATTRIBUTES, + Use VALUE instead of /etc/gitattributes as the + global git attributes file. + If VALUE is not fully qualified it will be interpretted + as a path relative to the computed prefix at runtime.) + # # Allow user to set the default pager GIT_PARSE_WITH_SET_MAKE_VAR(pager, DEFAULT_PAGER,
Signature · 1 line
1.7.1.msysgit.0.10.g9ffa0
Hi.
Quoted 1 line · Petr Onderka
Allow gitattributes to be set globally and system wide in ~/.giattributes
^^
I assume you mean "~/.gitattributes" (ie missing a 't').
Quoted 3 lines
and $(prefix)/etc/gitattributes files, respectively. This way, settings for particular file types can be set in one place and apply for all user's repositories.
[...]
Quoted 4 lines
Hi,
I thought this feature would be useful for me, so I coded it up. What do you think? Is it ready to be included to the official repository as is?
The feature as such seems reasonable.
Quoted 4 lines
Documentation/gitattributes.txt +0
-0
[...]
Quoted 7 lines
When deciding what attributes are assigned to a path, git
Documentation/gitattributes.txt +2
-1-consults `$GIT_DIR/info/attributes` file (which has the highest +consults `$GIT_DIR/info/attributes`, `~/.gitattributes` +and `$(prefix)/etc/gitconfig` files (in order of decreasingprecedence),
.gitattributesfile in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains.gitattributes
I'm not sure if the above priority order is the most desireable order, since the user may want to set a default attribute, and have it to be overridden by the .gitattributes in the repositories.
configure.ac GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, · line 285
Quoted 6 lines
configure.ac +0
-0@@ -285,6 +285,13 @@ GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, If VALUE is not fully qualified it will be interpretted
^^
Spello (not your fault): "interpreted".
configure.ac GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, · line 292
Quoted 7 lines
configure.ac +5
-0as a path relative to the computed prefix at runtime.) +# Allow user to set ETC_GITATTRIBUTS variable +GIT_PARSE_WITH_SET_MAKE_VAR(gitattributes, ETC_GITATTRIBUTES, + Use VALUE instead of /etc/gitattributes as the + global git attributes file. + If VALUE is not fully qualified it will be interpretted
^^
Same.
configure.ac GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, · line 294
Quoted 2 lines
configure.ac +2
-0+ as a path relative to the computed prefix at runtime.) +
--
Henrik Grubbström [email protected]
Roxen Internet Software AB [email protected]
Hi,
Quoted 4 lines
Quoted 1 line
Allow gitattributes to be set globally and system wide in ~/.giattributes
^^ I assume you mean "~/.gitattributes" (ie missing a 't').
Yeah.
Quoted 3 lines
I'm not sure if the above priority order is the most desireable order, since the user may want to set a default attribute, and have it to be overridden by the .gitattributes in the repositories.
I wasn't sure either. I'm assuming info/gitattributes was made with higher priority, so that that users could override .gitattributes without polluting their repository, so I made the new ones behave the same way. But now that I think of it, you probably want to do that only for a specific repository, and have defaults for all repositories that could be overriden by local .gitattributes. I'm going to rewrite it this way.
Petr Onderka
Quoted 4 lines · Petr Onderka
Allow gitattributes to be set globally and system wide in ~/.giattributes and $(prefix)/etc/gitattributes files, respectively. This way, settings for particular file types can be set in one place and apply for all user's repositories.
The feature is definitely useful, and I'll use it as soon as it gets into git.git ;-).
One point: we need to make sure the choice for the the user-wide filename is the right one, since it's a pain to change it later.
We already have ~/.gitconfig, which often points to ~/.gitexcludes or ~/.gitignored (but this filename is specified with a config variable, for which we didn't manage to agree on a default value). We're about to add ~/.gitattributes. That makes 3 ~/.git* files, and I think it's time to make it a directory (similar to $GIT_DIR/info/)
I think it should be done like this:
1) Default core.excludesfile to $CONF/exclude
2) Make your user-wide gitattribute $CONF/attributes
3) Optionally, read $CONF/config as well as ~/.gitconfig so that people can have all their git configuration in the same directory.
Now, we need to agree on $CONF. Some non-options are:
* CONF=~/.gitconfig would clash with the file ~/.gitconfig
* CONF=~/.git would prevent people from versionning their $HOME.
I'd be in favor of following the freedesktop standard (roughly, defaulting to ~/.config/git):
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
because other applications start using it, and it allows one to easily keep the configuration in a (typically git-versionned) ~/.config directory. And if we are to choose a config directory, it doesn't harm to chose one consistant with other applications and with a standard.
I never got time to implement this. If you're willing to do something like that, that would be great. If not, I'd suggest having a config variable to point to the user-wide gitattributes file (without a default value), because it allows a future transition by giving a default value to the variable.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 4 lines · Petr Onderka
attr.c +0
-0@@ -480,7 +501,15 @@ static void bootstrap_attr_stack(void)debug_push (elem); }
attr.c static void bootstrap_attr_stack(void) · line 512
Quoted 10 lines
attr.c +9
-1- elem =read_attr_from_file (git_path (INFOATTRIBUTES_FILE ),1 ); + elem =read_attr_from_file (git_path (INFOATTRIBUTES_FILE ),1 ,NULL ); + home =get_home_directory (); +if (git_attr_global () && home) { +char *user_attr =xstrdup (mkpath ("%s/%s" , home,GITATTRIBUTES_FILE )); + elem =read_attr_from_file (user_attr,1 , elem); +free (user_attr); + } +if (git_attr_system ()) + elem =read_attr_from_file (git_etc_gitattributes (),1 , elem);
Have you read the comment at the top of prepare-attr-stack? This patch feels triply wrong:
- The attribute stack is arranged to have higher precedence file near the top ($GIT_DIR/info/attributes used to be the highest). The above addition means that ~/.gitattributes from user's home trumps what is in a particular repository. That is backwards. You may work on more than one projects and have more than one repositories. What you share among them personally will go to ~/.gitattributes, while a setting specific to a particular repository goes to $GIT_DIR/info/attributes and the latter needs to be able to override the former.
- Same thing for git_attr_system() being at the end, which means you set up your own $GIT_DIR/info/attributes (or ~/.gitattributes) carefully but that can be broken by a selfish sysadmin who puts stuff that is only useful to him in /etc/gitattributes, which is not what you want.
- Whenever we enter a new directory (either recursing into, or coming back up), prepare_attr_stack() is called to pop the attributes records from now-exited directories and push the attributes records from directories we are about to descend into. The current code knows that the topmost element on the stack is special ($GIT_DIR/info/attributes) and first pops it, adjust the stack for elements that came from the directory hierarcy, and then pushes that back. I don't see any code in the patch to do the equivalent for these two new attribute sources.
Hi,
Quoted 17 lines · Junio C Hamano
Have you read the comment at the top of prepare-attr-stack? This patch feels triply wrong:
- The attribute stack is arranged to have higher precedence file near the top ($GIT_DIR/info/attributes used to be the highest). The above addition means that ~/.gitattributes from user's home trumps what is in a particular repository. That is backwards. You may work on more than one projects and have more than one repositories. What you share among them personally will go to ~/.gitattributes, while a setting specific to a particular repository goes to $GIT_DIR/info/attributes and the latter needs to be able to override the former.
- Same thing for
git_attr_system()being at the end, which means you set up your own $GIT_DIR/info/attributes (or ~/.gitattributes) carefully but that can be broken by a selfish sysadmin who puts stuff that is only useful to him in/etc/gitattributes, which is not what you want.
Quoted 8 lines
- Whenever we enter a new directory (either recursing into, or coming back up),
prepare_attr_stack()is called to pop the attributes records from now-exited directories and push the attributes records from directories we are about to descend into. The current code knows that the topmost element on the stack is special ($GIT_DIR/info/attributes) and first pops it, adjust the stack for elements that came from the directory hierarcy, and then pushes that back. I don't see any code in the patch to do the equivalent for these two new attribute sources.
Yeah, I realize now that I got the precedence wrong, the corrected patch is in the following email.
But to your third point, I read the comment and the code worked, because I put all the attributes from the 3 files into one attr_stack struct (the one at the top of the stack). That's why I changed read_attr_from_file too. Of course this is irrelevant now that those attributes will be at the bottom of the stack.
Petr Onderka
PATCH v2 1/1 Add global and system-wide gitattributes
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
The location of system-wide attributes file is $(prefix)/etc/gitattributes. The location of the global file can be configured by setting core.attributesfile.
Some parts of the code were copied from the implementation of the same functionality in config.c.
---
This version has the correct precedence for global and system-wide attributes.
I decided not to implement having user config files in a directory (at least for now). The location of the global attributes file can be set using core.attributesfile. This setting has no default, as Matthieu suggested.
Documentation/config.txt | 6 +++++ Documentation/gitattributes.txt | 13 ++++++++-- Makefile | 6 +++++ attr.c | 44 ++++++++++++++++++++++++++++++++++++++- cache.h | 1 + config.c | 3 ++ configure.ac | 10 ++++++++- environment.c | 1 + 8 files changed, 79 insertions(+), 5 deletions(-)
Documentation/config.txt +6 -0
@@ -450,6 +450,12 @@ core.excludesfile:: to the value of `$HOME` and "{tilde}user/" to the specified user's home directory. See linkgit:gitignore[5]. +core.attributesfile:: + In addition to '.gitattributes' (per-directory) and + '.git/info/attributes', git looks into this file for attributes + (see linkgit:gitattributes[5]). Path expansions are made the same + way as for `core.excludesfile`. + core.editor:: Commands such as `commit` and `tag` that lets you edit messages by launching an editor uses the value of this
Documentation/gitattributes.txt +10 -3
@@ -62,14 +62,21 @@ consults `$GIT_DIR/info/attributes` file (which has the highest precedence), `.gitattributes` file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains `.gitattributes` -is from the path in question, the lower its precedence). +is from the path in question, the lower its precedence). Finally +global and system-wide files are considered (they have the lowest +precedence). If you wish to affect only a single repository (i.e., to assign -attributes to files that are particular to one user's workflow), then +attributes to files that are particular to +one user's workflow for that repository), then attributes should be placed in the `$GIT_DIR/info/attributes` file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into -`.gitattributes` files. +`.gitattributes` files. Attributes that should affect all repositories +for a single user should be placed in a file specified by the +`core.attributesfile` configuration option (see linkgit:git-config[1]). +Attributes for all users on a system should be placed in the +`$(prefix)/etc/gitattributes` file. Sometimes you would need to override an setting of an attribute for a path to `unspecified` state. This can be done by listing
Makefile +6 -0
@@ -268,6 +268,7 @@ STRIP ?= strip # infodir # htmldir # ETC_GITCONFIG (but not sysconfdir) +# ETC_GITATTRIBUTES # can be specified as a relative path some/where/else; # this is interpreted as relative to $(prefix) and "git" at # runtime figures out where they are based on the path to the executable.
@@ -286,9 +287,11 @@ htmldir = share/doc/git-doc ifeq ($(prefix),/usr) sysconfdir = /etc ETC_GITCONFIG = $(sysconfdir)/gitconfig +ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes else sysconfdir = $(prefix)/etc ETC_GITCONFIG = etc/gitconfig +ETC_GITATTRIBUTES = etc/gitattributes endif lib = lib # DESTDIR=
@@ -1502,6 +1505,7 @@ endif SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) +ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir))
@@ -1872,6 +1876,8 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' +attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"' + http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' ifdef NO_EXPAT
attr.c +43 -1
67 lines not on this page · raw message
cache.h +1 -0
@@ -1030,6 +1030,7 @@ extern int pager_use_color;extern const char *editor_program;extern const char *excludes_file; +extern const char *attributes_file;/* base85 */ int decode_85 (char *dst,const char *line,int linelen);
config.c +3 -0
@@ -563,6 +563,9 @@ static int git_default_core_config(const char *var, const char *value)if (!strcmp (var,"core.excludesfile" ))return git_config_pathname (&excludes_file, var, value); +if (!strcmp (var,"core.attributesfile" )) +return git_config_pathname (&attributes_file, var, value); +if (!strcmp (var,"core.whitespace" )) {if (!value)return config_error_nonbool (var);
configure.ac +9 -1
@@ -282,7 +282,15 @@ GIT_PARSE_WITH(iconv)) GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, Use VALUE instead of /etc/gitconfig as the global git configuration file. - If VALUE is not fully qualified it will be interpretted + If VALUE is not fully qualified it will be interpreted + as a path relative to the computed prefix at runtime.) + +# +# Allow user to set ETC_GITATTRIBUTES variable +GIT_PARSE_WITH_SET_MAKE_VAR(gitattributes, ETC_GITATTRIBUTES, + Use VALUE instead of /etc/gitattributes as the + global git attributes file. + If VALUE is not fully qualified it will be interpreted as a path relative to the computed prefix at runtime.) #
environment.c +1 -0
@@ -38,6 +38,7 @@ const char *pager_program;int pager_use_color =1 ;const char *editor_program;const char *excludes_file; +const char *attributes_file;enum auto_crlf auto_crlf =AUTO_CRLF_FALSE ;int read_replace_refs =1 ;enum eol eol =EOL_UNSET ;
Signature · 1 line
1.7.2.1.2361.g5f8e3
Quoted 3 lines · Petr Onderka
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
[...]
I really can't wait till this gets into Git and I'm certainly not the only one (thank you so much for working on it, Petr!). Any reason the patch still hasn't been applied?
Štěpán
Quoted 10 lines · Štěpán Němec
Quoted 3 lines · Petr Onderka
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
[...]
I really can't wait till this gets into Git and I'm certainly not the only one (thank you so much for working on it, Petr!).
Same here ;-).
Quoted 1 line
Any reason the patch still hasn't been applied?
Usually, patches are applied if either
1) Junio has personal interest in it, or
2) Other people review the code and show interest for it.
I guess none of the conditions were met here (and Junio was very busy these days). I'm sure you can help about point 2) ;-)
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 15 lines · Matthieu Moy
Quoted 10 lines · Štěpán Němec
Quoted 3 lines · Petr Onderka
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
[...]
I really can't wait till this gets into Git and I'm certainly not the only one (thank you so much for working on it, Petr!).
Same here ;-).
Quoted 7 lines
Quoted 1 line
Any reason the patch still hasn't been applied?
Usually, patches are applied if either
1) Junio has personal interest in it, or
2) Other people review the code and show interest for it.
(1) is a bit more subtle than that. Even when I do not foresee using a proposed feature myself, if I can imagine somebody else would benefit, and more importantly if I can see a healthy rationale behind the change so that I can convince myself to be an advocate of that change to the end users, such a change will fall into category (1). That is why I often ask people to justify their changes better than they originally do.
Isn't the patch in question on 'pu' to be tried by interested parties already?
Quoted 19 lines · Junio C Hamano
Quoted 17 lines · Matthieu Moy
Quoted 10 lines · Štěpán Němec
Quoted 3 lines · Petr Onderka
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
[...]
I really can't wait till this gets into Git and I'm certainly not the only one (thank you so much for working on it, Petr!).
Same here ;-).
Quoted 1 line
Any reason the patch still hasn't been applied?
[...]
Quoted 3 lines
Isn't the patch in question on 'pu' to be tried by interested parties already?
I see it now, sorry for the confusion. I didn't check when I saw no response to the mail.
Štěpán
Quoted 7 lines · Petr Onderka
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
The location of system-wide attributes file is $(prefix)/etc/gitattributes. The location of the global file can be configured by setting core.attributesfile.
Good, I like this :-)
Quoted 2 lines
Some parts of the code were copied from the implementation of the same functionality in
config.c.
(maybe you could say quickly which ones and why)
attr.c static void bootstrap_attr_stack(void) · line 503
Quoted 1 line
attr.c +1
-0+if (git_attr_global () && attributes_file) {
I tried this, and attributes_file was NULL here. I don't know how it worked for you, but there should be a call to git_config here.
attr.c static void bootstrap_attr_stack(void) · line 507
Quoted 4 lines
attr.c +4
-0+char *user_attr =xstrdup (attributes_file); + + elem =read_attr_from_file (user_attr,1 ); +free (user_attr);
Any reason for this xstrdup/free?
Patch follows for these two points + a test, to be squashed into yours.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
PATCH 1/1 core.attributesfile: a fix, a simplification, and a test
Patch meant to be squashed into the core.attributesfile.
* attributes_file won't be set unless one calls git_config before => do this.
* There was a useless xstrdup/free in the code.
* This really deserves a test, so I added one in t0003-attributes.sh. (I've been too lazy to check the system-wide attributes file, though)
--- attr.c | 6 ++---- t/t0003-attributes.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-)
attr.c +2 -4
@@ -500,11 +500,9 @@ static void bootstrap_attr_stack(void) } } +git_config (git_default_config,NULL );if (git_attr_global () && attributes_file) { -char *user_attr =xstrdup (attributes_file); - - elem =read_attr_from_file (user_attr,1 ); -free (user_attr); + elem =read_attr_from_file (attributes_file,1 );if (elem) { elem->origin =NULL ; elem->prev = attr_stack;
t/t0003-attributes.sh +14 -0
@@ -15,6 +15,7 @@ attr_check () { } +HOME=$(pwd) test_expect_success 'setup' '
@@ -36,6 +37,9 @@ test_expect_success 'setup' ' echo "d/* test=a/b/d/*" echo "d/yes notest" ) >a/b/.gitattributes + ( + echo "global test=global" + ) >$HOME/global-gitattributes '
@@ -57,6 +61,16 @@ test_expect_success 'attribute test' ' ' +test_expect_success 'core.attributesfile' ' + attr_check global unspecified && + git config core.attributesfile "$HOME/global-gitattributes" && + attr_check global global && + git config core.attributesfile "~/global-gitattributes" && + attr_check global global && + echo "global test=precedence" >> .gitattributes && + attr_check global precedence +' + test_expect_success 'attribute test: read paths from stdin' ' cat <<EOF > expect
Signature · 1 line
1.7.2.2.175.ga619d.dirty
Thanks, Matthieu!
Petr's original patch doesn't apply cleanly due to a bogus context line after a recent change in Makefile. For convenience, below is the updated patch including Matthieu's changes applicable to current master.
And FWIW (I didn't try to build the documentation, though):
--- 8< ---
From b63a6449dbf2c6d4a111ad840ae7d408afdd5e43 Mon Sep 17 00:00:00 2001
From: Petr Onderka <[email protected]>
Date: Mon, 16 Aug 2010 16:56:53 +0000
Subject: [PATCH] Add global and system-wide gitattributes
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
The location of system-wide attributes file is $(prefix)/etc/gitattributes. The location of the global file can be configured by setting core.attributesfile.
Some parts of the code were copied from the implementation of the same functionality in config.c.
--- Documentation/config.txt | 6 +++++ Documentation/gitattributes.txt | 13 +++++++++-- Makefile | 6 +++++ attr.c | 42 ++++++++++++++++++++++++++++++++++++++- cache.h | 1 + config.c | 3 ++ configure.ac | 10 ++++++++- environment.c | 1 + t/t0003-attributes.sh | 14 +++++++++++++ 9 files changed, 91 insertions(+), 5 deletions(-)
Documentation/config.txt +6 -0
@@ -450,6 +450,12 @@ core.excludesfile:: to the value of `$HOME` and "{tilde}user/" to the specified user's home directory. See linkgit:gitignore[5]. +core.attributesfile:: + In addition to '.gitattributes' (per-directory) and + '.git/info/attributes', git looks into this file for attributes + (see linkgit:gitattributes[5]). Path expansions are made the same + way as for `core.excludesfile`. + core.editor:: Commands such as `commit` and `tag` that lets you edit messages by launching an editor uses the value of this
Documentation/gitattributes.txt +10 -3
@@ -62,14 +62,21 @@ consults `$GIT_DIR/info/attributes` file (which has the highest precedence), `.gitattributes` file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains `.gitattributes` -is from the path in question, the lower its precedence). +is from the path in question, the lower its precedence). Finally +global and system-wide files are considered (they have the lowest +precedence). If you wish to affect only a single repository (i.e., to assign -attributes to files that are particular to one user's workflow), then +attributes to files that are particular to +one user's workflow for that repository), then attributes should be placed in the `$GIT_DIR/info/attributes` file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into -`.gitattributes` files. +`.gitattributes` files. Attributes that should affect all repositories +for a single user should be placed in a file specified by the +`core.attributesfile` configuration option (see linkgit:git-config[1]). +Attributes for all users on a system should be placed in the +`$(prefix)/etc/gitattributes` file. Sometimes you would need to override an setting of an attribute for a path to `unspecified` state. This can be done by listing
Makefile +6 -0
@@ -268,6 +268,7 @@ STRIP ?= strip # infodir # htmldir # ETC_GITCONFIG (but not sysconfdir) +# ETC_GITATTRIBUTES # can be specified as a relative path some/where/else; # this is interpreted as relative to $(prefix) and "git" at # runtime figures out where they are based on the path to the executable.
@@ -286,9 +287,11 @@ htmldir = share/doc/git-doc ifeq ($(prefix),/usr) sysconfdir = /etc ETC_GITCONFIG = $(sysconfdir)/gitconfig +ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes else sysconfdir = $(prefix)/etc ETC_GITCONFIG = etc/gitconfig +ETC_GITATTRIBUTES = etc/gitattributes endif lib = lib # DESTDIR=
@@ -1502,6 +1505,7 @@ endif SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) +ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir))
@@ -1873,6 +1877,8 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' +attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"' + http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"' ifdef NO_EXPAT
attr.c +41 -1
65 lines not on this page · raw message
cache.h +1 -0
@@ -1033,6 +1033,7 @@ extern int pager_use_color;extern const char *editor_program;extern const char *excludes_file; +extern const char *attributes_file;/* base85 */ int decode_85 (char *dst,const char *line,int linelen);
config.c +3 -0
@@ -563,6 +563,9 @@ static int git_default_core_config(const char *var, const char *value)if (!strcmp (var,"core.excludesfile" ))return git_config_pathname (&excludes_file, var, value); +if (!strcmp (var,"core.attributesfile" )) +return git_config_pathname (&attributes_file, var, value); +if (!strcmp (var,"core.whitespace" )) {if (!value)return config_error_nonbool (var);
configure.ac +9 -1
@@ -282,7 +282,15 @@ GIT_PARSE_WITH(iconv)) GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, Use VALUE instead of /etc/gitconfig as the global git configuration file. - If VALUE is not fully qualified it will be interpretted + If VALUE is not fully qualified it will be interpreted + as a path relative to the computed prefix at runtime.) + +# +# Allow user to set ETC_GITATTRIBUTES variable +GIT_PARSE_WITH_SET_MAKE_VAR(gitattributes, ETC_GITATTRIBUTES, + Use VALUE instead of /etc/gitattributes as the + global git attributes file. + If VALUE is not fully qualified it will be interpreted as a path relative to the computed prefix at runtime.) #
environment.c +1 -0
@@ -38,6 +38,7 @@ const char *pager_program;int pager_use_color =1 ;const char *editor_program;const char *excludes_file; +const char *attributes_file;enum auto_crlf auto_crlf =AUTO_CRLF_FALSE ;int read_replace_refs =1 ;enum eol eol =EOL_UNSET ;
t/t0003-attributes.sh +14 -0
@@ -15,6 +15,7 @@ attr_check () { } +HOME=$(pwd) test_expect_success 'setup' '
@@ -36,6 +37,9 @@ test_expect_success 'setup' ' echo "d/* test=a/b/d/*" echo "d/yes notest" ) >a/b/.gitattributes + ( + echo "global test=global" + ) >$HOME/global-gitattributes '
@@ -57,6 +61,16 @@ test_expect_success 'attribute test' ' ' +test_expect_success 'core.attributesfile' ' + attr_check global unspecified && + git config core.attributesfile "$HOME/global-gitattributes" && + attr_check global global && + git config core.attributesfile "~/global-gitattributes" && + attr_check global global && + echo "global test=precedence" >> .gitattributes && + attr_check global precedence +' + test_expect_success 'attribute test: read paths from stdin' ' cat <<EOF > expect
Signature · 1 line
1.7.1
Quoted 9 lines · Štěpán Němec
Thanks, Matthieu!
Petr's original patch doesn't apply cleanly due to a bogus context line after a recent change in
Makefile. For convenience, below is the updated patch including Matthieu's changes applicable to current master.And FWIW (I didn't try to build the documentation, though):
Tested-by Štěpán Němec <[email protected]>
Thanks, but this seems to break t8005 for whatever reason.
t/t0003-attributes.sh attr_check () { · line 18
Quoted 9 lines
t/t0003-attributes.sh +1
-0@@ -15,6 +15,7 @@ attr_check () { } +HOME=$(pwd)
I see a few tests here and there that uses the test-trash directory as HOME; perhaps we should have done that in test-lib.sh to make our life easier?
PATCH 1/1 tests: factor HOME=$(pwd) in test-lib.sh
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
---
Quoted 7 lines · Junio C Hamano
t/t0003-attributes.sh
Quoted 3 lines
t/t0003-attributes.sh +1
-0+HOME=$(pwd)I see a few tests here and there that uses the test-trash directory as HOME; perhaps we should have done that in
test-lib.shto make our life easier?
I just mimicked what the other tests were doing, but doing it in test-lib.sh makes sense, yes. That also prevents accidental modification of the actual $HOME when writing buggy tests.
The test-suite still passes if I apply this, so it's probably as easy as it seems to be :-). The patch comes on top of mine for .gitattributes, to remove my HOME=$(pwd).
t/lib-cvs.sh | 3 --- t/t0001-init.sh | 6 ------ t/t0003-attributes.sh | 2 -- t/t5601-clone.sh | 2 -- t/t9130-git-svn-authors-file.sh | 2 -- t/test-lib.sh | 3 +++ 6 files changed, 3 insertions(+), 15 deletions(-)
t/lib-cvs.sh +0 -3
@@ -3,9 +3,6 @@ . ./test-lib.sh unset CVS_SERVER -# for clean cvsps cache -HOME=$(pwd) -export HOME if ! type cvs >/dev/null 2>&1 then
t/t0001-init.sh +0 -6
@@ -171,8 +171,6 @@ test_expect_success 'init with init.templatedir set' ' mkdir templatedir-source && echo Content >templatedir-source/file && ( - HOME="`pwd`" && - export HOME && test_config="${HOME}/.gitconfig" && git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && mkdir templatedir-set &&
@@ -188,8 +186,6 @@ test_expect_success 'init with init.templatedir set' ' test_expect_success 'init --bare/--shared overrides system/global config' ' ( - HOME="`pwd`" && - export HOME && test_config="$HOME"/.gitconfig && unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" core.bare false &&
@@ -205,8 +201,6 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' test_expect_success 'init honors global core.sharedRepository' ' ( - HOME="`pwd`" && - export HOME && test_config="$HOME"/.gitconfig && unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" core.sharedRepository 0666 &&
t/t0003-attributes.sh +0 -2
@@ -15,8 +15,6 @@ attr_check () { } -HOME=$(pwd) - test_expect_success 'setup' ' mkdir -p a/b/d a/c &&
t/t5601-clone.sh +0 -2
@@ -163,8 +163,6 @@ test_expect_success 'clone a void' ' test_expect_success 'clone respects global branch.autosetuprebase' ' ( - HOME=$(pwd) && - export HOME && test_config="$HOME/.gitconfig" && unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" branch.autosetuprebase remote &&
t/t9130-git-svn-authors-file.sh +0 -2
@@ -95,8 +95,6 @@ test_expect_success 'fresh clone with svn.authors-file in config' ' ( rm -r "$GIT_DIR" && test x = x"$(git config svn.authorsfile)" && - HOME="`pwd`" && - export HOME && test_config="$HOME"/.gitconfig && unset GIT_CONFIG_NOGLOBAL && unset GIT_DIR &&
t/test-lib.sh +3 -0
@@ -861,6 +861,9 @@ test_create_repo "$test" # in subprocesses like git equals our $PWD (for pathname comparisons). cd -P "$test" || exit 1 +HOME=$(pwd) +export HOME + this_test=${0##*/} this_test=${this_test%%-*} for skp in $GIT_SKIP_TESTS
Signature · 1 line
1.7.2.2.175.ga619d.dirty
Re: [PATCH] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 2 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Looks good, but why not:
t/test-lib.sh test_create_repo "$test" · line 865
Quoted 2 lines
t/test-lib.sh +2
-0+HOME=$(pwd) +export HOME
This instead:
HOME=$TRASH_DIRECTORY
export HOME
Looks like it might be more correct given this (always an absolute path), but I haven't tested:
case "$test" in
/*) TRASH_DIRECTORY="$test" ;;
*) TRASH_DIRECTORY="$TEST_DIRECTORY/$test" ;;
esac
Re: [PATCH] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 11 lines · Ævar Arnfjörð Bjarmason
Quoted 2 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Looks good, but why not:
t/test-lib.sh test_create_repo "$test" · line 865
Quoted 2 lines
t/test-lib.sh +2
-0+HOME=$(pwd) +export HOMEThis instead:
Quoted 5 lines
HOME=$TRASH_DIRECTORY
export HOMELooks like it might be more correct given this (always an absolute path), but I haven't tested:
That should work too, but with your version, I have to think harder to make sure $TRASH_DIRECTORY is absolute (that should be OK), and won't make any issue with symlinks (I have no idea whether it is OK or not), while it's trivially correct with mine (pwd is absolute, and the -P option of the cd command right above prevents issue with symlinks).
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Re: [PATCH] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 16 lines · Matthieu Moy
Quoted 14 lines · Ęvar Arnfjörš Bjarmason
Quoted 2 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Looks good, but why not:
t/test-lib.sh test_create_repo "$test" · line 865
Quoted 2 lines
t/test-lib.sh +2
-0+HOME=$(pwd) +export HOMEThis instead:
HOME=$TRASH_DIRECTORY
export HOME
Quoted 8 lines
Quoted 2 lines
Looks like it might be more correct given this (always an absolute path), but I haven't tested:
That should work too, but with your version, I have to think harder to make sure $TRASH_DIRECTORY is absolute (that should be OK), and won't make any issue with symlinks (I have no idea whether it is OK or not), while it's trivially correct with mine (pwd is absolute, and the -P option of the cd command right above prevents issue with symlinks).
I don't know what's best here (and I didn't look hard at this).
but I recently brought down the number of $(pwd) invocations in test-lib.sh down to exactly 1, so everything that comes later is now defined in terms of that pwd invocation.
Defining everything that comes afterwards in terms of that pwd might be clearer.
But it's a trivial issue.
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Štěpán Němec
Thanks, Matthieu!
Petr's original patch doesn't apply cleanly due to a bogus context line after a recent change in
Makefile. For convenience, below is the updated patch including Matthieu's changes applicable to current master.
Quoted 5 lines
Quoted 3 lines
And FWIW (I didn't try to build the documentation, though):
Tested-by Štěpán Němec <[email protected]>Thanks, but this seems to break t8005 for whatever reason.
The guilty line is
git_config(git_default_config, NULL);
(t8005 passes if I remove it).
I don't understand why this breaks the test. It seems blame --encoding=UTF-8 relies on the fact that the i18n section of the configuration is not loaded.
An obvious fix on our side is to squash the patch below into the previous ones, to make sure the attributes code loads only the core configuration. OTOH, it seems to me that the blame code is very fragile, but I'm not familiar with this code to say whether and how it should be fixed.
Any other thoughts?
attr.c +1 -1
@@ -500,7 +500,7 @@ static void bootstrap_attr_stack(void) } } -git_config (git_default_config,NULL ); +git_config (git_core_config,NULL );if (git_attr_global () && attributes_file) { elem =read_attr_from_file (attributes_file,1 );if (elem) {
cache.h +1 -0
@@ -972,6 +972,7 @@ extern int update_server_info(int);typedef int (*config_fn_t )(const char *,const char *,void *);extern int git_default_config (const char *,const char *,void *); +extern int git_core_config (const char *,const char *,void *);extern int git_config_from_file (config_fn_t fn,const char *,void *);extern int git_config_parse_parameter (const char *text);extern int git_config_from_parameters (config_fn_t fn,void *data);
config.c +8 -0
@@ -602,6 +602,14 @@ static int git_default_core_config(const char *var, const char *value)return 0 ; } +/* +* Wrapper around git_default_core_config, with type acceptable as +* argument to git_config(...) +*/ +int git_core_config (const char *var,const char *value,void *dummy) { +return git_default_core_config (var, value); +} +static int git_default_user_config (const char *var,const char *value) {if (!strcmp (var,"user.name" )) {
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Quoted 3 lines · Matthieu Moy
I don't understand why this breaks the test. It seems blame --encoding=UTF-8 relies on the fact that the i18n section of the configuration is not loaded.
That's interesting; I haven't traced the codepath involved, but I do not think "configuration is not loaded" is the issue. "Reading either before the main codepath is ready, or more likely overwriting/destroying what the main codepath has read it by re-reading the configuration" may be.
Perhaps the part that reads encoding configuration is busted and is not expected to be called way early or way late. In short, this patch introduces uncertainty that config reader is called at a random and unexpected (from the existing code's point of view) place in the codepath, and I wouldn't be very surprised if there are similar breakages introduced by it.
What does the callchain look like when we bootstrap the attr stack for the first time with this patch applied? Have we already located where the git repository is? Has the main codepath that wants to read encoding settings read them? Has the main codepath already used the command line option that overrides the settings it obtained from the configuration file? Is the extra reading of the config destroying that data?
I am afraid that your patch to narrow the parts of the config that is read from this codepath is only sweeping the problem under the rug, making the issue harder to diagnose. Wouldn't we see exactly the same issue if some codepath (other than blame) wants to see a core.* configuration not to be read in this codepath for whatever reason?
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Matthieu Moy
I don't understand why this breaks the test. It seems blame --encoding=UTF-8 relies on the fact that the i18n section of the configuration is not loaded.
That's interesting; I haven't traced the codepath involved, but I do not think "configuration is not loaded" is the issue. "Reading either before the main codepath is ready, or more likely overwriting/destroying what the main codepath has read it by re-reading the configuration" may be.
I think that hunch is correct. A typical way we default to hardcoded value, overridable by configuration file, and then further use command line to override that, is for the main codepath to do the following in this order:
- call git_config(git_appropriate_config); this changes the variables (with possibly hardcoded default) defined in environment.c;
- parse command line options and override the variable;
- use the variable at runtime.
This obviously relies on the main codepath having _total_ control of the calls made to git_config(). If you call git_config(git_default_config) when an attribute is asked for for the first time (which would be way after all of the above happened) behind the main codepath's back, you will of course break things. In the "blame" case, aren't you stomping on git_log_output_encoding?
The correct solution would be twofold, but the latter is rather painful:
- The call from the bootstrap_attr_stack should use a callback that reads only the attribute file location configuration and _nothing else_.
Also I do not think the parsing of this configuration variable needs to be in git_default_config() to begin with, if you are reading it from the bootstrap codepath on demand anyway, and not relying on the main codepath of any particular program to be calling on git_config().
- The way programs (this is not limited to blame and other rev-list machinery users) implement the "use configured values but let command line override them" need to be changed.
One possibility is to copy the values determined by reading the config and the command line to their own variables, so that later random call to git_config() won't stomp on the actual values to be used. This is painful as environment.c variables are _meant_ to be easily usable as global variables and copying them away (which means they now need to be passed around throughout the callchain in the various APIs) defeats the whole point of having them.
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Matthieu Moy
I don't understand why this breaks the test. It seems blame --encoding=UTF-8 relies on the fact that the i18n section of the configuration is not loaded.
Quoted 6 lines
Quoted 4 lines
That's interesting; I haven't traced the codepath involved, but I do not think "configuration is not loaded" is the issue. "Reading either before the main codepath is ready, or more likely overwriting/destroying what the main codepath has read it by re-reading the configuration" may be.
I think that hunch is correct.
Confirmed.
Quoted 10 lines
A typical way we default to hardcoded value, overridable by configuration file, and then further use command line to override that, is for the main codepath to do the following in this order:
- call
git_config(git_appropriate_config); this changes the variables (with possibly hardcoded default) defined inenvironment.c;- parse command line options and override the variable;
- use the variable at runtime.
Yes, this is the problem, with git_log_output_encoding as you guessed.
Quoted 1 line
The correct solution would be twofold, but the latter is rather painful:
Not that much in the case of git_log_output_encoding, but other uses of the same pattern may exist.
Quoted 2 lines
- The call from the
bootstrap_attr_stackshould use a callback that reads only the attribute file location configuration and_nothingelse_.
[...]
Quoted 3 lines
- The way programs (this is not limited to blame and other rev-list machinery users) implement the "use configured values but let command line override them" need to be changed.
I think it's reasonable to do both. Having both git_config() and command-line parsing write to the same variable is fragile and should be avoided IMHO, but OTOH, arbitrary calls to git_config(git_default_config) may break other things, so ...
Quoted 7 lines
One possibility is to copy the values determined by reading the config and the command line to their own variables, so that later random call to
git_config()won't stomp on the actual values to be used. This is painful asenvironment.cvariables are _meant_ to be easily usable as global variables and copying them away (which means they now need to be passed around throughout the callchain in the various APIs) defeats the whole point of having them.
I just keep two global variables instead of two, and implement a straightforward accessor. Command-line option parsing already used to write to a global variable, so it doesn't change much.
New patch serie follows,
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
PATCH v2 1/3 tests: factor HOME=$(pwd) in test-lib.sh
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
---
Just re-ordered the patch to make this one the first.
I took Ævar's suggestion of using $TRASH_DIRECTORY instead of $(pwd).
t/lib-cvs.sh | 3 --- t/t0001-init.sh | 6 ------ t/t0003-attributes.sh | 1 - t/t5601-clone.sh | 2 -- t/t9130-git-svn-authors-file.sh | 2 -- t/test-lib.sh | 3 +++ 6 files changed, 3 insertions(+), 14 deletions(-)
t/lib-cvs.sh +0 -3
@@ -3,9 +3,6 @@ . ./test-lib.sh unset CVS_SERVER -# for clean cvsps cache -HOME=$(pwd) -export HOME if ! type cvs >/dev/null 2>&1 then
t/t0001-init.sh +0 -6
@@ -171,8 +171,6 @@ test_expect_success 'init with init.templatedir set' ' mkdir templatedir-source && echo Content >templatedir-source/file && ( - HOME="`pwd`" && - export HOME && test_config="${HOME}/.gitconfig" && git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && mkdir templatedir-set &&
@@ -188,8 +186,6 @@ test_expect_success 'init with init.templatedir set' ' test_expect_success 'init --bare/--shared overrides system/global config' ' ( - HOME="`pwd`" && - export HOME && test_config="$HOME"/.gitconfig && unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" core.bare false &&
@@ -205,8 +201,6 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' test_expect_success 'init honors global core.sharedRepository' ' ( - HOME="`pwd`" && - export HOME && test_config="$HOME"/.gitconfig && unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" core.sharedRepository 0666 &&
t/t0003-attributes.sh +0 -1
@@ -15,7 +15,6 @@ attr_check () { } - test_expect_success 'setup' ' mkdir -p a/b/d a/c &&
t/t5601-clone.sh +0 -2
@@ -163,8 +163,6 @@ test_expect_success 'clone a void' ' test_expect_success 'clone respects global branch.autosetuprebase' ' ( - HOME=$(pwd) && - export HOME && test_config="$HOME/.gitconfig" && unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" branch.autosetuprebase remote &&
t/t9130-git-svn-authors-file.sh +0 -2
@@ -95,8 +95,6 @@ test_expect_success 'fresh clone with svn.authors-file in config' ' ( rm -r "$GIT_DIR" && test x = x"$(git config svn.authorsfile)" && - HOME="`pwd`" && - export HOME && test_config="$HOME"/.gitconfig && unset GIT_CONFIG_NOGLOBAL && unset GIT_DIR &&
t/test-lib.sh +3 -0
@@ -861,6 +861,9 @@ test_create_repo "$test" # in subprocesses like git equals our $PWD (for pathname comparisons). cd -P "$test" || exit 1 +HOME="$TRASH_DIRECTORY" +export HOME + this_test=${0##*/} this_test=${this_test%%-*} for skp in $GIT_SKIP_TESTS
Signature · 1 line
1.7.2.2.175.ga619d.dirty
Re: [PATCH 1/3 v2] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 8 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Signed-off-by Matthieu Moy <[email protected]>---
Just re-ordered the patch to make this one the first.I took Ævar's suggestion of using $TRASH_DIRECTORY instead of $(pwd).
Thanks,
PATCH 2/3 don't write to git_log_output_encoding outside git_config()
In reply to Matthieu MoyThe log encoding can be given by the user either with --encoding=foo or with i18n.logoutputencoding. The code dealing with this used to write to git_log_output_encoding in both places, making sure that --encoding=foo is dealt with after reading the configuration file.
This is a very fragile mechanism, since any further call to git_config(git_default_config, ...) the value given on the command line.
Instead, keep the config value and the cli value, and decide which one to take at read time (in the straightforward accessor get_git_log_output_encoding()).
---
So, this isn't strictly necessary since the new version of the patch implementing the gitattributes file doesn't read the full config anymore, but I think that makes the code more robust.
builtin/log.c | 4 ++-- cache.h | 18 ++++++++++++++++++ environment.c | 4 +++- pretty.c | 4 ++-- revision.c | 4 ++-- 5 files changed, 27 insertions(+), 7 deletions(-)
builtin/log.c +2 -2
@@ -329,8 +329,8 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)struct strbuf out =STRBUF_INIT ;pp_user_info ("Tagger" , rev->commit_format, &out, buf, rev->date_mode, - git_log_output_encoding ? - git_log_output_encoding: git_commit_encoding); +get_git_log_output_encoding () ? +get_git_log_output_encoding (): git_commit_encoding);printf ("%s" , out.buf);strbuf_release (&out); }
cache.h +18 -0
@@ -1005,7 +1005,25 @@ extern int user_ident_explicitly_given;extern int user_ident_sufficiently_given (void );extern const char *git_commit_encoding; + +/* Value found in config file */ extern const char *git_log_output_encoding; + +/* Value given in command line with --encoding */ +extern const char *git_log_output_encoding_cli; + +/* +* Prioritize the value given by the command-line over the value found +* in the config file. +*/ +static inline +const char *get_git_log_output_encoding () +{ +return git_log_output_encoding_cli ? + git_log_output_encoding_cli : + git_log_output_encoding; +} +extern const char *git_mailmap_file;/* IO helper functions */
environment.c +3 -1
@@ -23,7 +23,9 @@ int log_all_ref_updates = -1; /* unspecified */int warn_ambiguous_refs =1 ;int repository_format_version;const char *git_commit_encoding; -const char *git_log_output_encoding; +const char *git_log_output_encoding =NULL ; +const char *git_log_output_encoding_cli =NULL ; +int shared_repository =PERM_UMASK ;const char *apply_default_whitespace;const char *apply_default_ignorewhitespace;
pretty.c +2 -2
@@ -1159,8 +1159,8 @@ char *reencode_commit_message(const struct commit *commit, const char **encoding {const char *encoding; - encoding = (git_log_output_encoding - ? git_log_output_encoding + encoding = (get_git_log_output_encoding () + ?get_git_log_output_encoding () : git_commit_encoding);if (!encoding) encoding ="UTF-8" ;
revision.c +2 -2
@@ -1402,9 +1402,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->grep_filter.all_match =1 ; }else if ((argcount =parse_long_opt ("encoding" , argv, &optarg))) {if (strcmp (optarg,"none" )) - git_log_output_encoding =xstrdup (optarg); + git_log_output_encoding_cli =xstrdup (optarg);else - git_log_output_encoding ="" ; + git_log_output_encoding_cli ="" ;return argcount; }else if (!strcmp (arg,"--reverse" )) { revs->reverse ^=1 ;
Signature · 1 line
1.7.2.2.175.ga619d.dirty
PATCH v4 3/3 Add global and system-wide gitattributes
In reply to Matthieu MoyFrom: Petr Onderka <[email protected]>
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
The location of system-wide attributes file is $(prefix)/etc/gitattributes. The location of the global file can be configured by setting core.attributesfile.
Some parts of the code were copied from the implementation of the same functionality in config.c.
---
This version doesn't touch config.c, and calls git_config with a trivial callback reading only the core.attributesfile variable.
This time, I did run the whole testsuite ;-).
Documentation/config.txt | 6 ++++ Documentation/gitattributes.txt | 13 +++++++-- Makefile | 6 ++++ attr.c | 50 ++++++++++++++++++++++++++++++++++++++- cache.h | 1 + configure.ac | 10 +++++++- environment.c | 1 + t/t0003-attributes.sh | 13 ++++++++++ 8 files changed, 95 insertions(+), 5 deletions(-)
Documentation/config.txt +6 -0
@@ -450,6 +450,12 @@ core.excludesfile:: to the value of `$HOME` and "{tilde}user/" to the specified user's home directory. See linkgit:gitignore[5]. +core.attributesfile:: + In addition to '.gitattributes' (per-directory) and + '.git/info/attributes', git looks into this file for attributes + (see linkgit:gitattributes[5]). Path expansions are made the same + way as for `core.excludesfile`. + core.editor:: Commands such as `commit` and `tag` that lets you edit messages by launching an editor uses the value of this
Documentation/gitattributes.txt +10 -3
@@ -62,14 +62,21 @@ consults `$GIT_DIR/info/attributes` file (which has the highest precedence), `.gitattributes` file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains `.gitattributes` -is from the path in question, the lower its precedence). +is from the path in question, the lower its precedence). Finally +global and system-wide files are considered (they have the lowest +precedence). If you wish to affect only a single repository (i.e., to assign -attributes to files that are particular to one user's workflow), then +attributes to files that are particular to +one user's workflow for that repository), then attributes should be placed in the `$GIT_DIR/info/attributes` file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into -`.gitattributes` files. +`.gitattributes` files. Attributes that should affect all repositories +for a single user should be placed in a file specified by the +`core.attributesfile` configuration option (see linkgit:git-config[1]). +Attributes for all users on a system should be placed in the +`$(prefix)/etc/gitattributes` file. Sometimes you would need to override an setting of an attribute for a path to `unspecified` state. This can be done by listing
Makefile +6 -0
@@ -268,6 +268,7 @@ STRIP ?= strip # infodir # htmldir # ETC_GITCONFIG (but not sysconfdir) +# ETC_GITATTRIBUTES # can be specified as a relative path some/where/else; # this is interpreted as relative to $(prefix) and "git" at # runtime figures out where they are based on the path to the executable.
@@ -286,9 +287,11 @@ htmldir = share/doc/git-doc ifeq ($(prefix),/usr) sysconfdir = /etc ETC_GITCONFIG = $(sysconfdir)/gitconfig +ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes else sysconfdir = $(prefix)/etc ETC_GITCONFIG = etc/gitconfig +ETC_GITATTRIBUTES = etc/gitattributes endif lib = lib # DESTDIR=
@@ -1502,6 +1505,7 @@ endif SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) +ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir))
@@ -1873,6 +1877,8 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' +attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"' + http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"' ifdef NO_EXPAT
attr.c +49 -1
73 lines not on this page · raw message
cache.h +1 -0
@@ -1051,6 +1051,7 @@ extern int pager_use_color;extern const char *editor_program;extern const char *excludes_file; +extern const char *attributes_file;/* base85 */ int decode_85 (char *dst,const char *line,int linelen);
configure.ac +9 -1
@@ -282,7 +282,15 @@ GIT_PARSE_WITH(iconv)) GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, Use VALUE instead of /etc/gitconfig as the global git configuration file. - If VALUE is not fully qualified it will be interpretted + If VALUE is not fully qualified it will be interpreted + as a path relative to the computed prefix at runtime.) + +# +# Allow user to set ETC_GITATTRIBUTES variable +GIT_PARSE_WITH_SET_MAKE_VAR(gitattributes, ETC_GITATTRIBUTES, + Use VALUE instead of /etc/gitattributes as the + global git attributes file. + If VALUE is not fully qualified it will be interpreted as a path relative to the computed prefix at runtime.) #
environment.c +1 -0
@@ -40,6 +40,7 @@ const char *pager_program;int pager_use_color =1 ;const char *editor_program;const char *excludes_file; +const char *attributes_file;enum auto_crlf auto_crlf =AUTO_CRLF_FALSE ;int read_replace_refs =1 ;enum eol eol =EOL_UNSET ;
t/t0003-attributes.sh +13 -0
@@ -35,6 +35,9 @@ test_expect_success 'setup' ' echo "d/* test=a/b/d/*" echo "d/yes notest" ) >a/b/.gitattributes + ( + echo "global test=global" + ) >$HOME/global-gitattributes '
@@ -56,6 +59,16 @@ test_expect_success 'attribute test' ' ' +test_expect_success 'core.attributesfile' ' + attr_check global unspecified && + git config core.attributesfile "$HOME/global-gitattributes" && + attr_check global global && + git config core.attributesfile "~/global-gitattributes" && + attr_check global global && + echo "global test=precedence" >> .gitattributes && + attr_check global precedence +' + test_expect_success 'attribute test: read paths from stdin' ' cat <<EOF > expect
Signature · 1 line
1.7.2.2.175.ga619d.dirty
Quoted 2 lines · Matthieu Moy
This version doesn't touch
config.c, and callsgit_configwith a trivial callback reading only the core.attributesfile variable.
I see that pu has a variant of my fix:
17cd572 fixup! Add global and system-wide gitattributes
(is the fixup! here on purpose, or is it a failed rebase -i?)
Junio: your fixup fixes the git_config issue, but doesn't have the test that my patch have. The difference is that your fixup moves the global variable attributes_file in attr.c, which sounds like a good idea. I'm resending my patch with this change for conveinience.
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
PATCH 1/1 Add global and system-wide gitattributes
From: Petr Onderka <[email protected]>
Allow gitattributes to be set globally and system wide. This way, settings for particular file types can be set in one place and apply for all user's repositories.
The location of system-wide attributes file is $(prefix)/etc/gitattributes. The location of the global file can be configured by setting core.attributesfile.
Some parts of the code were copied from the implementation of the same functionality in config.c.
---
Here it is!
Documentation/config.txt | 6 ++++ Documentation/gitattributes.txt | 13 +++++++-- Makefile | 6 ++++ attr.c | 52 ++++++++++++++++++++++++++++++++++++++- configure.ac | 10 ++++++- t/t0003-attributes.sh | 13 +++++++++ 6 files changed, 95 insertions(+), 5 deletions(-)
Documentation/config.txt +6 -0
@@ -450,6 +450,12 @@ core.excludesfile:: to the value of `$HOME` and "{tilde}user/" to the specified user's home directory. See linkgit:gitignore[5]. +core.attributesfile:: + In addition to '.gitattributes' (per-directory) and + '.git/info/attributes', git looks into this file for attributes + (see linkgit:gitattributes[5]). Path expansions are made the same + way as for `core.excludesfile`. + core.editor:: Commands such as `commit` and `tag` that lets you edit messages by launching an editor uses the value of this
Documentation/gitattributes.txt +10 -3
@@ -62,14 +62,21 @@ consults `$GIT_DIR/info/attributes` file (which has the highest precedence), `.gitattributes` file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains `.gitattributes` -is from the path in question, the lower its precedence). +is from the path in question, the lower its precedence). Finally +global and system-wide files are considered (they have the lowest +precedence). If you wish to affect only a single repository (i.e., to assign -attributes to files that are particular to one user's workflow), then +attributes to files that are particular to +one user's workflow for that repository), then attributes should be placed in the `$GIT_DIR/info/attributes` file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into -`.gitattributes` files. +`.gitattributes` files. Attributes that should affect all repositories +for a single user should be placed in a file specified by the +`core.attributesfile` configuration option (see linkgit:git-config[1]). +Attributes for all users on a system should be placed in the +`$(prefix)/etc/gitattributes` file. Sometimes you would need to override an setting of an attribute for a path to `unspecified` state. This can be done by listing
Makefile +6 -0
@@ -268,6 +268,7 @@ STRIP ?= strip # infodir # htmldir # ETC_GITCONFIG (but not sysconfdir) +# ETC_GITATTRIBUTES # can be specified as a relative path some/where/else; # this is interpreted as relative to $(prefix) and "git" at # runtime figures out where they are based on the path to the executable.
@@ -286,9 +287,11 @@ htmldir = share/doc/git-doc ifeq ($(prefix),/usr) sysconfdir = /etc ETC_GITCONFIG = $(sysconfdir)/gitconfig +ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes else sysconfdir = $(prefix)/etc ETC_GITCONFIG = etc/gitconfig +ETC_GITATTRIBUTES = etc/gitattributes endif lib = lib # DESTDIR=
@@ -1502,6 +1505,7 @@ endif SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) +ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir))
@@ -1873,6 +1877,8 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' +attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"' + http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"' ifdef NO_EXPAT
attr.c +51 -1
81 lines not on this page · raw message
configure.ac +9 -1
@@ -282,7 +282,15 @@ GIT_PARSE_WITH(iconv)) GIT_PARSE_WITH_SET_MAKE_VAR(gitconfig, ETC_GITCONFIG, Use VALUE instead of /etc/gitconfig as the global git configuration file. - If VALUE is not fully qualified it will be interpretted + If VALUE is not fully qualified it will be interpreted + as a path relative to the computed prefix at runtime.) + +# +# Allow user to set ETC_GITATTRIBUTES variable +GIT_PARSE_WITH_SET_MAKE_VAR(gitattributes, ETC_GITATTRIBUTES, + Use VALUE instead of /etc/gitattributes as the + global git attributes file. + If VALUE is not fully qualified it will be interpreted as a path relative to the computed prefix at runtime.) #
t/t0003-attributes.sh +13 -0
@@ -35,6 +35,9 @@ test_expect_success 'setup' ' echo "d/* test=a/b/d/*" echo "d/yes notest" ) >a/b/.gitattributes + ( + echo "global test=global" + ) >$HOME/global-gitattributes '
@@ -56,6 +59,16 @@ test_expect_success 'attribute test' ' ' +test_expect_success 'core.attributesfile' ' + attr_check global unspecified && + git config core.attributesfile "$HOME/global-gitattributes" && + attr_check global global && + git config core.attributesfile "~/global-gitattributes" && + attr_check global global && + echo "global test=precedence" >> .gitattributes && + attr_check global precedence +' + test_expect_success 'attribute test: read paths from stdin' ' cat <<EOF > expect
Signature · 1 line
1.7.2.2.175.ga619d.dirty
Quoted 10 lines · Matthieu Moy
Quoted 2 lines · Matthieu Moy
This version doesn't touch
config.c, and callsgit_configwith a trivial callback reading only the core.attributesfile variable.I see that pu has a variant of my fix:
17cd572 fixup! Add global and system-wide gitattributes
(is the fixup! here on purpose, or is it a failed rebase -i?)
It wasn't a failed "rebase -i" but was a reminder to myself. I didn't want to squash that in before discussing on the list.
Quoted 1 line
... I'm resending my patch with this change for conveinience.
Will take a look; it will have to wait until my git Wednesday this week to be pushed out, though.
Thanks.
Re: [PATCH 1/3 v2] tests: factor HOME=$(pwd) in test-lib.sh
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 7 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Signed-off-by Matthieu Moy <[email protected]>---
Just re-ordered the patch to make this one the first.
Quoted 5 lines
Quoted 1 line
I took Ævar's suggestion of using $TRASH_DIRECTORY instead of $(pwd).
Thanks,
Junio: FYI you picked up v1 of this for next/pu, not this v2.
Re: [PATCH 1/3 v2] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 7 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Signed-off-by Matthieu Moy <[email protected]>---
Just re-ordered the patch to make this one the first.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I took Ævar's suggestion of using $TRASH_DIRECTORY instead of $(pwd).
Thanks,
Junio: FYI you picked up v1 of this for next/pu, not this v2.
I know.
The originals all used $(pwd) as far as I saw, and it _is_ more faithful and correct refactoring not to use $TRASH_DIRECTORY in this patch, no? You can choose to change it to use $TRASH but that should be done in a separate patch.
Re: [PATCH 1/3 v2] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 17 lines · Junio C Hamano
Quoted 15 lines · Ævar Arnfjörð Bjarmason
Quoted 13 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Matthieu Moy
The same pattern is used in many tests, and makes it easy for new ones to rely on $HOME being a trashable, clean, directory.
Signed-off-by Matthieu Moy <[email protected]>---
Just re-ordered the patch to make this one the first.I took Ævar's suggestion of using $TRASH_DIRECTORY instead of $(pwd).
Thanks,
Quoted 8 lines
Quoted 1 line
Junio: FYI you picked up v1 of this for next/pu, not this v2.
I know.
The originals all used $(pwd) as far as I saw, and it _is_ more faithful and correct refactoring not to use $TRASH_DIRECTORY in this patch, no? You can choose to change it to use $TRASH but that should be done in a separate patch.
I just wanted to note it in case you didn't see it. It's a trivial issue and I don't really care, I just wanted to note it in case the v2 went past you.
Re: [PATCH 1/3 v2] tests: factor HOME=$(pwd) in test-lib.sh
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines
The originals all used $(pwd) as far as I saw, and it _is_ more faithful and correct refactoring not to use $TRASH_DIRECTORY in this patch, no? You can choose to change it to use $TRASH but that should be done in a separate patch.
I just wanted to note it in case you didn't see it. It's a trivial issue and I don't really care, I just wanted to note it in case the v2 went past you.
Just for the record: I don't care either ;-).
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Re: [PATCH 2/3] don't write to git_log_output_encoding outside git_config()
In reply to Matthieu MoyHi,
I'm just raising attention on this patch. It didn't receive any comment and didn't find its way to pu.
I think it makes the code more robust, and would prevent accidental bugs like the one I introduced patching the gitattributes patch, but it's not critical.
Anyway, if you (i.e. the mailing list, not Junio) don't like the patch, I'd prefer to have counter-argument than having the patch silently ignored ;-).
Thanks,
Quoted 116 lines · Matthieu Moy
The log encoding can be given by the user either with --encoding=foo or with i18n.logoutputencoding. The code dealing with this used to write to
git_log_output_encodingin both places, making sure that --encoding=foo is dealt with after reading the configuration file.This is a very fragile mechanism, since any further call to
git_config(git_default_config, ...)the value given on the command line.Instead, keep the config value and the cli value, and decide which one to take at read time (in the straightforward accessor
get_git_log_output_encoding()).Signed-off-by Matthieu Moy <[email protected]>---
So, this isn't strictly necessary since the new version of the patch implementing the gitattributes file doesn't read the full config anymore, but I think that makes the code more robust.builtin/log.c | 4 ++-- cache.h | 18 ++++++++++++++++++ environment.c | 4 +++- pretty.c | 4 ++-- revision.c | 4 ++-- 5 files changed, 27 insertions(+), 7 deletions(-)builtin/log.c +2
-2@@ -329,8 +329,8 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)struct strbuf out =STRBUF_INIT ;pp_user_info ("Tagger" , rev->commit_format, &out, buf, rev->date_mode, - git_log_output_encoding ? - git_log_output_encoding: git_commit_encoding); +get_git_log_output_encoding () ? +get_git_log_output_encoding (): git_commit_encoding);printf ("%s" , out.buf);strbuf_release (&out); }cache.h +18
-0@@ -1005,7 +1005,25 @@ extern int user_ident_explicitly_given;extern int user_ident_sufficiently_given (void );extern const char *git_commit_encoding; + +/* Value found in config file */ extern const char *git_log_output_encoding; + +/* Value given in command line with --encoding */ +extern const char *git_log_output_encoding_cli; + +/* +* Prioritize the value given by the command-line over the value found +* in the config file. +*/ +static inline +const char *get_git_log_output_encoding () +{ +return git_log_output_encoding_cli ? + git_log_output_encoding_cli : + git_log_output_encoding; +} +extern const char *git_mailmap_file;/* IO helper functions */ environment.c +3
-1@@ -23,7 +23,9 @@ int log_all_ref_updates = -1; /* unspecified */int warn_ambiguous_refs =1 ;int repository_format_version;const char *git_commit_encoding; -const char *git_log_output_encoding; +const char *git_log_output_encoding =NULL ; +const char *git_log_output_encoding_cli =NULL ; +int shared_repository =PERM_UMASK ;const char *apply_default_whitespace;const char *apply_default_ignorewhitespace;pretty.c +2
-2@@ -1159,8 +1159,8 @@ char *reencode_commit_message(const struct commit *commit, const char **encoding {const char *encoding; - encoding = (git_log_output_encoding - ? git_log_output_encoding + encoding = (get_git_log_output_encoding () + ?get_git_log_output_encoding () : git_commit_encoding);if (!encoding) encoding ="UTF-8" ;revision.c +2
-2@@ -1402,9 +1402,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->grep_filter.all_match =1 ; }else if ((argcount =parse_long_opt ("encoding" , argv, &optarg))) {if (strcmp (optarg,"none" )) - git_log_output_encoding =xstrdup (optarg); + git_log_output_encoding_cli =xstrdup (optarg);else - git_log_output_encoding ="" ; + git_log_output_encoding_cli ="" ;return argcount; }else if (!strcmp (arg,"--reverse" )) { revs->reverse ^=1 ;
Signature · 2 lines
Matthieu Moy http://www-verimag.imag.fr/~moy/
Re: [PATCH 2/3] don't write to git_log_output_encoding outside git_config()
Quoted 6 lines · Matthieu Moy
I'm just raising attention on this patch. It didn't receive any comment and didn't find its way to pu.
I think it makes the code more robust, and would prevent accidental bugs like the one I introduced patching the gitattributes patch, but it's not critical.
If we didn't have the fix to po/etc-gitattributes topic, the patch is absolutely necessary as it stops bleeding.
Two points and a bit of discussion.
(1) The patch claims that the existing "have a variable in environment.c, with possibly hardcoded default, update that variable by reading config file at the startup, further override the same variable by reading the command line, and use the final result from the variable" pattern is fragile, _if_ configuration files can be re-read at random places outside the control of the main program.
The above claim _is_ correct, but is it the existing pattern that is broken, or the uncontrolled reading of configuration file, that is the real culprit (iow, you said "X if Y" but if Y is false then what X claims does not matter)?
I don't think we have a satisfactory answer to that question yet.
(2) If the answer to the question (1) is that the existing pattern is bad, I agree that a mechanism to protect the value that the main program decided to use (after taking environment.c default, config and its command line processing) _is_ necessary, and the patch shows one possible way to do so by replacing a single environment.c variable with a pair of variables and an accessor macro.
(a) Is that the best solution to the problem, though?
(b) Does the solution show us a pattern that is easy to follow to avoid the same problem with other environment.c variables?
One minor potential flaw I see is that while this solution can be applied to a variable of a type with an obvious "unset" value (e.g. pointer with NULL), we cannot use it for a variable of type "int" if it can truly take any value, because get_git_frotz() macro needs to be able to check if git_fortz_cli has that "unset" value in order to decide which one of the variables to use. My gut feeling is that it wouldn't matter in real-life (most int-type knobs actually take uint values), but I didn't check.
I care about (2-b) more than anything else. For example, we see "git_commit_encoding" variable in cache.h in the context of your patch. This particular patch does not have to (and I do not want it to) fix potential problems with that or any other variable, but it would be nice if the patch shows us an obvious and uniform way to apply the same fix when/if it becomes necessary. IOW, we would want to make sure that this is a generic enough solution, not an ad-hoc workaround.
Is there something we can do to make it easier to apply to other cases? Perhaps something along the lines of...
#define git_declare_var_pair(type, name, unset) \
extern type name; \
extern type name ## _cli; \
static inline type get_ ## name (void) { \
return (name ## _cli != (unset)) \
? name ## _cli \
: name; \
}
git_declare_var_pair(const char *, git_log_output_encoding, NULL)Or is it a way-premature generalization?
By the way, do we have a case where the main codepath reads an environment variable and updates a variable in environment.c to be used with that value? Then the existing "fragile" pattern for that case may look like:
- there is a variable with default value in environment.c;
- it is overwritten by reading configuration file;
- it is further overwritten by reading environ[];
- it is further overwritten by reading argv[];
- and then it is used.
Does the solution presented by this patch show us a pattern that is applicable to such a case as well?
Quoted 28 lines
Quoted 28 lines
cache.h +18
-0@@ -1005,7 +1005,25 @@ extern int user_ident_explicitly_given;extern int user_ident_sufficiently_given (void );extern const char *git_commit_encoding; + +/* Value found in config file */ extern const char *git_log_output_encoding; + +/* Value given in command line with --encoding */ +extern const char *git_log_output_encoding_cli; + +/* +* Prioritize the value given by the command-line over the value found +* in the config file. +*/ +static inline +const char *get_git_log_output_encoding () +{ +return git_log_output_encoding_cli ? + git_log_output_encoding_cli : + git_log_output_encoding; +} +extern const char *git_mailmap_file;