Skip to content

Commit 4d7c989

Browse files
peffgitster
authored andcommitted
archive: pass archiver struct to write_archive callback
The current archivers are very static; when you are in the write_tar_archive function, you know you are writing a tar. However, to facilitate runtime-configurable archivers that will share a common write function we need to tell the function which archiver was used. As a convenience, we also provide an opaque data pointer in the archiver struct so that individual archivers can put something useful there when they register themselves. Technically they could just use the "name" field to look in an internal map of names to data, but this is much simpler. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 13e0f88 commit 4d7c989

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

archive-tar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ static int git_tar_config(const char *var, const char *value, void *cb)
234234
return 0;
235235
}
236236

237-
static int write_tar_archive(struct archiver_args *args)
237+
static int write_tar_archive(const struct archiver *ar,
238+
struct archiver_args *args)
238239
{
239240
int err = 0;
240241

archive-zip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ static void dos_time(time_t *time, int *dos_date, int *dos_time)
261261
*dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
262262
}
263263

264-
static int write_zip_archive(struct archiver_args *args)
264+
static int write_zip_archive(const struct archiver *ar,
265+
struct archiver_args *args)
265266
{
266267
int err;
267268

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,5 +410,5 @@ int write_archive(int argc, const char **argv, const char *prefix,
410410
parse_treeish_arg(argv, &args, prefix);
411411
parse_pathspec_arg(argv + 1, &args);
412412

413-
return ar->write_archive(&args);
413+
return ar->write_archive(ar, &args);
414414
}

archive.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ struct archiver_args {
1717
#define ARCHIVER_WANT_COMPRESSION_LEVELS 1
1818
struct archiver {
1919
const char *name;
20-
int (*write_archive)(struct archiver_args *);
20+
int (*write_archive)(const struct archiver *, struct archiver_args *);
2121
unsigned flags;
22+
void *data;
2223
};
2324
extern void register_archiver(struct archiver *);
2425

0 commit comments

Comments
 (0)