Skip to content

Commit 3b754ee

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af10e8b commit 3b754ee

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

builtin/bundle.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,15 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
2020
struct bundle_header header;
2121
const char *cmd, *bundle_file;
2222
int bundle_fd = -1;
23-
char buffer[PATH_MAX];
2423

2524
if (argc < 3)
2625
usage(builtin_bundle_usage);
2726

2827
cmd = argv[1];
29-
bundle_file = argv[2];
28+
bundle_file = prefix_filename(prefix, argv[2]);
3029
argc -= 2;
3130
argv += 2;
3231

33-
if (prefix && bundle_file[0] != '/') {
34-
snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
35-
bundle_file = buffer;
36-
}
37-
3832
memset(&header, 0, sizeof(header));
3933
if (strcmp(cmd, "create") && (bundle_fd =
4034
read_bundle_header(bundle_file, &header)) < 0)

0 commit comments

Comments
 (0)