Skip to content

Commit

Permalink
archive: add write_archive()
Browse files Browse the repository at this point in the history
Both archive and upload-archive have to parse command line arguments and
then call the archiver specific write function.  Move the duplicate code
to a new function, write_archive().

Signed-off-by: Rene Scharfe <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Rene Scharfe authored and gitster committed Jul 26, 2008
1 parent d3296e3 commit 6e94e68
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
18 changes: 18 additions & 0 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,21 @@ int write_archive_entries(struct archiver_args *args,
err = 0;
return err;
}

int write_archive(int argc, const char **argv, const char *prefix,
int setup_prefix)
{
const struct archiver *ar = NULL;
struct archiver_args args;
int tree_idx;

tree_idx = parse_archive_args(argc, argv, &ar, &args);
if (setup_prefix && prefix == NULL)
prefix = setup_git_directory();

argv += tree_idx;
parse_treeish_arg(argv, &args, prefix);
parse_pathspec_arg(argv + 1, &args);

return ar->write_archive(&args);
}
1 change: 1 addition & 0 deletions archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ extern int write_tar_archive(struct archiver_args *);
extern int write_zip_archive(struct archiver_args *);

extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix);

#endif /* ARCHIVE_H */
13 changes: 1 addition & 12 deletions builtin-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ static const char *extract_remote_arg(int *ac, const char **av)

int cmd_archive(int argc, const char **argv, const char *prefix)
{
const struct archiver *ar = NULL;
struct archiver_args args;
int tree_idx;
const char *remote = NULL;

remote = extract_remote_arg(&argc, argv);
Expand All @@ -243,13 +240,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)

setvbuf(stderr, NULL, _IOLBF, BUFSIZ);

tree_idx = parse_archive_args(argc, argv, &ar, &args);
if (prefix == NULL)
prefix = setup_git_directory();

argv += tree_idx;
parse_treeish_arg(argv, &args, prefix);
parse_pathspec_arg(argv + 1, &args);

return ar->write_archive(&args);
return write_archive(argc, argv, prefix, 1);
}
10 changes: 1 addition & 9 deletions builtin-upload-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ static const char lostchild[] =

static int run_upload_archive(int argc, const char **argv, const char *prefix)
{
const struct archiver *ar;
struct archiver_args args;
const char *sent_argv[MAX_ARGS];
const char *arg_cmd = "argument ";
char *p, buf[4096];
int treeish_idx;
int sent_argc;
int len;

Expand Down Expand Up @@ -66,12 +63,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)
sent_argv[sent_argc] = NULL;

/* parse all options sent by the client */
treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar, &args);

parse_treeish_arg(sent_argv + treeish_idx, &args, prefix);
parse_pathspec_arg(sent_argv + treeish_idx + 1, &args);

return ar->write_archive(&args);
return write_archive(sent_argc, sent_argv, prefix, 0);
}

static void error_clnt(const char *fmt, ...)
Expand Down

0 comments on commit 6e94e68

Please sign in to comment.