1136
stop_progress(&ctx->progress);
1137
}
1138
1139
-static int add_ref_to_list(const char *refname,
1140
- const struct object_id *oid,
1141
- int flags, void *cb_data)
1139
+static int add_ref_to_set(const char *refname,
1140
+ const struct object_id *oid,
1141
+ int flags, void *cb_data)
1142
{
1143
- struct string_list *list = (struct string_list *)cb_data;
1143
+ struct oidset *commits = (struct oidset *)cb_data;
1144
1145
- string_list_append(list, oid_to_hex(oid));
1145
+ oidset_insert(commits, oid);
1146
return 0;
1147
}
1148
1150
enum commit_graph_write_flags flags,
1151
const struct split_commit_graph_opts *split_opts)
1152
{
1153
- struct string_list list = STRING_LIST_INIT_DUP;
1153
+ struct oidset commits = OIDSET_INIT;
1154
int result;
1155
1156
- for_each_ref(add_ref_to_list, &list);
1157
- result = write_commit_graph(odb, NULL, &list,
1156
+ for_each_ref(add_ref_to_set, &commits);
1157
+ result = write_commit_graph(odb, NULL, &commits,
1158
flags, split_opts);
1159
1160
- string_list_clear(&list, 0);
1160
+ oidset_clear(&commits);
1161
return result;
1162
}
1163
1206
return 0;
1207
}
1208
1209
-static int fill_oids_from_commit_hex(struct write_commit_graph_context *ctx,
1210
- struct string_list *commit_hex)
1209
+static int fill_oids_from_commits(struct write_commit_graph_context *ctx,
1210
+ struct oidset *commits)
1211
{
1212
- uint32_t i;
1212
+ uint32_t i = 0;
1213
struct strbuf progress_title = STRBUF_INIT;
1214
+ struct oidset_iter iter;
1215
+ struct object_id *oid;
1216
+
1217
+ if (!oidset_size(commits))
1218
+ return 0;
1219
1220
if (ctx->report_progress) {
1221
strbuf_addf(&progress_title,
1222
Q_("Finding commits for commit graph from %d ref",
1223
"Finding commits for commit graph from %d refs",
1219
- commit_hex->nr),
1220
- commit_hex->nr);
1224
+ oidset_size(commits)),
1225
+ oidset_size(commits));
1226
ctx->progress = start_delayed_progress(
1227
progress_title.buf,
1223
- commit_hex->nr);
1228
+ oidset_size(commits));
1229
}
1225
- for (i = 0; i < commit_hex->nr; i++) {
1226
- const char *end;
1227
- struct object_id oid;
1230
+
1231
+ oidset_iter_init(commits, &iter);
1232
+ while ((oid = oidset_iter_next(&iter))) {
1233
struct commit *result;
1234
1230
- display_progress(ctx->progress, i + 1);
1231
- if (!parse_oid_hex(commit_hex->items[i].string, &oid, &end) &&
1232
- (result = lookup_commit_reference_gently(ctx->r, &oid, 1))) {
1235
+ display_progress(ctx->progress, ++i);
1236
+
1237
+ result = lookup_commit_reference_gently(ctx->r, oid, 1);
1238
+ if (result) {
1239
ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
1240
oidcpy(&ctx->oids.list[ctx->oids.nr], &(result->object.oid));
1241
ctx->oids.nr++;
1242
} else if (ctx->check_oids) {
1243
error(_("invalid commit object id: %s"),
1238
- commit_hex->items[i].string);
1244
+ oid_to_hex(oid));
1245
return -1;
1246
}
1247
}
1248
+
1249
stop_progress(&ctx->progress);
1250
strbuf_release(&progress_title);
1251
1792
1793
int write_commit_graph(struct object_directory *odb,
1794
struct string_list *pack_indexes,
1788
- struct string_list *commit_hex,
1795
+ struct oidset *commits,
1796
enum commit_graph_write_flags flags,
1797
const struct split_commit_graph_opts *split_opts)
1798
{
1868
goto cleanup;
1869
}
1870
1864
- if (commit_hex) {
1865
- if ((res = fill_oids_from_commit_hex(ctx, commit_hex)))
1871
+ if (commits) {
1872
+ if ((res = fill_oids_from_commits(ctx, commits)))
1873
goto cleanup;
1874
}
1875
1869
- if (!pack_indexes && !commit_hex)
1876
+ if (!pack_indexes && !commits)
1877
fill_oids_from_all_packs(ctx);
1878
1879
close_reachable(ctx);