diff options
author | Jeff King <peff@peff.net> | 2017-03-20 21:31:27 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-03-21 11:18:41 -0700 |
commit | 3b754eedd58636926d07b14a34799a3aa7b8ebc2 (patch) | |
tree | 4019a9f90e18676fe1cf6f1df37f8b67df0e5754 /builtin/bundle.c | |
parent | prefix_filename: simplify windows #ifdef (diff) | |
download | tgif-3b754eedd58636926d07b14a34799a3aa7b8ebc2.tar.xz |
bundle: use prefix_filename with bundle path
We may take the path to a bundle file as an argument, and
need to adjust the filename based on the prefix we
discovered while setting up the git directory. We do so
manually into a fixed-size buffer, but using
prefix_filename() is the normal way.
Besides being more concise, there are two subtle
improvements:
1. The original inserted a "/" between the two paths, even
though the "prefix" argument always has the "/"
appended. That means that:
cd subdir && git bundle verify ../foo.bundle
was looking at (and reporting) subdir//../foo.bundle.
Harmless, but ugly. Using prefix_filename() gets this
right.
2. The original checked for an absolute path by looking
for a leading '/'. It should have been using
is_absolute_path(), which also covers more cases on
Windows (backslashes and dos drive prefixes).
But it's easier still to just pass the name to
prefix_filename(), which handles this case
automatically.
Note that we'll just leak the resulting buffer in the name
of simplicity, since it needs to last through the duration
of the program anyway.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/bundle.c')
-rw-r--r-- | builtin/bundle.c | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/builtin/bundle.c b/builtin/bundle.c index 4883a435a9..d0de59b94f 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -20,21 +20,15 @@ int cmd_bundle(int argc, const char **argv, const char *prefix) struct bundle_header header; const char *cmd, *bundle_file; int bundle_fd = -1; - char buffer[PATH_MAX]; if (argc < 3) usage(builtin_bundle_usage); cmd = argv[1]; - bundle_file = argv[2]; + bundle_file = prefix_filename(prefix, argv[2]); argc -= 2; argv += 2; - if (prefix && bundle_file[0] != '/') { - snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file); - bundle_file = buffer; - } - memset(&header, 0, sizeof(header)); if (strcmp(cmd, "create") && (bundle_fd = read_bundle_header(bundle_file, &header)) < 0) |