17
#include "replace-object.h"
18
#include "progress.h"
19
#include "bloom.h"
20
+#include "commit-slab.h"
21
22
#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
23
#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
47
/* Remember to update object flag allocation in object.h */
48
#define REACHABLE (1u<<15)
49
49
-char *get_commit_graph_filename(struct object_directory *odb)
50
+/* Keep track of the order in which commits are added to our list. */
51
+define_commit_slab(commit_pos, int);
52
+static struct commit_pos commit_pos = COMMIT_SLAB_INIT(1, commit_pos);
53
+
54
+static void set_commit_pos(struct repository *r, const struct object_id *oid)
55
+{
56
+ static int32_t max_pos;
57
+ struct commit *commit = lookup_commit(r, oid);
58
+
59
+ if (!commit)
60
+ return; /* should never happen, but be lenient */
61
+
62
+ *commit_pos_at(&commit_pos, commit) = max_pos++;
63
+}
64
+
65
+static int commit_pos_cmp(const void *va, const void *vb)
66
{
51
- return xstrfmt("%s/info/commit-graph", odb->path);
67
+ const struct commit *a = *(const struct commit **)va;
68
+ const struct commit *b = *(const struct commit **)vb;
69
+ return commit_pos_at(&commit_pos, a) -
70
+ commit_pos_at(&commit_pos, b);
71
+}
72
+
73
+char *get_commit_graph_filename(struct object_directory *obj_dir)
74
+{
75
+ return xstrfmt("%s/info/commit-graph", obj_dir->path);
76
}
77
78
static char *get_split_graph_filename(struct object_directory *odb,
1045
oidcpy(&(ctx->oids.list[ctx->oids.nr]), oid);
1046
ctx->oids.nr++;
1047
1048
+ set_commit_pos(ctx->r, oid);
1049
+
1050
return 0;
1051
}
1052
1167
{
1168
int i;
1169
struct progress *progress = NULL;
1170
+ struct commit **sorted_commits;
1171
1172
init_bloom_filters();
1173
1176
_("Computing commit changed paths Bloom filters"),
1177
ctx->commits.nr);
1178
1179
+ ALLOC_ARRAY(sorted_commits, ctx->commits.nr);
1180
+ COPY_ARRAY(sorted_commits, ctx->commits.list, ctx->commits.nr);
1181
+ QSORT(sorted_commits, ctx->commits.nr, commit_pos_cmp);
1182
+
1183
for (i = 0; i < ctx->commits.nr; i++) {
1153
- struct commit *c = ctx->commits.list[i];
1184
+ struct commit *c = sorted_commits[i];
1185
struct bloom_filter *filter = get_bloom_filter(ctx->r, c);
1186
ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
1187
display_progress(progress, i + 1);
1188
}
1189
1190
+ free(sorted_commits);
1191
stop_progress(&progress);
1192
}
1193