char *get_commit_graph_filename(const char *obj_dir)
{
- return xstrfmt("%s/info/commit-graph", obj_dir);
+ char *filename = xstrfmt("%s/info/commit-graph", obj_dir);
+ char *normalized = xmalloc(strlen(filename) + 1);
+ normalize_path_copy(normalized, filename);
+ free(filename);
+ return normalized;
}
static char *get_split_graph_filename(const char *obj_dir,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph",
- obj_dir,
- oid_hex);
+ char *filename = xstrfmt("%s/info/commit-graphs/graph-%s.graph",
+ obj_dir,
+ oid_hex);
+ char *normalized = xmalloc(strlen(filename) + 1);
+ normalize_path_copy(normalized, filename);
+ free(filename);
+ return normalized;
}
static char *get_chain_filename(const char *obj_dir)
hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
- if (verify_commit_graph_lite(graph))
+ if (verify_commit_graph_lite(graph)) {
+ free(graph);
return NULL;
+ }
return graph;
}
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
}
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+ c->maybe_tree = t;
+}
+
static int fill_commit_in_graph(struct repository *r,
struct commit *item,
struct commit_graph *g, uint32_t pos)
item->object.parsed = 1;
- item->maybe_tree = NULL;
+ set_commit_tree(item, NULL);
date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
date_low = get_be32(commit_data + g->hash_len + 12);
GRAPH_DATA_WIDTH * (c->graph_pos - g->num_commits_in_base);
hashcpy(oid.hash, commit_data);
- c->maybe_tree = lookup_tree(r, &oid);
+ set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
}
struct write_commit_graph_context {
struct repository *r;
- const char *obj_dir;
+ char *obj_dir;
char *graph_name;
struct packed_oid_list oids;
struct packed_commit_list commits;
if (ctx->split_opts && ctx->split_opts->expire_time)
expire_time -= ctx->split_opts->expire_time;
+ if (!ctx->split) {
+ char *chain_file_name = get_chain_filename(ctx->obj_dir);
+ unlink(chain_file_name);
+ free(chain_file_name);
+ ctx->num_commit_graphs_after = 0;
+ }
strbuf_addstr(&path, ctx->obj_dir);
strbuf_addstr(&path, "/info/commit-graphs");
if (!found)
unlink(path.buf);
-
}
}
{
struct write_commit_graph_context *ctx;
uint32_t i, count_distinct = 0;
+ size_t len;
int res = 0;
if (!commit_graph_compatible(the_repository))
ctx = xcalloc(1, sizeof(struct write_commit_graph_context));
ctx->r = the_repository;
- ctx->obj_dir = obj_dir;
+
+ /* normalize object dir with no trailing slash */
+ ctx->obj_dir = xmallocz(strlen(obj_dir) + 1);
+ normalize_path_copy(ctx->obj_dir, obj_dir);
+ len = strlen(ctx->obj_dir);
+ if (len && ctx->obj_dir[len - 1] == '/')
+ ctx->obj_dir[len - 1] = 0;
+
ctx->append = flags & COMMIT_GRAPH_APPEND ? 1 : 0;
ctx->report_progress = flags & COMMIT_GRAPH_PROGRESS ? 1 : 0;
ctx->split = flags & COMMIT_GRAPH_SPLIT ? 1 : 0;
res = write_commit_graph_file(ctx);
- if (ctx->split) {
+ if (ctx->split)
mark_commit_graphs(ctx);
- expire_commit_graphs(ctx);
- }
+
+ expire_commit_graphs(ctx);
cleanup:
free(ctx->graph_name);
free(ctx->commits.list);
free(ctx->oids.list);
+ free(ctx->obj_dir);
if (ctx->commit_graph_filenames_after) {
for (i = 0; i < ctx->num_commit_graphs_after; i++) {
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
graph_commit = lookup_commit(r, &cur_oid);
- odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r));
+ odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
if (parse_commit_internal(odb_commit, 0, 0)) {
graph_report(_("failed to parse commit %s from object database for commit-graph"),
oid_to_hex(&cur_oid));