summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commit-graph.c30
-rwxr-xr-xt/t5324-split-commit-graph.sh7
2 files changed, 29 insertions, 8 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 3599ae664d..c91e6f0fb8 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -43,15 +43,23 @@
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)
@@ -746,7 +754,7 @@ struct packed_oid_list {
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;
@@ -1729,7 +1737,6 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (!found)
unlink(path.buf);
-
}
}
@@ -1741,6 +1748,7 @@ int write_commit_graph(const char *obj_dir,
{
struct write_commit_graph_context *ctx;
uint32_t i, count_distinct = 0;
+ size_t len;
int res = 0;
if (!commit_graph_compatible(the_repository))
@@ -1748,7 +1756,14 @@ int write_commit_graph(const char *obj_dir,
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;
@@ -1856,6 +1871,7 @@ 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++) {
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 130f2baf44..fc0d00751c 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -163,7 +163,12 @@ test_expect_success 'create fork and chain across alternate' '
test_line_count = 1 graph-files &&
git -c core.commitGraph=true rev-list HEAD >expect &&
git -c core.commitGraph=false rev-list HEAD >actual &&
- test_cmp expect actual
+ test_cmp expect actual &&
+ test_commit 14 &&
+ git commit-graph write --reachable --split --object-dir=.git/objects/ &&
+ test_line_count = 3 $graphdir/commit-graph-chain &&
+ ls $graphdir/graph-*.graph >graph-files &&
+ test_line_count = 1 graph-files
)
'