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

[PATCH v2 4/5] archive: do not read .gitattributes in working directory

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Apr 17, 2009, 22:18 UTC
Message-ID
<49E9001D.9020209@lsrfire.ath.cx>
In-Reply-To
<1239848917-14399-1-git-send-email-gitster@pobox.com>
From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>

The old behaviour still remains with --worktree-attributes, and it is always on for the legacy "git tar-tree".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Changes:
   s/--fix-attributes/--worktree-attributes/g
   Don't make tar-tree silently ignore --worktree-attributes; its
   behaviour should not be changed any more.
 Documentation/git-archive.txt |    5 ++++-
 archive.c                     |   23 +++++++++++++++++++++++
 archive.h                     |    1 +
 builtin-tar-tree.c            |    9 ++++++++-
 4 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt
index c1adf59..bc132c8 100644
--- a/Documentation/git-archive.txt
+++ b/Documentation/git-archive.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git archive' --format=<fmt> [--list] [--prefix=<prefix>/] [<extra>]
-	      [--output=<file>]
+	      [--output=<file>] [--worktree-attributes]
 	      [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
 	      [path...]
 
@@ -51,6 +51,9 @@ OPTIONS
 --output=<file>::
 	Write the archive to <file> instead of stdout.
 
+--worktree-attributes::
+	Look for attributes in .gitattributes in working directory too.
+
 <extra>::
 	This can be any options that the archiver backend understands.
 	See next section.
diff --git a/archive.c b/archive.c
index 96b62d4..b2b90d3 100644
--- a/archive.c
+++ b/archive.c
@@ -4,6 +4,7 @@
 #include "attr.h"
 #include "archive.h"
 #include "parse-options.h"
+#include "unpack-trees.h"
 
 static char const * const archive_usage[] = {
 	"git archive [options] <tree-ish> [path...]",
@@ -150,6 +151,8 @@ int write_archive_entries(struct archiver_args *args,
 		write_archive_entry_fn_t write_entry)
 {
 	struct archiver_context context;
+	struct unpack_trees_options opts;
+	struct tree_desc t;
 	int err;
 
 	if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -168,6 +171,22 @@ int write_archive_entries(struct archiver_args *args,
 	context.args = args;
 	context.write_entry = write_entry;
 
+	/*
+	 * Setup index and instruct attr to read index only
+	 */
+	if (!args->worktree_attributes) {
+		memset(&opts, 0, sizeof(opts));
+		opts.index_only = 1;
+		opts.head_idx = -1;
+		opts.src_index = &the_index;
+		opts.dst_index = &the_index;
+		opts.fn = oneway_merge;
+		init_tree_desc(&t, args->tree->buffer, args->tree->size);
+		if (unpack_trees(1, &t, &opts))
+			return -1;
+		git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
+	}
+
 	err =  read_tree_recursive(args->tree, args->base, args->baselen, 0,
 			args->pathspec, write_archive_entry, &context);
 	if (err == READ_TREE_RECURSIVE)
@@ -258,6 +277,7 @@ static int parse_archive_args(int argc, const char **argv,
 	int verbose = 0;
 	int i;
 	int list = 0;
+	int worktree_attributes = 0;
 	struct option opts[] = {
 		OPT_GROUP(""),
 		OPT_STRING(0, "format", &format, "fmt", "archive format"),
@@ -265,6 +285,8 @@ static int parse_archive_args(int argc, const char **argv,
 			"prepend prefix to each pathname in the archive"),
 		OPT_STRING(0, "output", &output, "file",
 			"write the archive to this file"),
+		OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
+			"read .gitattributes in working directory"),
 		OPT__VERBOSE(&verbose),
 		OPT__COMPR('0', &compression_level, "store only", 0),
 		OPT__COMPR('1', &compression_level, "compress faster", 1),
@@ -324,6 +346,7 @@ static int parse_archive_args(int argc, const char **argv,
 	args->verbose = verbose;
 	args->base = base;
 	args->baselen = strlen(base);
+	args->worktree_attributes = worktree_attributes;
 
 	return argc;
 }
diff --git a/archive.h b/archive.h
index 0b15b35..038ac35 100644
--- a/archive.h
+++ b/archive.h
@@ -10,6 +10,7 @@ struct archiver_args {
 	time_t time;
 	const char **pathspec;
 	unsigned int verbose : 1;
+	unsigned int worktree_attributes : 1;
 	int compression_level;
 };
 
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 0713bca..1a5a2ed 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -24,7 +24,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
 	 * 	git archive --format-tar --prefix=basedir tree-ish
 	 */
 	int i;
-	const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
+	const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
 	char *basedir_arg;
 	int nargc = 0;
 
@@ -36,6 +36,13 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
 		argv++;
 		argc--;
 	}
+
+	/*
+	 * Because it's just a compatibility wrapper, tar-tree supports only
+	 * the old behaviour of reading attributes from the work tree.
+	 */
+	nargv[nargc++] = "--worktree-attributes";
+
 	switch (argc) {
 	default:
 		usage(tar_tree_usage);
-- 
1.6.3.rc0
Previous: René ScharfeNext: René Scharfe
Message 18 of 19 in “archive attribute series”
  1. 0/5 archive attribute seriesJunio C Hamano, Apr 16, 2009
  2. 1/5 archive tests: do not use .gitattributes in working directoryJunio C Hamano, Apr 16, 2009
  3. 2/5 attr: add GIT_ATTR_INDEX "direction"Junio C Hamano, Apr 16, 2009
  4. 3/5 unpack-trees: do not muck with attributes when we are not checking outJunio C Hamano, Apr 16, 2009
  5. 4/5 archive: do not read .gitattributes in working directoryJunio C Hamano, Apr 16, 2009
  6. 5/5 archive test: test new --fix-attributes featureJunio C Hamano, Apr 16, 2009
  7. René ScharfeApr 17, 2009
  8. Junio C HamanoApr 16, 2009
  9. Jeff KingApr 16, 2009
  10. Jakub NarebskiApr 16, 2009
  11. Nguyen Thai Ngoc DuyApr 16, 2009
  12. Nguyen Thai Ngoc DuyApr 16, 2009
  13. René ScharfeApr 17, 2009
  14. René ScharfeApr 17, 2009
  15. 1/5 archive tests: do not use .gitattributes in working directoryRené Scharfe, Apr 17, 2009
  16. 2/5 attr: add GIT_ATTR_INDEX "direction"René Scharfe, Apr 17, 2009
  17. 3/5 unpack-trees: do not muck with attributes when we are not checking outRené Scharfe, Apr 17, 2009
  18. 4/5 archive: do not read .gitattributes in working directoryRené Scharfe, Apr 17, 2009
  19. 5/5 archive test: attributesRené Scharfe, Apr 17, 2009

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.