@ -59,7 +59,7 @@ static int parse_options_cmd_bundle(int argc,
@@ -59,7 +59,7 @@ static int parse_options_cmd_bundle(int argc,
PARSE_OPT_STOP_AT_NON_OPTION);
if (!argc)
usage_msg_opt(_("need a <file> argument"), usagestr, options);
*bundle_file = prefix_filename(prefix, argv[0]);
*bundle_file = prefix_filename_except_for_dash(prefix, argv[0]);
return argc;
}
@ -108,6 +108,23 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
@@ -108,6 +108,23 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
return ret;
}
/*
* Similar to read_bundle_header(), but handle "-" as stdin.
*/
static int open_bundle(const char *path, struct bundle_header *header,
const char **name)
{
if (!strcmp(path, "-")) {
if (name)
*name = "<stdin>";
return read_bundle_header_fd(0, header, "<stdin>");
}
if (name)
*name = path;
return read_bundle_header(path, header);
}
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
struct bundle_header header = BUNDLE_HEADER_INIT;
int bundle_fd = -1;
@ -119,12 +136,13 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
@@ -119,12 +136,13 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
OPT_END()
};
char *bundle_file;
const char *name;
argc = parse_options_cmd_bundle(argc, argv, prefix,
builtin_bundle_verify_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) {
if ((bundle_fd = open_bundle(bundle_file, &header, &name)) < 0) {
ret = 1;
goto cleanup;
}
@ -135,7 +153,7 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
@@ -135,7 +153,7 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
goto cleanup;
}
fprintf(stderr, _("%s is okay\n"), bundle_file);
fprintf(stderr, _("%s is okay\n"), name);
ret = 0;
cleanup:
free(bundle_file);
@ -156,7 +174,7 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix
@@ -156,7 +174,7 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix
builtin_bundle_list_heads_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) {
if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) {
ret = 1;
goto cleanup;
}
@ -186,7 +204,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
@@ -186,7 +204,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
builtin_bundle_unbundle_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) {
if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) {
ret = 1;
goto cleanup;
}