Skip to content

Commit

Permalink
archive: do not read .gitattributes in working directory
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pclouds authored and gitster committed Apr 18, 2009
1 parent 66985e6 commit ba053ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Documentation/git-archive.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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...]

Expand Down Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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...]",
Expand Down Expand Up @@ -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] == '/') {
Expand All @@ -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)
Expand Down Expand Up @@ -258,13 +277,16 @@ 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"),
OPT_STRING(0, "prefix", &base, "prefix",
"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),
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
9 changes: 8 additions & 1 deletion builtin-tar-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit ba053ea

Please sign in to comment.