Skip to content

Commit 77e6e0a

Browse files
committed
commit-graph: add verify changed paths option
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 47ae905 commit 77e6e0a

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
}
@@ -439,7 +449,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
439449

440450
hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
441451

442-
if (verify_commit_graph_lite(graph))
452+
if (verify_commit_graph_lite(graph, 0))
443453
goto free_and_return;
444454

445455
return graph;
@@ -2216,7 +2226,9 @@ static void graph_report(const char *fmt, ...)
22162226
#define GENERATION_ZERO_EXISTS 1
22172227
#define GENERATION_NUMBER_EXISTS 2
22182228

2219-
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2229+
int verify_commit_graph(struct repository *r,
2230+
struct commit_graph *g,
2231+
enum commit_graph_verify_flags flags)
22202232
{
22212233
uint32_t i, cur_fanout_pos = 0;
22222234
struct object_id prev_oid, cur_oid, checksum;
@@ -2231,7 +2243,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
22312243
return 1;
22322244
}
22332245

2234-
verify_commit_graph_error = verify_commit_graph_lite(g);
2246+
verify_commit_graph_error = verify_commit_graph_lite(g, flags & COMMIT_GRAPH_VERIFY_CHANGED_PATHS);
22352247
if (verify_commit_graph_error)
22362248
return verify_commit_graph_error;
22372249

@@ -2284,7 +2296,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
22842296
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
22852297
return verify_commit_graph_error;
22862298

2287-
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
2299+
if (flags & COMMIT_GRAPH_VERIFY_PROGRESS)
22882300
progress = start_progress(_("Verifying commits in commit graph"),
22892301
g->num_commits);
22902302

commit-graph.h

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

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

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

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

0 commit comments

Comments
 (0)