]> git.ipfire.org Git - thirdparty/git.git/blobdiff - fetch-pack.c
fetch-pack: clear marks before re-marking
[thirdparty/git.git] / fetch-pack.c
index 490c38f833419cde65b97f75f454a7d148fff6a2..2812499a5eca5c7718a5d651ee678e58898cda97 100644 (file)
@@ -336,9 +336,6 @@ static int find_common(struct fetch_pack_args *args,
 
        if (args->stateless_rpc && multi_ack == 1)
                die(_("--stateless-rpc requires multi_ack_detailed"));
-       if (marked)
-               for_each_ref(clear_marks, NULL);
-       marked = 1;
 
        for_each_ref(rev_list_insert_ref_oid, NULL);
        for_each_cached_alternate(insert_one_alternate_object);
@@ -734,12 +731,20 @@ static int add_loose_objects_to_set(const struct object_id *oid,
        return 0;
 }
 
-static int everything_local(struct fetch_pack_args *args,
-                           struct ref **refs,
-                           struct ref **sought, int nr_sought)
+/*
+ * Mark recent commits available locally and reachable from a local ref as
+ * COMPLETE. If args->no_dependents is false, also mark COMPLETE remote refs as
+ * COMMON_REF (otherwise, we are not planning to participate in negotiation, and
+ * thus do not need COMMON_REF marks).
+ *
+ * The cutoff time for recency is determined by this heuristic: it is the
+ * earliest commit time of the objects in refs that are commits and that we know
+ * the commit time of.
+ */
+static void mark_complete_and_common_ref(struct fetch_pack_args *args,
+                                        struct ref **refs)
 {
        struct ref *ref;
-       int retval;
        int old_save_commit_buffer = save_commit_buffer;
        timestamp_t cutoff = 0;
        struct oidset loose_oid_set = OIDSET_INIT;
@@ -812,7 +817,18 @@ static int everything_local(struct fetch_pack_args *args,
                }
        }
 
-       filter_refs(args, refs, sought, nr_sought);
+       save_commit_buffer = old_save_commit_buffer;
+}
+
+/*
+ * Returns 1 if every object pointed to by the given remote refs is available
+ * locally and reachable from a local ref, and 0 otherwise.
+ */
+static int everything_local(struct fetch_pack_args *args,
+                           struct ref **refs)
+{
+       struct ref *ref;
+       int retval;
 
        for (retval = 1, ref = *refs; ref ; ref = ref->next) {
                const struct object_id *remote = &ref->old_oid;
@@ -829,8 +845,6 @@ static int everything_local(struct fetch_pack_args *args,
                              ref->name);
        }
 
-       save_commit_buffer = old_save_commit_buffer;
-
        return retval;
 }
 
@@ -1053,7 +1067,12 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        if (!server_supports("deepen-relative") && args->deepen_relative)
                die(_("Server does not support --deepen"));
 
-       if (everything_local(args, &ref, sought, nr_sought)) {
+       if (marked)
+               for_each_ref(clear_marks, NULL);
+       marked = 1;
+       mark_complete_and_common_ref(args, &ref);
+       filter_refs(args, &ref, sought, nr_sought);
+       if (everything_local(args, &ref)) {
                packet_flush(fd[1]);
                goto all_done;
        }
@@ -1198,14 +1217,29 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
        else if (is_repository_shallow() || args->deepen)
                die(_("Server does not support shallow requests"));
 
+       /* Add filter */
+       if (server_supports_feature("fetch", "filter", 0) &&
+           args->filter_options.choice) {
+               print_verbose(args, _("Server supports filter"));
+               packet_buf_write(&req_buf, "filter %s",
+                                args->filter_options.filter_spec);
+       } else if (args->filter_options.choice) {
+               warning("filtering not recognized by server, ignoring");
+       }
+
        /* add wants */
        add_wants(wants, &req_buf);
 
-       /* Add all of the common commits we've found in previous rounds */
-       add_common(&req_buf, common);
+       if (args->no_dependents) {
+               packet_buf_write(&req_buf, "done");
+               ret = 1;
+       } else {
+               /* Add all of the common commits we've found in previous rounds */
+               add_common(&req_buf, common);
 
-       /* Add initial haves */
-       ret = add_haves(&req_buf, haves_to_send, in_vain);
+               /* Add initial haves */
+               ret = add_haves(&req_buf, haves_to_send, in_vain);
+       }
 
        /* Send request */
        packet_buf_flush(&req_buf);
@@ -1362,7 +1396,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                        for_each_cached_alternate(insert_one_alternate_object);
 
                        /* Filter 'ref' by 'sought' and those that aren't local */
-                       if (everything_local(args, &ref, sought, nr_sought))
+                       mark_complete_and_common_ref(args, &ref);
+                       filter_refs(args, &ref, sought, nr_sought);
+                       if (everything_local(args, &ref))
                                state = FETCH_DONE;
                        else
                                state = FETCH_SEND_REQUEST;