From: Heather Lapointe <alpha@alphaservcomputing.solutions> Remove archive_args.repo to ensure all functions are using local repository instances. Since all functions now have access to repo, this access isn't needed anymore. The main issue is that submodules do not use the same repo as the subproject repo that is being passed around contextually. Signed-off-by: Heather Lapointe <alpha@alphaservcomputing.solutions> --- archive.c | 51 +++++++++++++++++++++++++++++---------------------- archive.h | 1 - 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/archive.c b/archive.c index 2cca7bc5c8a..34549d849f1 100644 --- a/archive.c +++ b/archive.c @@ -36,7 +36,9 @@ void init_archivers(void) init_zip_archiver(); } -static void format_subst(const struct commit *commit, +static void format_subst( + struct repository *repo, + const struct commit *commit, const char *src, size_t len, struct strbuf *buf, struct pretty_print_context *ctx) { @@ -59,7 +61,7 @@ static void format_subst(const struct commit *commit, strbuf_add(&fmt, b + 8, c - b - 8); strbuf_add(buf, src, b - src); - format_commit_message(commit, fmt.buf, buf, ctx); + repo_format_commit_message(repo, commit, fmt.buf, buf, ctx); len -= c + 1 - src; src = c + 1; } @@ -68,7 +70,9 @@ static void format_subst(const struct commit *commit, free(to_free); } -static void *object_file_to_archive(const struct archiver_args *args, +static void *object_file_to_archive( + struct repository *repo, + const struct archiver_args *args, const char *path, const struct object_id *oid, unsigned int mode, @@ -84,15 +88,15 @@ static void *object_file_to_archive(const struct archiver_args *args, (args->tree ? &args->tree->object.oid : NULL), oid); path += args->baselen; - buffer = read_object_file(oid, type, sizep); + buffer = repo_read_object_file(repo, oid, type, sizep); if (buffer && S_ISREG(mode)) { struct strbuf buf = STRBUF_INIT; size_t size = 0; strbuf_attach(&buf, buffer, *sizep, *sizep + 1); - convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf, &meta); + convert_to_working_tree(repo->index, path, buf.buf, buf.len, &buf, &meta); if (commit) - format_subst(commit, buf.buf, buf.len, &buf, args->pretty_ctx); + format_subst(repo, commit, buf.buf, buf.len, &buf, args->pretty_ctx); buffer = strbuf_detach(&buf, &size); *sizep = size; } @@ -186,7 +190,7 @@ static int write_archive_entry( size > big_file_threshold) return write_entry(repo, args, oid, path.buf, path.len, mode, NULL, size); - buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size); + buffer = object_file_to_archive(repo, args, path.buf, oid, mode, &type, &size); if (!buffer) return error(_("cannot read '%s'"), oid_to_hex(oid)); err = write_entry(repo, args, oid, path.buf, path.len, mode, buffer, size); @@ -313,8 +317,8 @@ int write_archive_entries( 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.src_index = repo->index; + opts.dst_index = repo->index; opts.fn = oneway_merge; init_tree_desc(&t, args->tree->buffer, args->tree->size); if (unpack_trees(1, &t, &opts)) @@ -322,7 +326,7 @@ int write_archive_entries( git_attr_set_direction(GIT_ATTR_INDEX); } - err = read_tree(args->repo, args->tree, + err = read_tree(repo, args->tree, &args->pathspec, queue_or_write_archive_entry, &context); @@ -412,7 +416,7 @@ static int reject_entry( return ret; } -static int path_exists(struct archiver_args *args, const char *path) +static int path_exists(struct repository *repo, struct archiver_args *args, const char *path) { const char *paths[] = { path, NULL }; struct path_exists_context ctx; @@ -421,14 +425,16 @@ static int path_exists(struct archiver_args *args, const char *path) ctx.args = args; parse_pathspec(&ctx.pathspec, 0, 0, "", paths); ctx.pathspec.recursive = 1; - ret = read_tree(args->repo, args->tree, + ret = read_tree(repo, args->tree, &ctx.pathspec, reject_entry, &ctx); clear_pathspec(&ctx.pathspec); return ret != 0; } -static void parse_pathspec_arg(const char **pathspec, +static void parse_pathspec_arg( + struct repository *repo, + const char **pathspec, struct archiver_args *ar_args) { /* @@ -442,14 +448,16 @@ static void parse_pathspec_arg(const char **pathspec, ar_args->pathspec.recursive = 1; if (pathspec) { while (*pathspec) { - if (**pathspec && !path_exists(ar_args, *pathspec)) + if (**pathspec && !path_exists(repo, ar_args, *pathspec)) die(_("pathspec '%s' did not match any files"), *pathspec); pathspec++; } } } -static void parse_treeish_arg(const char **argv, +static void parse_treeish_arg( + struct repository *repo, + const char **argv, struct archiver_args *ar_args, const char *prefix, int remote) { @@ -475,7 +483,7 @@ static void parse_treeish_arg(const char **argv, if (get_oid(name, &oid)) die(_("not a valid object name: %s"), name); - commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1); + commit = lookup_commit_reference_gently(repo, &oid, 1); if (commit) { commit_oid = &commit->object.oid; archive_time = commit->date; @@ -484,7 +492,7 @@ static void parse_treeish_arg(const char **argv, archive_time = time(NULL); } - tree = parse_tree_indirect(&oid); + tree = repo_parse_tree_indirect(repo, &oid); if (!tree) die(_("not a tree object: %s"), oid_to_hex(&oid)); @@ -493,14 +501,14 @@ static void parse_treeish_arg(const char **argv, unsigned short mode; int err; - err = get_tree_entry(ar_args->repo, + err = get_tree_entry(repo, &tree->object.oid, prefix, &tree_oid, &mode); if (err || !S_ISDIR(mode)) die(_("current working directory is untracked")); - tree = parse_tree_indirect(&tree_oid); + tree = repo_parse_tree_indirect(repo, &tree_oid); } ar_args->refname = ref; ar_args->tree = tree; @@ -701,7 +709,6 @@ int write_archive(int argc, const char **argv, const char *prefix, ctx.abbrev = DEFAULT_ABBREV; ctx.describe_status = &describe_status; args.pretty_ctx = &ctx; - args.repo = repo; args.prefix = prefix; string_list_init_dup(&args.extra_files); argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote); @@ -714,8 +721,8 @@ int write_archive(int argc, const char **argv, const char *prefix, setup_git_directory(); } - parse_treeish_arg(argv, &args, prefix, remote); - parse_pathspec_arg(argv + 1, &args); + parse_treeish_arg(repo, argv, &args, prefix, remote); + parse_pathspec_arg(repo, argv + 1, &args); rc = ar->write_archive(ar, repo, &args); diff --git a/archive.h b/archive.h index bfbbd3274bd..540a3b12130 100644 --- a/archive.h +++ b/archive.h @@ -8,7 +8,6 @@ struct repository; struct pretty_print_context; struct archiver_args { - struct repository *repo; char *refname; const char *prefix; const char *base; -- gitgitgadget