From: "Heather Lapointe via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "René Scharfe" <l.s.r@web.de>,
"Heather Lapointe" <alpha@alphaservcomputing.solutions>,
"Heather Lapointe" <alpha@alphaservcomputing.solutions>
Subject: [PATCH v3 6/9] archive: pass repo objects to write_archive handlers
Date: Mon, 17 Oct 2022 02:23:18 +0000 [thread overview]
Message-ID: <1b9b049d64fc4ea919c94e57b74a1760b3837892.1665973401.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1359.v3.git.git.1665973401.gitgitgadget@gmail.com>
From: Heather Lapointe <alpha@alphaservcomputing.solutions>
Use contextual repos instead of the_repository or args->repo
to ensure that submodules will be handled correctly
since they use multiple repo instances.
Signed-off-by: Heather Lapointe <alpha@alphaservcomputing.solutions>
---
archive-tar.c | 15 ++++++++++-----
archive-zip.c | 15 +++++++++------
archive.c | 38 ++++++++++++++++++++++----------------
archive.h | 14 +++++++++++---
4 files changed, 52 insertions(+), 30 deletions(-)
diff --git a/archive-tar.c b/archive-tar.c
index 3e4822b6840..5a2d42ff229 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -18,6 +18,7 @@ static unsigned long offset;
static int tar_umask = 002;
static int write_tar_filter_archive(const struct archiver *ar,
+ struct repository *repo,
struct archiver_args *args);
/*
@@ -246,7 +247,9 @@ static void write_extended_header(struct archiver_args *args,
write_blocked(buffer, size);
}
-static int write_tar_entry(struct archiver_args *args,
+static int write_tar_entry(
+ struct repository *repo,
+ struct archiver_args *args,
const struct object_id *oid,
const char *path, size_t pathlen,
unsigned int mode,
@@ -316,7 +319,7 @@ static int write_tar_entry(struct archiver_args *args,
if (buffer)
write_blocked(buffer, size);
else
- err = stream_blocked(args->repo, oid);
+ err = stream_blocked(repo, oid);
}
return err;
}
@@ -422,12 +425,13 @@ static int git_tar_config(const char *var, const char *value, void *cb)
}
static int write_tar_archive(const struct archiver *ar UNUSED,
+ struct repository *repo,
struct archiver_args *args)
{
int err = 0;
write_global_extended_header(args);
- err = write_archive_entries(args, write_tar_entry);
+ err = write_archive_entries(repo, args, write_tar_entry);
if (!err)
write_trailer();
return err;
@@ -462,6 +466,7 @@ static void tgz_write_block(const void *data)
static const char internal_gzip_command[] = "git archive gzip";
static int write_tar_filter_archive(const struct archiver *ar,
+ struct repository *repo,
struct archiver_args *args)
{
#if ZLIB_VERNUM >= 0x1221
@@ -484,7 +489,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
gzstream.next_out = outbuf;
gzstream.avail_out = sizeof(outbuf);
- r = write_tar_archive(ar, args);
+ r = write_tar_archive(ar, repo, args);
tgz_deflate(Z_FINISH);
git_deflate_end(&gzstream);
@@ -506,7 +511,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
die_errno(_("unable to redirect descriptor"));
close(filter.in);
- r = write_tar_archive(ar, args);
+ r = write_tar_archive(ar, repo, args);
close(1);
if (finish_command(&filter) != 0)
diff --git a/archive-zip.c b/archive-zip.c
index 0456f1ebf15..2c1f943a6cc 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -283,7 +283,9 @@ static int entry_is_binary(struct index_state *istate, const char *path,
#define STREAM_BUFFER_SIZE (1024 * 16)
-static int write_zip_entry(struct archiver_args *args,
+static int write_zip_entry(
+ struct repository *repo,
+ struct archiver_args *args,
const struct object_id *oid,
const char *path, size_t pathlen,
unsigned int mode,
@@ -340,7 +342,7 @@ static int write_zip_entry(struct archiver_args *args,
if (!buffer) {
enum object_type type;
- stream = open_istream(args->repo, oid, &type, &size,
+ stream = open_istream(repo, oid, &type, &size,
NULL);
if (!stream)
return error(_("cannot stream blob %s"),
@@ -349,7 +351,7 @@ static int write_zip_entry(struct archiver_args *args,
out = NULL;
} else {
crc = crc32(crc, buffer, size);
- is_binary = entry_is_binary(args->repo->index,
+ is_binary = entry_is_binary(repo->index,
path_without_prefix,
buffer, size);
out = buffer;
@@ -426,7 +428,7 @@ static int write_zip_entry(struct archiver_args *args,
break;
crc = crc32(crc, buf, readlen);
if (is_binary == -1)
- is_binary = entry_is_binary(args->repo->index,
+ is_binary = entry_is_binary(repo->index,
path_without_prefix,
buf, readlen);
write_or_die(1, buf, readlen);
@@ -459,7 +461,7 @@ static int write_zip_entry(struct archiver_args *args,
break;
crc = crc32(crc, buf, readlen);
if (is_binary == -1)
- is_binary = entry_is_binary(args->repo->index,
+ is_binary = entry_is_binary(repo->index,
path_without_prefix,
buf, readlen);
@@ -619,6 +621,7 @@ static int archive_zip_config(const char *var, const char *value,
}
static int write_zip_archive(const struct archiver *ar UNUSED,
+ struct repository *repo,
struct archiver_args *args)
{
int err;
@@ -629,7 +632,7 @@ static int write_zip_archive(const struct archiver *ar UNUSED,
strbuf_init(&zip_dir, 0);
- err = write_archive_entries(args, write_zip_entry);
+ err = write_archive_entries(repo, args, write_zip_entry);
if (!err)
write_zip_trailer(args->commit_oid);
diff --git a/archive.c b/archive.c
index 15f3ac92dfc..2cca7bc5c8a 100644
--- a/archive.c
+++ b/archive.c
@@ -134,7 +134,9 @@ static int check_attr_export_subst(const struct attr_check *check)
return check && ATTR_TRUE(check->items[1].value);
}
-static int write_archive_entry(const struct object_id *oid, const char *base,
+static int write_archive_entry(
+ struct repository *repo,
+ const struct object_id *oid, const char *base,
int baselen, const char *filename, unsigned mode,
void *context)
{
@@ -160,7 +162,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
if (!S_ISDIR(mode)) {
const struct attr_check *check;
- check = get_archive_attrs(args->repo->index, path_without_prefix);
+ check = get_archive_attrs(repo->index, path_without_prefix);
if (check_attr_export_ignore(check))
return 0;
args->convert = check_attr_export_subst(check);
@@ -169,7 +171,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
if (args->verbose)
fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
- err = write_entry(args, oid, path.buf, path.len, mode, NULL, 0);
+ err = write_entry(repo, args, oid, path.buf, path.len, mode, NULL, 0);
if (err)
return err;
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@ -180,14 +182,14 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ oid_object_info(repo, oid, &size) == OBJ_BLOB &&
size > big_file_threshold)
- return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
+ 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);
if (!buffer)
return error(_("cannot read '%s'"), oid_to_hex(oid));
- err = write_entry(args, oid, path.buf, path.len, mode, buffer, size);
+ err = write_entry(repo, args, oid, path.buf, path.len, mode, buffer, size);
free(buffer);
return err;
}
@@ -207,7 +209,9 @@ static void queue_directory(const struct object_id *oid,
oidcpy(&d->oid, oid);
}
-static int write_directory(struct archiver_context *c)
+static int write_directory(
+ struct repository *repo,
+ struct archiver_context *c)
{
struct directory *d = c->bottom;
int ret;
@@ -217,8 +221,8 @@ static int write_directory(struct archiver_context *c)
c->bottom = d->up;
d->path[d->len - 1] = '\0'; /* no trailing slash */
ret =
- write_directory(c) ||
- write_archive_entry(&d->oid, d->path, d->baselen,
+ write_directory(repo, c) ||
+ write_archive_entry(repo, &d->oid, d->path, d->baselen,
d->path + d->baselen, d->mode,
c) != READ_TREE_RECURSIVE;
free(d);
@@ -257,9 +261,9 @@ static int queue_or_write_archive_entry(
return READ_TREE_RECURSIVE;
}
- if (write_directory(c))
+ if (write_directory(r, c))
return -1;
- return write_archive_entry(oid, base->buf, base->len, filename, mode,
+ return write_archive_entry(r, oid, base->buf, base->len, filename, mode,
context);
}
@@ -269,7 +273,9 @@ struct extra_file_info {
void *content;
};
-int write_archive_entries(struct archiver_args *args,
+int write_archive_entries(
+ struct repository *repo,
+ struct archiver_args *args,
write_archive_entry_fn_t write_entry)
{
struct archiver_context context;
@@ -290,7 +296,7 @@ int write_archive_entries(struct archiver_args *args,
len--;
if (args->verbose)
fprintf(stderr, "%.*s\n", (int)len, args->base);
- err = write_entry(args, &args->tree->object.oid, args->base,
+ err = write_entry(repo, args, &args->tree->object.oid, args->base,
len, 040777, NULL, 0);
if (err)
return err;
@@ -345,12 +351,12 @@ int write_archive_entries(struct archiver_args *args,
if (strbuf_read_file(&content, path, info->stat.st_size) < 0)
err = error_errno(_("cannot read '%s'"), path);
else
- err = write_entry(args, &fake_oid, path_in_archive.buf,
+ err = write_entry(repo, args, &fake_oid, path_in_archive.buf,
path_in_archive.len,
canon_mode(info->stat.st_mode),
content.buf, content.len);
} else {
- err = write_entry(args, &fake_oid,
+ err = write_entry(repo, args, &fake_oid,
path, strlen(path),
canon_mode(info->stat.st_mode),
info->content, info->stat.st_size);
@@ -711,7 +717,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
parse_treeish_arg(argv, &args, prefix, remote);
parse_pathspec_arg(argv + 1, &args);
- rc = ar->write_archive(ar, &args);
+ rc = ar->write_archive(ar, repo, &args);
string_list_clear_func(&args.extra_files, extra_file_info_clear);
free(args.refname);
diff --git a/archive.h b/archive.h
index 08bed3ed3af..bfbbd3274bd 100644
--- a/archive.h
+++ b/archive.h
@@ -41,7 +41,10 @@ const char *archive_format_from_filename(const char *filename);
#define ARCHIVER_HIGH_COMPRESSION_LEVELS 4
struct archiver {
const char *name;
- int (*write_archive)(const struct archiver *, struct archiver_args *);
+ int (*write_archive)(
+ const struct archiver *,
+ struct repository *,
+ struct archiver_args *);
unsigned flags;
char *filter_command;
};
@@ -51,12 +54,17 @@ void init_tar_archiver(void);
void init_zip_archiver(void);
void init_archivers(void);
-typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
+typedef int (*write_archive_entry_fn_t)(
+ struct repository *repo,
+ struct archiver_args *args,
const struct object_id *oid,
const char *path, size_t pathlen,
unsigned int mode,
void *buffer, unsigned long size);
-int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
+int write_archive_entries(
+ struct repository *repo,
+ struct archiver_args *args,
+ write_archive_entry_fn_t write_entry);
#endif /* ARCHIVE_H */
--
gitgitgadget
next prev parent reply other threads:[~2022-10-17 2:23 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 17:52 [PATCH] archive: add --recurse-submodules to git-archive command Heather Lapointe via GitGitGadget
2022-10-13 11:35 ` [PATCH v2 0/2] archive: Add " Heather Lapointe via GitGitGadget
2022-10-13 11:35 ` [PATCH v2 1/2] archive: add " Alphadelta14 via GitGitGadget
2022-10-13 17:53 ` René Scharfe
2022-10-13 21:37 ` Heather Lapointe
2022-10-13 11:36 ` [PATCH v2 2/2] archive: fix a case of submodule in submodule traversal Alphadelta14 via GitGitGadget
2022-10-13 17:53 ` [PATCH v2 0/2] archive: Add --recurse-submodules to git-archive command René Scharfe
2022-10-13 21:23 ` Heather Lapointe
2022-10-14 9:47 ` René Scharfe
2022-10-17 2:23 ` [PATCH v3 0/9] " Heather Lapointe via GitGitGadget
2022-10-17 2:23 ` [PATCH v3 1/9] tree: do not use the_repository for tree traversal methods Alphadelta14 via GitGitGadget
2022-10-17 13:26 ` Junio C Hamano
2022-10-26 22:33 ` Glen Choo
2022-10-27 18:09 ` Jonathan Tan
2022-10-27 18:50 ` Junio C Hamano
2022-10-17 2:23 ` [PATCH v3 2/9] tree: update cases to use repo_ tree methods Heather Lapointe via GitGitGadget
2022-10-17 2:23 ` [PATCH v3 3/9] tree: increase test coverage for tree.c Heather Lapointe via GitGitGadget
2022-10-17 13:34 ` Phillip Wood
2022-10-17 13:36 ` Junio C Hamano
2022-10-27 18:28 ` Jonathan Tan
2022-10-17 2:23 ` [PATCH v3 4/9] tree: handle submodule case for read_tree_at properly Heather Lapointe via GitGitGadget
2022-10-17 13:48 ` Phillip Wood
2022-10-17 13:56 ` Junio C Hamano
2022-10-26 22:48 ` Glen Choo
2022-10-27 18:43 ` Jonathan Tan
2022-10-17 2:23 ` [PATCH v3 5/9] tree: add repository parameter to read_tree_fn_t Heather Lapointe via GitGitGadget
2022-10-17 2:23 ` Heather Lapointe via GitGitGadget [this message]
2022-10-17 13:50 ` [PATCH v3 6/9] archive: pass repo objects to write_archive handlers Phillip Wood
2022-10-17 2:23 ` [PATCH v3 7/9] archive: remove global repository from archive_args Heather Lapointe via GitGitGadget
2022-10-17 2:23 ` [PATCH v3 8/9] archive: add --recurse-submodules to git-archive command Heather Lapointe via GitGitGadget
2022-10-26 23:34 ` Glen Choo
2022-10-27 7:09 ` René Scharfe
2022-10-27 17:29 ` Glen Choo
2022-10-27 17:30 ` Glen Choo
2022-10-27 17:33 ` Glen Choo
2022-10-17 2:23 ` [PATCH v3 9/9] archive: add tests for git archive --recurse-submodules Heather Lapointe via GitGitGadget
2022-10-27 18:54 ` Jonathan Tan
2022-10-27 23:30 ` Glen Choo
2022-10-28 0:17 ` Ævar Arnfjörð Bjarmason
2022-10-17 13:57 ` [PATCH v3 0/9] archive: Add --recurse-submodules to git-archive command Phillip Wood
2022-10-18 18:34 ` Junio C Hamano
2022-10-18 18:48 ` Heather Lapointe
2022-10-19 16:16 ` Junio C Hamano
2022-10-19 20:44 ` Junio C Hamano
2022-10-20 1:21 ` Junio C Hamano
2022-10-21 1:43 ` Junio C Hamano
2022-10-26 22:14 ` Glen Choo
2022-10-28 18:18 ` Heather Lapointe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1b9b049d64fc4ea919c94e57b74a1760b3837892.1665973401.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=alpha@alphaservcomputing.solutions \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).