Merge branch 'ds/commit-graph-tests'
authorJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:53:58 +0000 (13:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:53:58 +0000 (13:53 -0700)
We can now optionally run tests with commit-graph enabled.

* ds/commit-graph-tests:
commit-graph: define GIT_TEST_COMMIT_GRAPH

1  2 
builtin/commit.c
commit-graph.c
commit-graph.h
t/README
diff --combined builtin/commit.c
index fa3e53232d2d24564a2de6370b3bdef72a153735,37c0056a6eb0fad9afbe51c23f809a842b4636bb..b57d8e4b82052bdb85287b5fcb675261a68c639b
@@@ -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 [<options>] [--] <pathspec>..."),
@@@ -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 ae6cabb4cda46a74d5f4f59bbf54a550361fd10f,1643a0a816e0d38ac4b41303dab9e621d03d61ee..7f4519ec3b1a6659551fc4ba792cbef151367a4e
@@@ -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
        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++;
        }
  
        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;
        }
                        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),
                                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 698f09e2bc876cf9ccfed04022827dc1fdd9bfbd,5fd8ded7c68fadf086e9f2cb59664ac08e850f98..b05047676514e4d031ac90de50510eb33a4b6db6
@@@ -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 204b9f4cc5cbf8ad265423f6062cd99c24dd33d3,fed7a066ab03ce2999f0a734341685134b85b7fc..3ea6c854606056e1a7d9431dd59518d817768527
+++ b/t/README
@@@ -319,10 -319,10 +319,14 @@@ GIT_TEST_OE_DELTA_SIZE=<n> exercises th
  path where deltas larger than this limit require extra memory
  allocation for bookkeeping.
  
 +GIT_TEST_VALIDATE_INDEX_CACHE_ENTRIES=<boolean> 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=<boolean>, when true, forces the commit-graph to
+ be written after every 'git commit' command, and overrides the
+ 'core.commitGraph' setting to true.
  Naming Tests
  ------------