From: Junio C Hamano Date: Mon, 17 Sep 2018 20:53:58 +0000 (-0700) Subject: Merge branch 'ds/commit-graph-tests' X-Git-Tag: v2.20.0-rc0~234 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/06880cff3892185ae71839636e2d2c688413eccb?ds=inline;hp=-c Merge branch 'ds/commit-graph-tests' We can now optionally run tests with commit-graph enabled. * ds/commit-graph-tests: commit-graph: define GIT_TEST_COMMIT_GRAPH --- 06880cff3892185ae71839636e2d2c688413eccb diff --combined builtin/commit.c index fa3e53232d,37c0056a6e..b57d8e4b82 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -33,7 -33,7 +33,8 @@@ #include "sequencer.h" #include "mailmap.h" #include "help.h" +#include "commit-reach.h" + #include "commit-graph.h" static const char * const builtin_commit_usage[] = { N_("git commit [] [--] ..."), @@@ -1652,6 -1652,9 +1653,9 @@@ int cmd_commit(int argc, const char **a "new_index file. Check that disk is not full and quota is\n" "not exceeded, and then \"git reset HEAD\" to recover.")); + if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0)) + write_commit_graph_reachable(get_object_directory(), 0); + rerere(0); run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); diff --combined commit-graph.c index ae6cabb4cd,1643a0a816..7f4519ec3b --- a/commit-graph.c +++ b/commit-graph.c @@@ -213,8 -213,9 +213,9 @@@ static int prepare_commit_graph(struct return !!r->objects->commit_graph; r->objects->commit_graph_attempted = 1; - if (repo_config_get_bool(r, "core.commitgraph", &config_value) || - !config_value) + if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) && + (repo_config_get_bool(r, "core.commitgraph", &config_value) || + !config_value)) /* * This repository is not configured to use commit graphs, so * do not load one. (But report commit_graph_attempted anyway @@@ -233,24 -234,6 +234,24 @@@ return !!r->objects->commit_graph; } +int generation_numbers_enabled(struct repository *r) +{ + uint32_t first_generation; + struct commit_graph *g; + if (!prepare_commit_graph(r)) + return 0; + + g = r->objects->commit_graph; + + if (!g->num_commits) + return 0; + + first_generation = get_be32(g->chunk_commit_data + + g->hash_len + 8) >> 2; + + return !!first_generation; +} + static void close_commit_graph(void) { free_commit_graph(the_repository->objects->commit_graph); @@@ -783,7 -766,7 +784,7 @@@ void write_commit_graph(const char *obj count_distinct = 1; for (i = 1; i < oids.nr; i++) { - if (oidcmp(&oids.list[i-1], &oids.list[i])) + if (!oideq(&oids.list[i - 1], &oids.list[i])) count_distinct++; } @@@ -797,7 -780,7 +798,7 @@@ num_extra_edges = 0; for (i = 0; i < oids.nr; i++) { int num_parents = 0; - if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i])) + if (i > 0 && oideq(&oids.list[i - 1], &oids.list[i])) continue; commits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]); @@@ -918,7 -901,7 +919,7 @@@ int verify_commit_graph(struct reposito f = hashfd(devnull, NULL); hashwrite(f, g->data, g->data_len - g->hash_len); finalize_hashfile(f, checksum.hash, CSUM_CLOSE); - if (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) { + if (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) { graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt")); verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH; } @@@ -978,7 -961,7 +979,7 @@@ continue; } - if (oidcmp(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid, + if (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid, get_commit_tree_oid(odb_commit))) graph_report("root tree OID for commit %s in commit-graph is %s != %s", oid_to_hex(&cur_oid), @@@ -995,7 -978,7 +996,7 @@@ break; } - if (oidcmp(&graph_parents->item->object.oid, &odb_parents->item->object.oid)) + if (!oideq(&graph_parents->item->object.oid, &odb_parents->item->object.oid)) graph_report("commit-graph parent for %s is %s != %s", oid_to_hex(&cur_oid), oid_to_hex(&graph_parents->item->object.oid), diff --combined commit-graph.h index 698f09e2bc,5fd8ded7c6..b050476765 --- a/commit-graph.h +++ b/commit-graph.h @@@ -6,6 -6,8 +6,8 @@@ #include "string-list.h" #include "cache.h" + #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH" + struct commit; char *get_commit_graph_filename(const char *obj_dir); @@@ -52,12 -54,6 +54,12 @@@ struct commit_graph struct commit_graph *load_commit_graph_one(const char *graph_file); +/* + * Return 1 if and only if the repository has a commit-graph + * file and generation numbers are computed in that file. + */ +int generation_numbers_enabled(struct repository *r); + void write_commit_graph_reachable(const char *obj_dir, int append); void write_commit_graph(const char *obj_dir, struct string_list *pack_indexes, diff --combined t/README index 204b9f4cc5,fed7a066ab..3ea6c85460 --- a/t/README +++ b/t/README @@@ -319,10 -319,10 +319,14 @@@ GIT_TEST_OE_DELTA_SIZE= exercises th path where deltas larger than this limit require extra memory allocation for bookkeeping. +GIT_TEST_VALIDATE_INDEX_CACHE_ENTRIES= checks that cache-tree +records are valid when the index is written out or after a merge. This +is mostly to catch missing invalidation. Default is true. + + GIT_TEST_COMMIT_GRAPH=, when true, forces the commit-graph to + be written after every 'git commit' command, and overrides the + 'core.commitGraph' setting to true. + Naming Tests ------------