]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bundle: add flags to verify_bundle()
authorDerrick Stolee <derrickstolee@github.com>
Wed, 12 Oct 2022 12:52:37 +0000 (12:52 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Oct 2022 16:13:25 +0000 (09:13 -0700)
The verify_bundle() method has a 'verbose' option, but we will want to
extend this method to have more granular control over its output. First,
replace this 'verbose' option with a new 'flags' option with a single
possible value: VERIFY_BUNDLE_VERBOSE.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/bundle.c
bundle-uri.c
bundle.c
bundle.h
transport.c

index 2adad545a2e972221869703658e98be0c514d005..7d983a238f0bad6c5a336be7fca4c4166023cadf 100644 (file)
@@ -119,7 +119,8 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
                goto cleanup;
        }
        close(bundle_fd);
-       if (verify_bundle(the_repository, &header, !quiet)) {
+       if (verify_bundle(the_repository, &header,
+                         quiet ? 0 : VERIFY_BUNDLE_VERBOSE)) {
                ret = 1;
                goto cleanup;
        }
@@ -185,7 +186,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
                strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
                             _("Unbundling objects"), NULL);
        ret = !!unbundle(the_repository, &header, bundle_fd,
-                        &extra_index_pack_args) ||
+                        &extra_index_pack_args, 0) ||
                list_bundle_refs(&header, argc, argv);
        bundle_header_release(&header);
 cleanup:
index 70bfd2defeed41d4defb7422e445f4af379854e5..d9060be707e3a1e279d27d3c108d72dd5b938ba1 100644 (file)
@@ -303,7 +303,12 @@ static int unbundle_from_file(struct repository *r, const char *file)
        if ((bundle_fd = read_bundle_header(file, &header)) < 0)
                return 1;
 
-       if ((result = unbundle(r, &header, bundle_fd, NULL)))
+       /*
+        * Skip the reachability walk here, since we will be adding
+        * a reachable ref pointing to the new tips, which will reach
+        * the prerequisite commits.
+        */
+       if ((result = unbundle(r, &header, bundle_fd, NULL, 0)))
                return 1;
 
        /*
index c277f3b93608db433eb23028d25fc47f73d0b496..1f6a7f782e163d9cc79ad90e1583e11bf87c47a0 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -189,7 +189,7 @@ static int list_refs(struct string_list *r, int argc, const char **argv)
 
 int verify_bundle(struct repository *r,
                  struct bundle_header *header,
-                 int verbose)
+                 enum verify_bundle_flags flags)
 {
        /*
         * Do fast check, then if any prereqs are missing then go line by line
@@ -248,7 +248,7 @@ int verify_bundle(struct repository *r,
                error("%s %s", oid_to_hex(oid), name);
        }
 
-       if (verbose) {
+       if (flags & VERIFY_BUNDLE_VERBOSE) {
                struct string_list *r;
 
                r = &header->references;
@@ -617,7 +617,8 @@ err:
 }
 
 int unbundle(struct repository *r, struct bundle_header *header,
-            int bundle_fd, struct strvec *extra_index_pack_args)
+            int bundle_fd, struct strvec *extra_index_pack_args,
+            enum verify_bundle_flags flags)
 {
        struct child_process ip = CHILD_PROCESS_INIT;
        strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
@@ -631,7 +632,7 @@ int unbundle(struct repository *r, struct bundle_header *header,
                strvec_clear(extra_index_pack_args);
        }
 
-       if (verify_bundle(r, header, 0))
+       if (verify_bundle(r, header, flags))
                return -1;
        ip.in = bundle_fd;
        ip.no_stdout = 1;
index 0c052f54964f110688c6b2edf02f4c7dfca8a623..6652e81998162bbe50e0282fbf8a05f06cd5ff84 100644 (file)
--- a/bundle.h
+++ b/bundle.h
@@ -29,7 +29,13 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
 int create_bundle(struct repository *r, const char *path,
                  int argc, const char **argv, struct strvec *pack_options,
                  int version);
-int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
+
+enum verify_bundle_flags {
+       VERIFY_BUNDLE_VERBOSE = (1 << 0),
+};
+
+int verify_bundle(struct repository *r, struct bundle_header *header,
+                 enum verify_bundle_flags flags);
 
 /**
  * Unbundle after reading the header with read_bundle_header().
@@ -40,9 +46,13 @@ int verify_bundle(struct repository *r, struct bundle_header *header, int verbos
  * Provide "extra_index_pack_args" to pass any extra arguments
  * (e.g. "-v" for verbose/progress), NULL otherwise. The provided
  * "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
+ *
+ * Before unbundling, this method will call verify_bundle() with the
+ * given 'flags'.
  */
 int unbundle(struct repository *r, struct bundle_header *header,
-            int bundle_fd, struct strvec *extra_index_pack_args);
+            int bundle_fd, struct strvec *extra_index_pack_args,
+            enum verify_bundle_flags flags);
 int list_bundle_refs(struct bundle_header *header,
                int argc, const char **argv);
 
index b51e991e4439467c3cb2fc15381c259e135f5139..de4d88687ca5da7455b4ce2170f19f55b4d81d3f 100644 (file)
@@ -178,7 +178,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
        if (!data->get_refs_from_bundle_called)
                get_refs_from_bundle_inner(transport);
        ret = unbundle(the_repository, &data->header, data->fd,
-                      &extra_index_pack_args);
+                      &extra_index_pack_args, 0);
        transport->hash_algo = data->header.hash_algo;
        return ret;
 }