Teach new attribute 'export-ignore' to git-archive
Paths marked with this attribute are not output to git-archive output. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 8, 2008 at 18:42 UTC
008d896df5deaa967d4d86306b408333e8ef34c3
6 files changed
+33
Documentation/gitattributes.txt
+6
@@ -502,6 +502,12 @@ frotz unspecified
502
Creating an archive
503
~~~~~~~~~~~~~~~~~~~
504
505
+`export-ignore`
506
+^^^^^^^^^^^^^^^
507
+
508
+Files and directories with the attribute `export-ignore` won't be added to
509
+archive files.
510
+
511
`export-subst`
512
^^^^^^^^^^^^^^
513
archive-tar.c
+2
@@ -247,6 +247,8 @@ static int write_tar_entry(const unsigned char *sha1,
247
strbuf_grow(&path, PATH_MAX);
248
strbuf_add(&path, base, baselen);
249
strbuf_addstr(&path, filename);
250
+ if (is_archive_path_ignored(path.buf + base_len))
251
+ return 0;
252
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
253
strbuf_addch(&path, '/');
254
buffer = NULL;
archive-zip.c
+2
@@ -176,6 +176,8 @@ static int write_zip_entry(const unsigned char *sha1,
176
crc = crc32(0, NULL, 0);
177
178
path = construct_path(base, baselen, filename, S_ISDIR(mode), &pathlen);
179
+ if (is_archive_path_ignored(path + base_len))
180
+ return 0;
181
if (verbose)
182
fprintf(stderr, "%s\n", path);
183
if (pathlen > 0xffff) {
archive.c
+13
@@ -82,3 +82,16 @@ void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
82
return buffer;
83
}
84
85
+int is_archive_path_ignored(const char *path)
86
+{
87
+ static struct git_attr *attr_export_ignore;
88
+ struct git_attr_check check[1];
89
+
90
+ if (!attr_export_ignore)
91
+ attr_export_ignore = git_attr("export-ignore", 13);
92
+
93
+ check[0].attr = attr_export_ignore;
94
+ if (git_checkattr(path, ARRAY_SIZE(check), check))
95
+ return 0;
96
+ return ATTR_TRUE(check[0].value);
97
+}
archive.h
+1
@@ -44,5 +44,6 @@ extern int write_zip_archive(struct archiver_args *);
44
extern void *parse_extra_zip_args(int argc, const char **argv);
45
46
extern void *sha1_file_to_archive(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size, const struct commit *commit);
47
+extern int is_archive_path_ignored(const char *path);
48
49
#endif /* ARCHIVE_H */
t/t5000-tar-tree.sh
+9
@@ -44,6 +44,11 @@ test_expect_success \
44
echo text >file_with_long_path) &&
45
(cd a && find .) | sort >a.lst'
46
47
+test_expect_success \
48
+ 'add ignored file' \
49
+ 'echo ignore me >a/ignored &&
50
+ echo ignored export-ignore >.gitattributes'
51
+
52
test_expect_success \
53
'add files to repository' \
54
'find a -type f | xargs git update-index --add &&
@@ -53,6 +58,10 @@ test_expect_success \
58
git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
59
git commit-tree $treeid </dev/null)'
60
61
+test_expect_success \
62
+ 'remove ignored file' \
63
+ 'rm a/ignored'
64
+
65
test_expect_success \
66
'git archive' \
67
'git archive HEAD >b.tar'