@matheusbsbs / matheus-bagliano / commits / 6e94e6835f
Fork 0

archive: add write_archive()

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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rene Scharfe committed Jul 25, 2008 at 12:41 UTC 6e94e6835f397cd2602ca1eb12002e51aa6b0500
4 files changed +21 -21
archive.c
+18
@@ -155,3 +155,21 @@ int write_archive_entries(struct archiver_args *args,
155 err = 0;
156 return err;
157 }
158 +
159 +int write_archive(int argc, const char **argv, const char *prefix,
160 + int setup_prefix)
161 +{
162 + const struct archiver *ar = NULL;
163 + struct archiver_args args;
164 + int tree_idx;
165 +
166 + tree_idx = parse_archive_args(argc, argv, &ar, &args);
167 + if (setup_prefix && prefix == NULL)
168 + prefix = setup_git_directory();
169 +
170 + argv += tree_idx;
171 + parse_treeish_arg(argv, &args, prefix);
172 + parse_pathspec_arg(argv + 1, &args);
173 +
174 + return ar->write_archive(&args);
175 +}
archive.h
+1
@@ -41,5 +41,6 @@ extern int write_tar_archive(struct archiver_args *);
41 extern int write_zip_archive(struct archiver_args *);
42
43 extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
44 +extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix);
45
46 #endif /* ARCHIVE_H */
builtin-archive.c
+1 -12
@@ -232,9 +232,6 @@ static const char *extract_remote_arg(int *ac, const char **av)
232
233 int cmd_archive(int argc, const char **argv, const char *prefix)
234 {
235 - const struct archiver *ar = NULL;
236 - struct archiver_args args;
237 - int tree_idx;
235 const char *remote = NULL;
236
237 remote = extract_remote_arg(&argc, argv);
@@ -243,13 +240,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
240
241 setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
242
246 - tree_idx = parse_archive_args(argc, argv, &ar, &args);
247 - if (prefix == NULL)
248 - prefix = setup_git_directory();
249 -
250 - argv += tree_idx;
251 - parse_treeish_arg(argv, &args, prefix);
252 - parse_pathspec_arg(argv + 1, &args);
253 -
254 - return ar->write_archive(&args);
243 + return write_archive(argc, argv, prefix, 1);
244 }
builtin-upload-archive.c
+1 -9
@@ -19,12 +19,9 @@ static const char lostchild[] =
19
20 static int run_upload_archive(int argc, const char **argv, const char *prefix)
21 {
22 - const struct archiver *ar;
23 - struct archiver_args args;
22 const char *sent_argv[MAX_ARGS];
23 const char *arg_cmd = "argument ";
24 char *p, buf[4096];
27 - int treeish_idx;
25 int sent_argc;
26 int len;
27
@@ -66,12 +63,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)
63 sent_argv[sent_argc] = NULL;
64
65 /* parse all options sent by the client */
69 - treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar, &args);
70 -
71 - parse_treeish_arg(sent_argv + treeish_idx, &args, prefix);
72 - parse_pathspec_arg(sent_argv + treeish_idx + 1, &args);
73 -
74 - return ar->write_archive(&args);
66 + return write_archive(sent_argc, sent_argv, prefix, 0);
67 }
68
69 static void error_clnt(const char *fmt, ...)