summaryrefslogtreecommitdiffstats
path: root/archive.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-10-01 01:16:15 +0200
committerJunio C Hamano <gitster@pobox.com>2024-10-01 01:16:16 +0200
commitc58eee092888844c5da0bf6e6c73ef3862ea080c (patch)
treefa7484b9279bf95c5ace6966a37cd7a2c002a4dc /archive.c
parentMerge branch 'rs/commit-graph-ununleak' (diff)
parentarchive: load index before pathspec checks (diff)
downloadgit-c58eee092888844c5da0bf6e6c73ef3862ea080c.tar.xz
git-c58eee092888844c5da0bf6e6c73ef3862ea080c.zip
Merge branch 'rs/archive-with-attr-pathspec-fix'
"git archive" with pathspec magic that uses the attribute information did not work well, which has been corrected. * rs/archive-with-attr-pathspec-fix: archive: load index before pathspec checks
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/archive.c b/archive.c
index 9ba96aae4f..58f86bf75c 100644
--- a/archive.c
+++ b/archive.c
@@ -304,8 +304,6 @@ 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;
struct strbuf path_in_archive = STRBUF_INIT;
struct strbuf content = STRBUF_INIT;
@@ -331,23 +329,6 @@ 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 = args->repo->index;
- opts.dst_index = args->repo->index;
- opts.fn = oneway_merge;
- init_tree_desc(&t, &args->tree->object.oid,
- args->tree->buffer, args->tree->size);
- if (unpack_trees(1, &t, &opts))
- return -1;
- git_attr_set_direction(GIT_ATTR_INDEX);
- }
-
err = read_tree(args->repo, args->tree,
&args->pathspec,
queue_or_write_archive_entry,
@@ -540,6 +521,26 @@ static void parse_treeish_arg(const char **argv,
if (!tree)
die(_("not a tree object: %s"), oid_to_hex(&oid));
+ /*
+ * Setup index and instruct attr to read index only
+ */
+ if (!ar_args->worktree_attributes) {
+ struct unpack_trees_options opts;
+ struct tree_desc t;
+
+ memset(&opts, 0, sizeof(opts));
+ opts.index_only = 1;
+ opts.head_idx = -1;
+ opts.src_index = ar_args->repo->index;
+ opts.dst_index = ar_args->repo->index;
+ opts.fn = oneway_merge;
+ init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
+ if (unpack_trees(1, &t, &opts))
+ die(_("unable to checkout working tree"));
+
+ git_attr_set_direction(GIT_ATTR_INDEX);
+ }
+
ar_args->refname = ref;
ar_args->tree = tree;
ar_args->commit_oid = commit_oid;