Skip to content

Commit

Permalink
archive: pass archiver struct to write_archive callback
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Jun 22, 2011
1 parent 13e0f88 commit 4d7c989
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ static int git_tar_config(const char *var, const char *value, void *cb)
return 0;
}

static int write_tar_archive(struct archiver_args *args)
static int write_tar_archive(const struct archiver *ar,
struct archiver_args *args)
{
int err = 0;

Expand Down
3 changes: 2 additions & 1 deletion archive-zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ static void dos_time(time_t *time, int *dos_date, int *dos_time)
*dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
}

static int write_zip_archive(struct archiver_args *args)
static int write_zip_archive(const struct archiver *ar,
struct archiver_args *args)
{
int err;

Expand Down
2 changes: 1 addition & 1 deletion archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,5 +410,5 @@ int write_archive(int argc, const char **argv, const char *prefix,
parse_treeish_arg(argv, &args, prefix);
parse_pathspec_arg(argv + 1, &args);

return ar->write_archive(&args);
return ar->write_archive(ar, &args);
}
3 changes: 2 additions & 1 deletion archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ struct archiver_args {
#define ARCHIVER_WANT_COMPRESSION_LEVELS 1
struct archiver {
const char *name;
int (*write_archive)(struct archiver_args *);
int (*write_archive)(const struct archiver *, struct archiver_args *);
unsigned flags;
void *data;
};
extern void register_archiver(struct archiver *);

Expand Down

0 comments on commit 4d7c989

Please sign in to comment.