Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

archive: do not read .gitattributes in working directory

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>
  • Loading branch information...
commit ba053ea96c252e04729dcd439e3c35d394d69914 1 parent 66985e6
Nguyễn Thái Ngọc Duy authored gitster committed
5  Documentation/git-archive.txt
@@ -10,7 +10,7 @@ SYNOPSIS
10 10
 --------
11 11
 [verse]
12 12
 'git archive' --format=<fmt> [--list] [--prefix=<prefix>/] [<extra>]
13  
-	      [--output=<file>]
  13
+	      [--output=<file>] [--worktree-attributes]
14 14
 	      [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
15 15
 	      [path...]
16 16
 
@@ -51,6 +51,9 @@ OPTIONS
51 51
 --output=<file>::
52 52
 	Write the archive to <file> instead of stdout.
53 53
 
  54
+--worktree-attributes::
  55
+	Look for attributes in .gitattributes in working directory too.
  56
+
54 57
 <extra>::
55 58
 	This can be any options that the archiver backend understands.
56 59
 	See next section.
23  archive.c
@@ -4,6 +4,7 @@
4 4
 #include "attr.h"
5 5
 #include "archive.h"
6 6
 #include "parse-options.h"
  7
+#include "unpack-trees.h"
7 8
 
8 9
 static char const * const archive_usage[] = {
9 10
 	"git archive [options] <tree-ish> [path...]",
@@ -150,6 +151,8 @@ int write_archive_entries(struct archiver_args *args,
150 151
 		write_archive_entry_fn_t write_entry)
151 152
 {
152 153
 	struct archiver_context context;
  154
+	struct unpack_trees_options opts;
  155
+	struct tree_desc t;
153 156
 	int err;
154 157
 
155 158
 	if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -168,6 +171,22 @@ int write_archive_entries(struct archiver_args *args,
168 171
 	context.args = args;
169 172
 	context.write_entry = write_entry;
170 173
 
  174
+	/*
  175
+	 * Setup index and instruct attr to read index only
  176
+	 */
  177
+	if (!args->worktree_attributes) {
  178
+		memset(&opts, 0, sizeof(opts));
  179
+		opts.index_only = 1;
  180
+		opts.head_idx = -1;
  181
+		opts.src_index = &the_index;
  182
+		opts.dst_index = &the_index;
  183
+		opts.fn = oneway_merge;
  184
+		init_tree_desc(&t, args->tree->buffer, args->tree->size);
  185
+		if (unpack_trees(1, &t, &opts))
  186
+			return -1;
  187
+		git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
  188
+	}
  189
+
171 190
 	err =  read_tree_recursive(args->tree, args->base, args->baselen, 0,
172 191
 			args->pathspec, write_archive_entry, &context);
173 192
 	if (err == READ_TREE_RECURSIVE)
@@ -258,6 +277,7 @@ static int parse_archive_args(int argc, const char **argv,
258 277
 	int verbose = 0;
259 278
 	int i;
260 279
 	int list = 0;
  280
+	int worktree_attributes = 0;
261 281
 	struct option opts[] = {
262 282
 		OPT_GROUP(""),
263 283
 		OPT_STRING(0, "format", &format, "fmt", "archive format"),
@@ -265,6 +285,8 @@ static int parse_archive_args(int argc, const char **argv,
265 285
 			"prepend prefix to each pathname in the archive"),
266 286
 		OPT_STRING(0, "output", &output, "file",
267 287
 			"write the archive to this file"),
  288
+		OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
  289
+			"read .gitattributes in working directory"),
268 290
 		OPT__VERBOSE(&verbose),
269 291
 		OPT__COMPR('0', &compression_level, "store only", 0),
270 292
 		OPT__COMPR('1', &compression_level, "compress faster", 1),
@@ -324,6 +346,7 @@ static int parse_archive_args(int argc, const char **argv,
324 346
 	args->verbose = verbose;
325 347
 	args->base = base;
326 348
 	args->baselen = strlen(base);
  349
+	args->worktree_attributes = worktree_attributes;
327 350
 
328 351
 	return argc;
329 352
 }
1  archive.h
@@ -10,6 +10,7 @@ struct archiver_args {
10 10
 	time_t time;
11 11
 	const char **pathspec;
12 12
 	unsigned int verbose : 1;
  13
+	unsigned int worktree_attributes : 1;
13 14
 	int compression_level;
14 15
 };
15 16
 
9  builtin-tar-tree.c
@@ -24,7 +24,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
24 24
 	 * 	git archive --format-tar --prefix=basedir tree-ish
25 25
 	 */
26 26
 	int i;
27  
-	const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
  27
+	const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
28 28
 	char *basedir_arg;
29 29
 	int nargc = 0;
30 30
 
@@ -36,6 +36,13 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
36 36
 		argv++;
37 37
 		argc--;
38 38
 	}
  39
+
  40
+	/*
  41
+	 * Because it's just a compatibility wrapper, tar-tree supports only
  42
+	 * the old behaviour of reading attributes from the work tree.
  43
+	 */
  44
+	nargv[nargc++] = "--worktree-attributes";
  45
+
39 46
 	switch (argc) {
40 47
 	default:
41 48
 		usage(tar_tree_usage);

0 notes on commit ba053ea

Please sign in to comment.
Something went wrong with that request. Please try again.