MCPcopy Create free account
hub / github.com/git/git / dfs_on_ref

Function dfs_on_ref

builtin/gc.c:1104–1159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1102};
1103
1104static int dfs_on_ref(const struct reference *ref, void *cb_data)
1105{
1106 struct cg_auto_data *data = (struct cg_auto_data *)cb_data;
1107 int result = 0;
1108 const struct object_id *maybe_peeled = ref->oid;
1109 struct object_id peeled;
1110 struct commit_list *stack = NULL;
1111 struct commit *commit;
1112
1113 if (!reference_get_peeled_oid(the_repository, ref, &peeled))
1114 maybe_peeled = &peeled;
1115 if (odb_read_object_info(the_repository->objects, maybe_peeled, NULL) != OBJ_COMMIT)
1116 return 0;
1117
1118 commit = lookup_commit(the_repository, maybe_peeled);
1119 if (!commit || commit->object.flags & SEEN)
1120 return 0;
1121 commit->object.flags |= SEEN;
1122
1123 if (repo_parse_commit(the_repository, commit) ||
1124 commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
1125 return 0;
1126
1127 data->num_not_in_graph++;
1128
1129 if (data->num_not_in_graph >= data->limit)
1130 return 1;
1131
1132 commit_list_insert(commit, &stack);
1133
1134 while (!result && stack) {
1135 struct commit_list *parent;
1136
1137 commit = pop_commit(&stack);
1138
1139 for (parent = commit->parents; parent; parent = parent->next) {
1140 if (repo_parse_commit(the_repository, parent->item) ||
1141 commit_graph_position(parent->item) != COMMIT_NOT_FROM_GRAPH ||
1142 parent->item->object.flags & SEEN)
1143 continue;
1144
1145 parent->item->object.flags |= SEEN;
1146 data->num_not_in_graph++;
1147
1148 if (data->num_not_in_graph >= data->limit) {
1149 result = 1;
1150 break;
1151 }
1152
1153 commit_list_insert(parent->item, &stack);
1154 }
1155 }
1156
1157 commit_list_free(stack);
1158 return result;
1159}
1160
1161static int should_write_commit_graph(struct gc_config *cfg UNUSED)

Callers

nothing calls this directly

Calls 8

reference_get_peeled_oidFunction · 0.85
odb_read_object_infoFunction · 0.85
lookup_commitFunction · 0.85
repo_parse_commitFunction · 0.85
commit_graph_positionFunction · 0.85
commit_list_insertFunction · 0.85
pop_commitFunction · 0.85
commit_list_freeFunction · 0.85

Tested by

no test coverage detected