public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire•ath.cx>
To: Junio C Hamano <gitster@pobox•com>
Cc: Git Mailing List <git@vger•kernel.org>
Subject: [PATCH 3/6] archive: add baselen member to struct archiver_args
Date: Mon, 14 Jul 2008 21:23:53 +0200	[thread overview]
Message-ID: <487BA7C9.6090908@lsrfire.ath.cx> (raw)
In-Reply-To: <487B92FC.5030103@lsrfire.ath.cx>

Calculate the length of base and save it in a new member of struct
archiver_args.  This way we don't have to compute it in each of the
format backends.

Note: parse_archive_args() guarantees that ->base won't ever be NULL.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire•ath.cx>
---
 archive-tar.c     |    8 +++-----
 archive-zip.c     |    8 +++-----
 archive.h         |    1 +
 builtin-archive.c |    1 +
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/archive-tar.c b/archive-tar.c
index 6eaf59e..63cc2ec 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -268,19 +268,17 @@ static int write_tar_entry(const unsigned char
*sha1, const char *base,

 int write_tar_archive(struct archiver_args *args)
 {
-	int plen = args->base ? strlen(args->base) : 0;
-
 	git_config(git_tar_config, NULL);

 	archive_time = args->time;
 	verbose = args->verbose;
 	commit = args->commit;
-	base_len = args->base ? strlen(args->base) : 0;
+	base_len = args->baselen;

 	if (args->commit_sha1)
 		write_global_extended_header(args->commit_sha1);

-	if (args->base && plen > 0 && args->base[plen - 1] == '/') {
+	if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
 		char *base = xstrdup(args->base);
 		int baselen = strlen(base);

@@ -290,7 +288,7 @@ int write_tar_archive(struct archiver_args *args)
 				0, NULL);
 		free(base);
 	}
-	read_tree_recursive(args->tree, args->base, plen, 0,
+	read_tree_recursive(args->tree, args->base, args->baselen, 0,
 			    args->pathspec, write_tar_entry, NULL);
 	write_trailer();

diff --git a/archive-zip.c b/archive-zip.c
index 0d24f3f..d18254c 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -316,17 +316,15 @@ static void dos_time(time_t *time, int *dos_date,
int *dos_time)

 int write_zip_archive(struct archiver_args *args)
 {
-	int plen = strlen(args->base);
-
 	dos_time(&args->time, &zip_date, &zip_time);

 	zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
 	zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
 	verbose = args->verbose;
 	commit = args->commit;
-	base_len = args->base ? strlen(args->base) : 0;
+	base_len = args->baselen;

-	if (args->base && plen > 0 && args->base[plen - 1] == '/') {
+	if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
 		char *base = xstrdup(args->base);
 		int baselen = strlen(base);

@@ -336,7 +334,7 @@ int write_zip_archive(struct archiver_args *args)
 				0, NULL);
 		free(base);
 	}
-	read_tree_recursive(args->tree, args->base, plen, 0,
+	read_tree_recursive(args->tree, args->base, args->baselen, 0,
 			    args->pathspec, write_zip_entry, NULL);
 	write_zip_trailer(args->commit_sha1);

diff --git a/archive.h b/archive.h
index 1b24ae3..34151f4 100644
--- a/archive.h
+++ b/archive.h
@@ -6,6 +6,7 @@

 struct archiver_args {
 	const char *base;
+	size_t baselen;
 	struct tree *tree;
 	const unsigned char *commit_sha1;
 	const struct commit *commit;
diff --git a/builtin-archive.c b/builtin-archive.c
index 6ee3677..e7f4ec6 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -192,6 +192,7 @@ int parse_archive_args(int argc, const char **argv,
const struct archiver **ar,
 	}
 	args->verbose = verbose;
 	args->base = base;
+	args->baselen = strlen(base);

 	return i;
 }
-- 
1.5.6.2.212.g08b51

  parent reply	other threads:[~2008-07-14 19:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <487B92FC.5030103@lsrfire.ath.cx>
2008-07-14 19:22 ` [PATCH 6/6] archive: remove extra arguments parsing code René Scharfe
2008-07-14 19:22 ` [PATCH 2/6] add context pointer to read_tree_recursive() René Scharfe
2008-07-14 19:22 ` [PATCH 4/6] archive: centralize archive entry writing René Scharfe
2008-07-14 19:22 ` [PATCH 5/6] archive: unify file attribute handling René Scharfe
2008-07-14 19:23 ` René Scharfe [this message]
2008-07-15  7:49   ` [PATCH 3/6] archive: add baselen member to struct archiver_args René Scharfe

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=487BA7C9.6090908@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire$(echo .)ath.cx \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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