git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/6] archive: add write_archive()
Date: Fri, 25 Jul 2008 12:41:21 +0200	[thread overview]
Message-ID: <1216982486-5887-1-git-send-email-rene.scharfe@lsrfire.ath.cx> (raw)

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>
---
 archive.c                |   18 ++++++++++++++++++
 archive.h                |    1 +
 builtin-archive.c        |   13 +------------
 builtin-upload-archive.c |   10 +---------
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/archive.c b/archive.c
index b8b45ba..75eb257 100644
--- a/archive.c
+++ b/archive.c
@@ -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);
+}
diff --git a/archive.h b/archive.h
index 4a02371..6b5fe5a 100644
--- a/archive.h
+++ b/archive.h
@@ -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 */
diff --git a/builtin-archive.c b/builtin-archive.c
index df97724..502b339 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -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);
@@ -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);
 }
diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c
index 13a6c62..cc37b36 100644
--- a/builtin-upload-archive.c
+++ b/builtin-upload-archive.c
@@ -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;
 
@@ -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, ...)
-- 
1.6.0.rc0.42.g186458

             reply	other threads:[~2008-07-25 10:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-25 10:41 Rene Scharfe [this message]
2008-07-25 10:41 ` [PATCH 2/6] archive: move parameter parsing code to archive.c Rene Scharfe
2008-07-25 10:41   ` [PATCH 3/6] archive: define MAX_ARGS where it's needed Rene Scharfe
2008-07-25 10:41     ` [PATCH 4/6] archive: declare struct archiver " Rene Scharfe
2008-07-25 10:41       ` [PATCH 5/6] archive: allow --exec and --remote without equal sign Rene Scharfe
2008-07-25 10:41         ` Rene Scharfe
2008-07-25 10:54           ` René Scharfe
2008-07-26  0:31           ` Junio C Hamano
2008-07-26  7:09             ` PATCH 6/6] archive: convert,to parse_options() [was: [PATCH 5/6] archive: allow --exec and --remote without equal sign] René Scharfe
2008-07-26  0:28         ` [PATCH 5/6] archive: allow --exec and --remote without equal sign Junio C Hamano

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=1216982486-5887-1-git-send-email-rene.scharfe@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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 NNTP newsgroup(s).