Skip to content

Commit 80d776b

Browse files
committed
commit-graph: add verify changed paths
Add '--has-changed-paths' option to 'git commit-graph verify' subcommand to validate whether the commit-graph was written with '--changed-paths' option. Signed-off-by: Son Luong Ngoc <[email protected]>
1 parent 6104cc2 commit 80d776b

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

builtin/commit-graph.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ static char const * const builtin_commit_graph_usage[] = {
1818
};
1919

2020
static const char * const builtin_commit_graph_verify_usage[] = {
21-
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
21+
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] "
22+
"[--has-changed-paths] [--[no-]progress]"),
2223
NULL
2324
};
2425

@@ -37,6 +38,7 @@ static struct opts_commit_graph {
3738
int append;
3839
int split;
3940
int shallow;
41+
int has_changed_paths;
4042
int progress;
4143
int enable_changed_paths;
4244
} opts;
@@ -71,12 +73,14 @@ static int graph_verify(int argc, const char **argv)
7173
int open_ok;
7274
int fd;
7375
struct stat st;
74-
int flags = 0;
76+
enum commit_graph_verify_flags flags = 0;
7577

7678
static struct option builtin_commit_graph_verify_options[] = {
7779
OPT_STRING(0, "object-dir", &opts.obj_dir,
7880
N_("dir"),
7981
N_("The object directory to store the graph")),
82+
OPT_BOOL(0, "has-changed-paths", &opts.has_changed_paths,
83+
N_("verify that the commit-graph includes changed paths")),
8084
OPT_BOOL(0, "shallow", &opts.shallow,
8185
N_("if the commit-graph is split, only verify the tip file")),
8286
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
@@ -94,8 +98,10 @@ static int graph_verify(int argc, const char **argv)
9498
opts.obj_dir = get_object_directory();
9599
if (opts.shallow)
96100
flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
101+
if (opts.has_changed_paths)
102+
flags |= COMMIT_GRAPH_VERIFY_CHANGED_PATHS;
97103
if (opts.progress)
98-
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
104+
flags |= COMMIT_GRAPH_VERIFY_PROGRESS;
99105

100106
odb = find_odb(the_repository, opts.obj_dir);
101107
graph_name = get_commit_graph_filename(odb);

commit-graph.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
250250
return ret;
251251
}
252252

253-
static int verify_commit_graph_lite(struct commit_graph *g)
253+
static int verify_commit_graph_lite(struct commit_graph *g, int verify_changed_path)
254254
{
255255
/*
256256
* Basic validation shared between parse_commit_graph()
@@ -276,6 +276,16 @@ static int verify_commit_graph_lite(struct commit_graph *g)
276276
error("commit-graph is missing the Commit Data chunk");
277277
return 1;
278278
}
279+
if (verify_changed_path) {
280+
if (!g->chunk_bloom_indexes) {
281+
error("commit-graph is missing Bloom Index chunk");
282+
return 1;
283+
}
284+
if (!g->chunk_bloom_data) {
285+
error("commit-graph is missing Bloom Data chunk");
286+
return 1;
287+
}
288+
}
279289

280290
return 0;
281291
}
@@ -434,7 +444,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
434444

435445
hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
436446

437-
if (verify_commit_graph_lite(graph))
447+
if (verify_commit_graph_lite(graph, 0))
438448
goto free_and_return;
439449

440450
return graph;
@@ -2272,7 +2282,9 @@ static void graph_report(const char *fmt, ...)
22722282
#define GENERATION_ZERO_EXISTS 1
22732283
#define GENERATION_NUMBER_EXISTS 2
22742284

2275-
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2285+
int verify_commit_graph(struct repository *r,
2286+
struct commit_graph *g,
2287+
enum commit_graph_verify_flags flags)
22762288
{
22772289
uint32_t i, cur_fanout_pos = 0;
22782290
struct object_id prev_oid, cur_oid, checksum;
@@ -2287,7 +2299,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
22872299
return 1;
22882300
}
22892301

2290-
verify_commit_graph_error = verify_commit_graph_lite(g);
2302+
verify_commit_graph_error = verify_commit_graph_lite(g, flags & COMMIT_GRAPH_VERIFY_CHANGED_PATHS);
22912303
if (verify_commit_graph_error)
22922304
return verify_commit_graph_error;
22932305

@@ -2340,7 +2352,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
23402352
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
23412353
return verify_commit_graph_error;
23422354

2343-
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
2355+
if (flags & COMMIT_GRAPH_VERIFY_PROGRESS)
23442356
progress = start_progress(_("Verifying commits in commit graph"),
23452357
g->num_commits);
23462358

commit-graph.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ enum commit_graph_write_flags {
9595
COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS = (1 << 4),
9696
};
9797

98+
enum commit_graph_verify_flags {
99+
COMMIT_GRAPH_VERIFY_SHALLOW = (1 << 0),
100+
COMMIT_GRAPH_VERIFY_CHANGED_PATHS = (1 << 1),
101+
COMMIT_GRAPH_VERIFY_PROGRESS = (1 << 2),
102+
};
103+
98104
enum commit_graph_split_flags {
99105
COMMIT_GRAPH_SPLIT_UNSPECIFIED = 0,
100106
COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED = 1,
@@ -123,9 +129,9 @@ int write_commit_graph(struct object_directory *odb,
123129
enum commit_graph_write_flags flags,
124130
const struct split_commit_graph_opts *split_opts);
125131

126-
#define COMMIT_GRAPH_VERIFY_SHALLOW (1 << 0)
127-
128-
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
132+
int verify_commit_graph(struct repository *r,
133+
struct commit_graph *g,
134+
enum commit_graph_verify_flags flags);
129135

130136
void close_commit_graph(struct raw_object_store *);
131137
void free_commit_graph(struct commit_graph *);

0 commit comments

Comments
 (0)