43
43
44
44
char * get_commit_graph_filename (const char * obj_dir )
45
45
{
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 ;
47
51
}
48
52
49
53
static char * get_split_graph_filename (const char * obj_dir ,
50
54
const char * oid_hex )
51
55
{
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 ;
55
63
}
56
64
57
65
static char * get_chain_filename (const char * obj_dir )
@@ -751,7 +759,7 @@ struct packed_oid_list {
751
759
752
760
struct write_commit_graph_context {
753
761
struct repository * r ;
754
- const char * obj_dir ;
762
+ char * obj_dir ;
755
763
char * graph_name ;
756
764
struct packed_oid_list oids ;
757
765
struct packed_commit_list commits ;
@@ -1700,7 +1708,11 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
1700
1708
}
1701
1709
1702
1710
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" );
1704
1716
dir = opendir (path .buf );
1705
1717
1706
1718
if (!dir ) {
@@ -1734,7 +1746,6 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
1734
1746
1735
1747
if (!found )
1736
1748
unlink (path .buf );
1737
-
1738
1749
}
1739
1750
}
1740
1751
@@ -1746,14 +1757,22 @@ int write_commit_graph(const char *obj_dir,
1746
1757
{
1747
1758
struct write_commit_graph_context * ctx ;
1748
1759
uint32_t i , count_distinct = 0 ;
1760
+ size_t len ;
1749
1761
int res = 0 ;
1750
1762
1751
1763
if (!commit_graph_compatible (the_repository ))
1752
1764
return 0 ;
1753
1765
1754
1766
ctx = xcalloc (1 , sizeof (struct write_commit_graph_context ));
1755
1767
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
+
1757
1776
ctx -> append = flags & COMMIT_GRAPH_APPEND ? 1 : 0 ;
1758
1777
ctx -> report_progress = flags & COMMIT_GRAPH_PROGRESS ? 1 : 0 ;
1759
1778
ctx -> split = flags & COMMIT_GRAPH_SPLIT ? 1 : 0 ;
@@ -1861,6 +1880,7 @@ int write_commit_graph(const char *obj_dir,
1861
1880
free (ctx -> graph_name );
1862
1881
free (ctx -> commits .list );
1863
1882
free (ctx -> oids .list );
1883
+ free (ctx -> obj_dir );
1864
1884
1865
1885
if (ctx -> commit_graph_filenames_after ) {
1866
1886
for (i = 0 ; i < ctx -> num_commit_graphs_after ; i ++ ) {
0 commit comments