should_pack_ref(): new function, extracted from `files_pack_refs()`
[gitweb.git] / builtin / bundle.c
index 92a8a6026a9bd6da5394e7b37f07dbe91f73db9c..d0de59b94ff23eebe03984dc670babf793bdd5ff 100644 (file)
@@ -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)
@@ -42,6 +36,10 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
 
        if (!strcmp(cmd, "verify")) {
                close(bundle_fd);
+               if (argc != 1) {
+                       usage(builtin_bundle_usage);
+                       return 1;
+               }
                if (verify_bundle(&header, 1))
                        return 1;
                fprintf(stderr, _("%s is okay\n"), bundle_file);
@@ -52,6 +50,10 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
                return !!list_bundle_refs(&header, argc, argv);
        }
        if (!strcmp(cmd, "create")) {
+               if (argc < 2) {
+                       usage(builtin_bundle_usage);
+                       return 1;
+               }
                if (!startup_info->have_repository)
                        die(_("Need a repository to create a bundle."));
                return !!create_bundle(&header, bundle_file, argc, argv);