]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'gs/commit-graph-progress'
authorJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2019 02:32:57 +0000 (11:32 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2019 02:32:57 +0000 (11:32 +0900)
* gs/commit-graph-progress:
  commit-graph: add --[no-]progress to write and verify

1  2 
builtin/commit-graph.c
commit-graph.c

diff --combined builtin/commit-graph.c
index 052696f1af43c0da6e8ab7f588b451458bec40ce,184872c0ed0f0bb9bc09945b388809da38b0091c..a6c500d8daf43ba58c6dfc28187b2ff9f228fe6a
  static char const * const builtin_commit_graph_usage[] = {
        N_("git commit-graph [--object-dir <objdir>]"),
        N_("git commit-graph read [--object-dir <objdir>]"),
-       N_("git commit-graph verify [--object-dir <objdir>] [--shallow]"),
-       N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] <split options>"),
+       N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
+       N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
        NULL
  };
  
  static const char * const builtin_commit_graph_verify_usage[] = {
-       N_("git commit-graph verify [--object-dir <objdir>] [--shallow]"),
+       N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
        NULL
  };
  
@@@ -26,7 -26,7 +26,7 @@@ static const char * const builtin_commi
  };
  
  static const char * const builtin_commit_graph_write_usage[] = {
-       N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] <split options>"),
+       N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
        NULL
  };
  
@@@ -38,6 -38,7 +38,7 @@@ static struct opts_commit_graph 
        int append;
        int split;
        int shallow;
+       int progress;
  } opts;
  
  static int graph_verify(int argc, const char **argv)
                           N_("The object directory to store the graph")),
                OPT_BOOL(0, "shallow", &opts.shallow,
                         N_("if the commit-graph is split, only verify the tip file")),
+               OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
                OPT_END(),
        };
  
+       opts.progress = isatty(2);
        argc = parse_options(argc, argv, NULL,
                             builtin_commit_graph_verify_options,
                             builtin_commit_graph_verify_usage, 0);
@@@ -66,6 -69,8 +69,8 @@@
                opts.obj_dir = get_object_directory();
        if (opts.shallow)
                flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
+       if (opts.progress)
+               flags |= COMMIT_GRAPH_WRITE_PROGRESS;
  
        graph_name = get_commit_graph_filename(opts.obj_dir);
        open_ok = open_commit_graph(graph_name, &fd, &st);
@@@ -154,7 -159,7 +159,7 @@@ static int graph_write(int argc, const 
        struct string_list *commit_hex = NULL;
        struct string_list lines;
        int result = 0;
-       enum commit_graph_write_flags flags = COMMIT_GRAPH_WRITE_PROGRESS;
+       enum commit_graph_write_flags flags = 0;
  
        static struct option builtin_commit_graph_write_options[] = {
                OPT_STRING(0, "object-dir", &opts.obj_dir,
                        N_("start walk at commits listed by stdin")),
                OPT_BOOL(0, "append", &opts.append,
                        N_("include all commits already in the commit-graph file")),
+               OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
                OPT_BOOL(0, "split", &opts.split,
                        N_("allow writing an incremental commit-graph file")),
                OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
                OPT_END(),
        };
  
+       opts.progress = isatty(2);
        split_opts.size_multiple = 2;
        split_opts.max_commits = 0;
        split_opts.expire_time = 0;
                flags |= COMMIT_GRAPH_WRITE_APPEND;
        if (opts.split)
                flags |= COMMIT_GRAPH_WRITE_SPLIT;
+       if (opts.progress)
+               flags |= COMMIT_GRAPH_WRITE_PROGRESS;
  
        read_replace_refs = 0;
  
@@@ -251,8 -260,6 +260,8 @@@ int cmd_commit_graph(int argc, const ch
                             builtin_commit_graph_usage,
                             PARSE_OPT_STOP_AT_NON_OPTION);
  
 +      save_commit_buffer = 0;
 +
        if (argc > 0) {
                if (!strcmp(argv[0], "read"))
                        return graph_read(argc, argv);
diff --combined commit-graph.c
index 19cb1fecfa34ba5945bb6baab6f4c0a4b096cc78,1f23e90567c819f4524e1bc2ade0e5a288e800f8..c3ba79fe4e11f5b47cf05e29c68a868d29ade1f9
@@@ -468,21 -468,14 +468,21 @@@ static int prepare_commit_graph(struct 
  {
        struct object_directory *odb;
  
 -      if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0))
 -              die("dying as requested by the '%s' variable on commit-graph load!",
 -                  GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD);
 +      /*
 +       * This must come before the "already attempted?" check below, because
 +       * we want to disable even an already-loaded graph file.
 +       */
 +      if (r->commit_graph_disabled)
 +              return 0;
  
        if (r->objects->commit_graph_attempted)
                return !!r->objects->commit_graph;
        r->objects->commit_graph_attempted = 1;
  
 +      if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0))
 +              die("dying as requested by the '%s' variable on commit-graph load!",
 +                  GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD);
 +
        prepare_repo_settings(r);
  
        if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
