@matheusbsbs / matheus-bagliano / commits / d53fe8187c
Fork 0

archive: add baselen member to struct archiver_args

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

René Scharfe committed Jul 15, 2008 at 09:49 UTC d53fe8187c38a5a160ef2199a899d9c47ec881b9
4 files changed +8 -10
archive-tar.c
+3 -5
@@ -268,19 +268,17 @@ static int write_tar_entry(const unsigned char *sha1, const char *base,
268
269 int write_tar_archive(struct archiver_args *args)
270 {
271 - int plen = args->base ? strlen(args->base) : 0;
272 -
271 git_config(git_tar_config, NULL);
272
273 archive_time = args->time;
274 verbose = args->verbose;
275 commit = args->commit;
278 - base_len = args->base ? strlen(args->base) : 0;
276 + base_len = args->baselen;
277
278 if (args->commit_sha1)
279 write_global_extended_header(args->commit_sha1);
280
283 - if (args->base && plen > 0 && args->base[plen - 1] == '/') {
281 + if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
282 char *base = xstrdup(args->base);
283 int baselen = strlen(base);
284
@@ -290,7 +288,7 @@ int write_tar_archive(struct archiver_args *args)
288 0, NULL);
289 free(base);
290 }
293 - read_tree_recursive(args->tree, args->base, plen, 0,
291 + read_tree_recursive(args->tree, args->base, args->baselen, 0,
292 args->pathspec, write_tar_entry, NULL);
293 write_trailer();
294
archive-zip.c
+3 -5
@@ -316,17 +316,15 @@ static void dos_time(time_t *time, int *dos_date, int *dos_time)
316
317 int write_zip_archive(struct archiver_args *args)
318 {
319 - int plen = strlen(args->base);
320 -
319 dos_time(&args->time, &zip_date, &zip_time);
320
321 zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
322 zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
323 verbose = args->verbose;
324 commit = args->commit;
327 - base_len = args->base ? strlen(args->base) : 0;
325 + base_len = args->baselen;
326
329 - if (args->base && plen > 0 && args->base[plen - 1] == '/') {
327 + if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
328 char *base = xstrdup(args->base);
329 int baselen = strlen(base);
330
@@ -336,7 +334,7 @@ int write_zip_archive(struct archiver_args *args)
334 0, NULL);
335 free(base);
336 }
339 - read_tree_recursive(args->tree, args->base, plen, 0,
337 + read_tree_recursive(args->tree, args->base, args->baselen, 0,
338 args->pathspec, write_zip_entry, NULL);
339 write_zip_trailer(args->commit_sha1);
340
archive.h
+1
@@ -6,6 +6,7 @@
6
7 struct archiver_args {
8 const char *base;
9 + size_t baselen;
10 struct tree *tree;
11 const unsigned char *commit_sha1;
12 const struct commit *commit;
builtin-archive.c
+1
@@ -192,6 +192,7 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
192 }
193 args->verbose = verbose;
194 args->base = base;
195 + args->baselen = strlen(base);
196
197 return i;
198 }