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>
Nguyễn Thái Ngọc Duy committed
Apr 18, 2009 at 00:18 UTC
ba053ea96c252e04729dcd439e3c35d394d69914
4 files changed
+36
-2
Documentation/git-archive.txt
+4
-1
@@ -10,7 +10,7 @@ SYNOPSIS
10
--------
11
[verse]
12
'git archive' --format=<fmt> [--list] [--prefix=<prefix>/] [<extra>]
13
- [--output=<file>]
13
+ [--output=<file>] [--worktree-attributes]
14
[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
15
[path...]
16
@@ -51,6 +51,9 @@ OPTIONS
51
--output=<file>::
52
Write the archive to <file> instead of stdout.
53
54
+--worktree-attributes::
55
+ Look for attributes in .gitattributes in working directory too.
56
+
57
<extra>::
58
This can be any options that the archiver backend understands.
59
See next section.
archive.c
+23
@@ -4,6 +4,7 @@
4
#include "attr.h"
5
#include "archive.h"
6
#include "parse-options.h"
7
+#include "unpack-trees.h"
8
9
static char const * const archive_usage[] = {
10
"git archive [options] <tree-ish> [path...]",
@@ -150,6 +151,8 @@ int write_archive_entries(struct archiver_args *args,
151
write_archive_entry_fn_t write_entry)
152
{
153
struct archiver_context context;
154
+ struct unpack_trees_options opts;
155
+ struct tree_desc t;
156
int err;
157
158
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -168,6 +171,22 @@ int write_archive_entries(struct archiver_args *args,
171
context.args = args;
172
context.write_entry = write_entry;
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
+
190
err = read_tree_recursive(args->tree, args->base, args->baselen, 0,
191
args->pathspec, write_archive_entry, &context);
192
if (err == READ_TREE_RECURSIVE)
@@ -258,6 +277,7 @@ static int parse_archive_args(int argc, const char **argv,
277
int verbose = 0;
278
int i;
279
int list = 0;
280
+ int worktree_attributes = 0;
281
struct option opts[] = {
282
OPT_GROUP(""),
283
OPT_STRING(0, "format", &format, "fmt", "archive format"),
@@ -265,6 +285,8 @@ static int parse_archive_args(int argc, const char **argv,
285
"prepend prefix to each pathname in the archive"),
286
OPT_STRING(0, "output", &output, "file",
287
"write the archive to this file"),
288
+ OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
289
+ "read .gitattributes in working directory"),
290
OPT__VERBOSE(&verbose),
291
OPT__COMPR('0', &compression_level, "store only", 0),
292
OPT__COMPR('1', &compression_level, "compress faster", 1),
@@ -324,6 +346,7 @@ static int parse_archive_args(int argc, const char **argv,
346
args->verbose = verbose;
347
args->base = base;
348
args->baselen = strlen(base);
349
+ args->worktree_attributes = worktree_attributes;
350
351
return argc;
352
}
archive.h
+1
@@ -10,6 +10,7 @@ struct archiver_args {
10
time_t time;
11
const char **pathspec;
12
unsigned int verbose : 1;
13
+ unsigned int worktree_attributes : 1;
14
int compression_level;
15
};
16
builtin-tar-tree.c
+8
-1
@@ -24,7 +24,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
24
* git archive --format-tar --prefix=basedir tree-ish
25
*/
26
int i;
27
- const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
27
+ const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
28
char *basedir_arg;
29
int nargc = 0;
30
@@ -36,6 +36,13 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
36
argv++;
37
argc--;
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
+
46
switch (argc) {
47
default:
48
usage(tar_tree_usage);