@@@ -1057,7 -1050,7 +1057,7 @@@ static void close_reachable(struct writ
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
                                        _("Expanding reachable commits in commit graph"),
 -                                      ctx->oids.nr);
 +                                      0);
        for (i = 0; i < ctx->oids.nr; i++) {
                display_progress(ctx->progress, i + 1);
                commit = lookup_commit(ctx->r, &ctx->oids.list[i]);
@@@ -1286,6 -1279,7 +1286,6 @@@ static uint32_t count_distinct_commits(
  static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
  {
        uint32_t i;
 -      struct commit_list *parent;
  
        ctx->num_extra_edges = 0;
        if (ctx->report_progress)
                        _("Finding extra edges in commit graph"),
                        ctx->oids.nr);
        for (i = 0; i < ctx->oids.nr; i++) {
 -              int num_parents = 0;
 +              unsigned int num_parents;
 +
                display_progress(ctx->progress, i + 1);
                if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
                        continue;
  
                parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
  
 -              for (parent = ctx->commits.list[ctx->commits.nr]->parents;
 -                   parent; parent = parent->next)
 -                      num_parents++;
 -
 +              num_parents = commit_list_count(ctx->commits.list[ctx->commits.nr]->parents);
                if (num_parents > 2)
                        ctx->num_extra_edges += num_parents - 1;
  
@@@ -1620,7 -1616,8 +1620,7 @@@ static int commit_compare(const void *_
  
  static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
  {
 -      uint32_t i, num_parents;
 -      struct commit_list *parent;
 +      uint32_t i;
  
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
                        die(_("unexpected duplicate commit id %s"),
                            oid_to_hex(&ctx->commits.list[i]->object.oid));
                } else {
 -                      num_parents = 0;
 -                      for (parent = ctx->commits.list[i]->parents; parent; parent = parent->next)
 -                              num_parents++;
 +                      unsigned int num_parents;
  
 +                      num_parents = commit_list_count(ctx->commits.list[i]->parents);
                        if (num_parents > 2)
                                ctx->num_extra_edges += num_parents - 1;
                }
@@@ -1994,8 -1992,10 +1994,10 @@@ int verify_commit_graph(struct reposito
        if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
                return verify_commit_graph_error;
  
-       progress = start_progress(_("Verifying commits in commit graph"),
-                                 g->num_commits);
+       if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
+               progress = start_progress(_("Verifying commits in commit graph"),
+                                       g->num_commits);
        for (i = 0; i < g->num_commits; i++) {
                struct commit *graph_commit, *odb_commit;
                struct commit_list *graph_parents, *odb_parents;
@@@ -2103,8 -2103,3 +2105,8 @@@ void free_commit_graph(struct commit_gr
        free(g->filename);
        free(g);
  }
 +
 +void disable_commit_graph(struct repository *r)
 +{
 +      r->commit_graph_disabled = 1;
 +}