]> git.ipfire.org Git - thirdparty/git.git/blobdiff - shallow.c
The 20th batch
[thirdparty/git.git] / shallow.c
index 7711798127e49efaa18b6403ecf103f05e92f7e7..dcebc263d704ce9cb2eb63047617b8b6e2c702a9 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "hex.h"
 #include "repository.h"
@@ -49,10 +51,12 @@ int unregister_shallow(const struct object_id *oid)
        int pos = commit_graft_pos(the_repository, oid);
        if (pos < 0)
                return -1;
-       if (pos + 1 < the_repository->parsed_objects->grafts_nr)
+       if (pos + 1 < the_repository->parsed_objects->grafts_nr) {
+               free(the_repository->parsed_objects->grafts[pos]);
                MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
                           the_repository->parsed_objects->grafts + pos + 1,
                           the_repository->parsed_objects->grafts_nr - pos - 1);
+       }
        the_repository->parsed_objects->grafts_nr--;
        return 0;
 }
@@ -95,7 +99,7 @@ static void reset_repository_shallow(struct repository *r)
 {
        r->parsed_objects->is_shallow = -1;
        stat_validity_clear(r->parsed_objects->shallow_stat);
-       reset_commit_grafts(r);
+       parsed_object_pool_reset_commit_grafts(r->parsed_objects);
 }
 
 int commit_shallow_file(struct repository *r, struct shallow_lock *lk)
@@ -485,6 +489,15 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
 
 void clear_shallow_info(struct shallow_info *info)
 {
+       if (info->used_shallow) {
+               for (size_t i = 0; i < info->shallow->nr; i++)
+                       free(info->used_shallow[i]);
+               free(info->used_shallow);
+       }
+
+       free(info->need_reachability_test);
+       free(info->reachable);
+       free(info->shallow_ref);
        free(info->ours);
        free(info->theirs);
 }
@@ -610,6 +623,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
 }
 
 static int mark_uninteresting(const char *refname UNUSED,
+                             const char *referent UNUSED,
                              const struct object_id *oid,
                              int flags UNUSED,
                              void *cb_data UNUSED)
@@ -678,8 +692,10 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
         * connect to old refs. If not (e.g. force ref updates) it'll
         * have to go down to the current shallow commits.
         */
-       head_ref(mark_uninteresting, NULL);
-       for_each_ref(mark_uninteresting, NULL);
+       refs_head_ref(get_main_ref_store(the_repository), mark_uninteresting,
+                     NULL);
+       refs_for_each_ref(get_main_ref_store(the_repository),
+                         mark_uninteresting, NULL);
 
        /* Mark potential bottoms so we won't go out of bound */
        for (i = 0; i < nr_shallow; i++) {
@@ -723,6 +739,7 @@ struct commit_array {
 };
 
 static int add_ref(const char *refname UNUSED,
+                 const char *referent UNUSED,
                   const struct object_id *oid,
                   int flags UNUSED,
                   void *cb_data)
@@ -782,8 +799,8 @@ static void post_assign_shallow(struct shallow_info *info,
        info->nr_theirs = dst;
 
        memset(&ca, 0, sizeof(ca));
-       head_ref(add_ref, &ca);
-       for_each_ref(add_ref, &ca);
+       refs_head_ref(get_main_ref_store(the_repository), add_ref, &ca);
+       refs_for_each_ref(get_main_ref_store(the_repository), add_ref, &ca);
 
        /* Remove unreachable shallow commits from "ours" */
        for (i = dst = 0; i < info->nr_ours; i++) {
@@ -794,12 +811,16 @@ static void post_assign_shallow(struct shallow_info *info,
                if (!*bitmap)
                        continue;
                for (j = 0; j < bitmap_nr; j++)
-                       if (bitmap[0][j] &&
-                           /* Step 7, reachability test at commit level */
-                           !repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits)) {
-                               update_refstatus(ref_status, info->ref->nr, *bitmap);
-                               dst++;
-                               break;
+                       if (bitmap[0][j]) {
+                               /* Step 7, reachability test at commit level */
+                               int ret = repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1);
+                               if (ret < 0)
+                                       exit(128);
+                               if (!ret) {
+                                       update_refstatus(ref_status, info->ref->nr, *bitmap);
+                                       dst++;
+                                       break;
+                               }
                        }
        }
        info->nr_ours = dst;
@@ -818,8 +839,10 @@ int delayed_reachability_test(struct shallow_info *si, int c)
                        struct commit_array ca;
 
                        memset(&ca, 0, sizeof(ca));
-                       head_ref(add_ref, &ca);
-                       for_each_ref(add_ref, &ca);
+                       refs_head_ref(get_main_ref_store(the_repository),
+                                     add_ref, &ca);
+                       refs_for_each_ref(get_main_ref_store(the_repository),
+                                         add_ref, &ca);
                        si->commits = ca.commits;
                        si->nr_commits = ca.nr;
                }
@@ -827,7 +850,10 @@ int delayed_reachability_test(struct shallow_info *si, int c)
                si->reachable[c] = repo_in_merge_bases_many(the_repository,
                                                            commit,
                                                            si->nr_commits,
-                                                           si->commits);
+                                                           si->commits,
+                                                           1);
+               if (si->reachable[c] < 0)
+                       exit(128);
                si->need_reachability_test[c] = 0;
        }
        return si->reachable[c];