git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] core.attributesfile: a fix, a simplification, and a test

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Aug 28, 2010, 18:41 UTC
Message-ID
<1283020870-24888-1-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<vpqy6bqr3ep.fsf@bauges.imag.fr>
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)
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 attr.c                |    6 ++----
 t/t0003-attributes.sh |   14 ++++++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/attr.c b/attr.c
index 068e13b..342791a 100644
--- a/attr.c
+++ b/attr.c
@@ -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;
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index de38c7f..24286e5 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -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
-- 
1.7.2.2.175.ga619d.dirty
Previous: Matthieu MoyNext: Štěpán Němec
Message 13 of 36 in “Add global and system-wide gitattributes”
  1. Add global and system-wide gitattributesPetr Onderka, Aug 11, 2010
  2. Henrik GrubbströmAug 11, 2010
  3. Petr OnderkaAug 11, 2010
  4. Matthieu MoyAug 11, 2010
  5. Junio C HamanoAug 11, 2010
  6. Petr OnderkaAug 16, 2010
  7. Add global and system-wide gitattributesPetr Onderka, Aug 16, 2010
  8. Štěpán NěmecAug 25, 2010
  9. Matthieu MoyAug 28, 2010
  10. Junio C HamanoAug 30, 2010
  11. Štěpán NěmecAug 30, 2010
  12. Matthieu MoyAug 28, 2010
  13. core.attributesfile: a fix, a simplification, and a testMatthieu Moy, Aug 28, 2010
  14. Štěpán NěmecAug 29, 2010
  15. Junio C HamanoAug 30, 2010
  16. Matthieu MoyAug 30, 2010
  17. Junio C HamanoAug 30, 2010
  18. Junio C HamanoAug 30, 2010
  19. Matthieu MoyAug 30, 2010
  20. 1/3 tests: factor HOME=$(pwd) in test-lib.shMatthieu Moy, Aug 30, 2010
  21. Ævar Arnfjörð BjarmasonAug 31, 2010
  22. Ævar Arnfjörð BjarmasonSep 1, 2010
  23. Junio C HamanoSep 1, 2010
  24. Ævar Arnfjörð BjarmasonSep 1, 2010
  25. Matthieu MoySep 1, 2010
  26. 2/3 don't write to git_log_output_encoding outside git_config()Matthieu Moy, Aug 30, 2010
  27. Matthieu MoySep 2, 2010
  28. Junio C HamanoSep 2, 2010
  29. 3/3 Add global and system-wide gitattributesMatthieu Moy, Aug 30, 2010
  30. Matthieu MoyAug 31, 2010
  31. Add global and system-wide gitattributesMatthieu Moy, Aug 31, 2010
  32. Junio C HamanoAug 31, 2010
  33. tests: factor HOME=$(pwd) in test-lib.shMatthieu Moy, Aug 30, 2010
  34. Ævar Arnfjörð BjarmasonAug 30, 2010
  35. Matthieu MoyAug 30, 2010
  36. Ævar Arnfjörð BjarmasonAug 30, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.