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>
This commit is contained in:

committed by
Junio C Hamano

parent
671f070721
commit
d53fe8187c
@ -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 write_tar_archive(struct archiver_args *args)
|
||||||
{
|
{
|
||||||
int plen = args->base ? strlen(args->base) : 0;
|
|
||||||
|
|
||||||
git_config(git_tar_config, NULL);
|
git_config(git_tar_config, NULL);
|
||||||
|
|
||||||
archive_time = args->time;
|
archive_time = args->time;
|
||||||
verbose = args->verbose;
|
verbose = args->verbose;
|
||||||
commit = args->commit;
|
commit = args->commit;
|
||||||
base_len = args->base ? strlen(args->base) : 0;
|
base_len = args->baselen;
|
||||||
|
|
||||||
if (args->commit_sha1)
|
if (args->commit_sha1)
|
||||||
write_global_extended_header(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);
|
char *base = xstrdup(args->base);
|
||||||
int baselen = strlen(base);
|
int baselen = strlen(base);
|
||||||
|
|
||||||
@ -290,7 +288,7 @@ int write_tar_archive(struct archiver_args *args)
|
|||||||
0, NULL);
|
0, NULL);
|
||||||
free(base);
|
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);
|
args->pathspec, write_tar_entry, NULL);
|
||||||
write_trailer();
|
write_trailer();
|
||||||
|
|
||||||
|
@ -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 write_zip_archive(struct archiver_args *args)
|
||||||
{
|
{
|
||||||
int plen = strlen(args->base);
|
|
||||||
|
|
||||||
dos_time(&args->time, &zip_date, &zip_time);
|
dos_time(&args->time, &zip_date, &zip_time);
|
||||||
|
|
||||||
zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
|
zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
|
||||||
zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
|
zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
|
||||||
verbose = args->verbose;
|
verbose = args->verbose;
|
||||||
commit = args->commit;
|
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);
|
char *base = xstrdup(args->base);
|
||||||
int baselen = strlen(base);
|
int baselen = strlen(base);
|
||||||
|
|
||||||
@ -336,7 +334,7 @@ int write_zip_archive(struct archiver_args *args)
|
|||||||
0, NULL);
|
0, NULL);
|
||||||
free(base);
|
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);
|
args->pathspec, write_zip_entry, NULL);
|
||||||
write_zip_trailer(args->commit_sha1);
|
write_zip_trailer(args->commit_sha1);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
struct archiver_args {
|
struct archiver_args {
|
||||||
const char *base;
|
const char *base;
|
||||||
|
size_t baselen;
|
||||||
struct tree *tree;
|
struct tree *tree;
|
||||||
const unsigned char *commit_sha1;
|
const unsigned char *commit_sha1;
|
||||||
const struct commit *commit;
|
const struct commit *commit;
|
||||||
|
@ -192,6 +192,7 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
|
|||||||
}
|
}
|
||||||
args->verbose = verbose;
|
args->verbose = verbose;
|
||||||
args->base = base;
|
args->base = base;
|
||||||
|
args->baselen = strlen(base);
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user