* This is a common internal function that can either return a list of * shallow commits or calculate the current maximum depth of a shallow * repository, depending on the input parameters. * * Depth calculation is triggered by passing the `shallows` parameter. * In this case, the computed depth is stored in `max_cur_depth` (if it is * provided), and the function returns NULL. * * Otherwise
| 143 | * a list of shallow commits. |
| 144 | */ |
| 145 | static struct commit_list *get_shallows_or_depth(struct object_array *heads, |
| 146 | struct object_array *shallows, int *max_cur_depth, |
| 147 | int depth, int shallow_flag, int not_shallow_flag) |
| 148 | { |
| 149 | size_t i = 0; |
| 150 | int cur_depth = 0, cur_depth_shallow = 0; |
| 151 | struct commit_list *result = NULL; |
| 152 | struct object_array stack = OBJECT_ARRAY_INIT; |
| 153 | struct commit *commit = NULL; |
| 154 | struct commit_graft *graft; |
| 155 | struct commit_depth depths; |
| 156 | |
| 157 | init_commit_depth(&depths); |
| 158 | while (commit || i < heads->nr || stack.nr) { |
| 159 | struct commit_list *p; |
| 160 | if (!commit) { |
| 161 | if (i < heads->nr) { |
| 162 | int **depth_slot; |
| 163 | commit = (struct commit *) |
| 164 | deref_tag(the_repository, |
| 165 | heads->objects[i++].item, |
| 166 | NULL, 0); |
| 167 | if (!commit || commit->object.type != OBJ_COMMIT) { |
| 168 | commit = NULL; |
| 169 | continue; |
| 170 | } |
| 171 | depth_slot = commit_depth_at(&depths, commit); |
| 172 | if (!*depth_slot) |
| 173 | *depth_slot = xmalloc(sizeof(int)); |
| 174 | **depth_slot = 0; |
| 175 | cur_depth = 0; |
| 176 | } else { |
| 177 | commit = (struct commit *) |
| 178 | object_array_pop(&stack); |
| 179 | cur_depth = **commit_depth_at(&depths, commit); |
| 180 | } |
| 181 | } |
| 182 | parse_commit_or_die(commit); |
| 183 | cur_depth++; |
| 184 | if (shallows) { |
| 185 | for (size_t j = 0; j < shallows->nr; j++) |
| 186 | if (oideq(&commit->object.oid, &shallows->objects[j].item->oid)) |
| 187 | if (!cur_depth_shallow || cur_depth < cur_depth_shallow) |
| 188 | cur_depth_shallow = cur_depth; |
| 189 | |
| 190 | if ((is_repository_shallow(the_repository) && !commit->parents && |
| 191 | (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL && |
| 192 | graft->nr_parent < 0)) { |
| 193 | commit = NULL; |
| 194 | continue; |
| 195 | } |
| 196 | } else { |
| 197 | if ((depth != INFINITE_DEPTH && cur_depth >= depth) || |
| 198 | (is_repository_shallow(the_repository) && !commit->parents && |
| 199 | (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL && |
| 200 | graft->nr_parent < 0)) { |
| 201 | commit_list_insert(commit, &result); |
| 202 | commit->object.flags |= shallow_flag; |
no test coverage detected