Skip to content

Commit 8496a9d

Browse files
committed
Merge branch 'ds/commit-graph-incremental' into pu
The commits in a repository can be described by multiple commit-graph files now, which allows the commit-graph files to be updated incrementally. * ds/commit-graph-incremental: commit-graph: normalize commit-graph filenames
2 parents 8b0e68d + 9c87c79 commit 8496a9d

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

commit-graph.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@
4343

4444
char *get_commit_graph_filename(const char *obj_dir)
4545
{
46-
return xstrfmt("%s/info/commit-graph", obj_dir);
46+
char *filename = xstrfmt("%s/info/commit-graph", obj_dir);
47+
char *normalized = xmalloc(strlen(filename) + 1);
48+
normalize_path_copy(normalized, filename);
49+
free(filename);
50+
return normalized;
4751
}
4852

4953
static char *get_split_graph_filename(const char *obj_dir,
5054
const char *oid_hex)
5155
{
52-
return xstrfmt("%s/info/commit-graphs/graph-%s.graph",
53-
obj_dir,
54-
oid_hex);
56+
char *filename = xstrfmt("%s/info/commit-graphs/graph-%s.graph",
57+
obj_dir,
58+
oid_hex);
59+
char *normalized = xmalloc(strlen(filename) + 1);
60+
normalize_path_copy(normalized, filename);
61+
free(filename);
62+
return normalized;
5563
}
5664

5765
static char *get_chain_filename(const char *obj_dir)
@@ -751,7 +759,7 @@ struct packed_oid_list {
751759

752760
struct write_commit_graph_context {
753761
struct repository *r;
754-
const char *obj_dir;
762+
char *obj_dir;
755763
char *graph_name;
756764
struct packed_oid_list oids;
757765
struct packed_commit_list commits;
@@ -1700,7 +1708,11 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
17001708
}
17011709

17021710
strbuf_addstr(&path, ctx->obj_dir);
1703-
strbuf_addstr(&path, "/info/commit-graphs");
1711+
1712+
if (path.buf[path.len - 1] != '/')
1713+
strbuf_addch(&path, '/');
1714+
1715+
strbuf_addstr(&path, "info/commit-graphs");
17041716
dir = opendir(path.buf);
17051717

17061718
if (!dir) {
@@ -1734,7 +1746,6 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
17341746

17351747
if (!found)
17361748
unlink(path.buf);
1737-
17381749
}
17391750
}
17401751

@@ -1746,14 +1757,22 @@ int write_commit_graph(const char *obj_dir,
17461757
{
17471758
struct write_commit_graph_context *ctx;
17481759
uint32_t i, count_distinct = 0;
1760+
size_t len;
17491761
int res = 0;
17501762

17511763
if (!commit_graph_compatible(the_repository))
17521764
return 0;
17531765

17541766
ctx = xcalloc(1, sizeof(struct write_commit_graph_context));
17551767
ctx->r = the_repository;
1756-
ctx->obj_dir = obj_dir;
1768+
1769+
/* normalize object dir with no trailing slash */
1770+
ctx->obj_dir = xmallocz(strlen(obj_dir) + 1);
1771+
normalize_path_copy(ctx->obj_dir, obj_dir);
1772+
len = strlen(ctx->obj_dir);
1773+
if (len && ctx->obj_dir[len - 1] == '/')
1774+
ctx->obj_dir[len - 1] = 0;
1775+
17571776
ctx->append = flags & COMMIT_GRAPH_APPEND ? 1 : 0;
17581777
ctx->report_progress = flags & COMMIT_GRAPH_PROGRESS ? 1 : 0;
17591778
ctx->split = flags & COMMIT_GRAPH_SPLIT ? 1 : 0;
@@ -1861,6 +1880,7 @@ int write_commit_graph(const char *obj_dir,
18611880
free(ctx->graph_name);
18621881
free(ctx->commits.list);
18631882
free(ctx->oids.list);
1883+
free(ctx->obj_dir);
18641884

18651885
if (ctx->commit_graph_filenames_after) {
18661886
for (i = 0; i < ctx->num_commit_graphs_after; i++) {

0 commit comments

Comments
 (0)