723
o->commit_graph = NULL;
724
}
725
726
-static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
726
+static int bsearch_graph(struct commit_graph *g, const struct object_id *oid, uint32_t *pos)
727
{
728
return bsearch_hash(oid->hash, g->chunk_oid_fanout,
729
g->chunk_oid_lookup, g->hash_len, pos);
864
return 1;
865
}
866
867
-static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos)
867
+static int search_commit_pos_in_graph(const struct object_id *id, struct commit_graph *g, uint32_t *pos)
868
+{
869
+ struct commit_graph *cur_g = g;
870
+ uint32_t lex_index;
871
+
872
+ while (cur_g && !bsearch_graph(cur_g, id, &lex_index))
873
+ cur_g = cur_g->base_graph;
874
+
875
+ if (cur_g) {
876
+ *pos = lex_index + cur_g->num_commits_in_base;
877
+ return 1;
878
+ }
879
+
880
+ return 0;
881
+}
882
+
883
+static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos)
884
{
885
uint32_t graph_pos = commit_graph_position(item);
886
if (graph_pos != COMMIT_NOT_FROM_GRAPH) {
887
*pos = graph_pos;
888
return 1;
889
} else {
874
- struct commit_graph *cur_g = g;
875
- uint32_t lex_index;
876
-
877
- while (cur_g && !bsearch_graph(cur_g, &(item->object.oid), &lex_index))
878
- cur_g = cur_g->base_graph;
879
-
880
- if (cur_g) {
881
- *pos = lex_index + cur_g->num_commits_in_base;
882
- return 1;
883
- }
884
-
885
- return 0;
890
+ return search_commit_pos_in_graph(&item->object.oid, g, pos);
891
}
892
}
893
900
if (item->object.parsed)
901
return 1;
902
898
- if (find_commit_in_graph(item, g, &pos))
903
+ if (find_commit_pos_in_graph(item, g, &pos))
904
return fill_commit_in_graph(r, item, g, pos);
905
906
return 0;
926
uint32_t pos;
927
if (!prepare_commit_graph(r))
928
return;
924
- if (find_commit_in_graph(item, r->objects->commit_graph, &pos))
929
+ if (find_commit_pos_in_graph(item, r->objects->commit_graph, &pos))
930
fill_commit_graph_info(item, r->objects->commit_graph, pos);
931
}
932
1096
edge_value += ctx->new_num_commits_in_base;
1097
else if (ctx->new_base_graph) {
1098
uint32_t pos;
1094
- if (find_commit_in_graph(parent->item,
1095
- ctx->new_base_graph,
1096
- &pos))
1099
+ if (find_commit_pos_in_graph(parent->item,
1100
+ ctx->new_base_graph,
1101
+ &pos))
1102
edge_value = pos;
1103
}
1104
1127
edge_value += ctx->new_num_commits_in_base;
1128
else if (ctx->new_base_graph) {
1129
uint32_t pos;
1125
- if (find_commit_in_graph(parent->item,
1126
- ctx->new_base_graph,
1127
- &pos))
1130
+ if (find_commit_pos_in_graph(parent->item,
1131
+ ctx->new_base_graph,
1132
+ &pos))
1133
edge_value = pos;
1134
}
1135
1240
edge_value += ctx->new_num_commits_in_base;
1241
else if (ctx->new_base_graph) {
1242
uint32_t pos;
1238
- if (find_commit_in_graph(parent->item,
1239
- ctx->new_base_graph,
1240
- &pos))
1243
+ if (find_commit_pos_in_graph(parent->item,
1244
+ ctx->new_base_graph,
1245
+ &pos))
1246
edge_value = pos;
1247
}
1248