]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: collapse parameters into flags
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 12 Jun 2019 13:29:38 +0000 (06:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Jun 2019 18:20:53 +0000 (11:20 -0700)
The write_commit_graph() and write_commit_graph_reachable() methods
currently take two boolean parameters: 'append' and 'report_progress'.
As we update these methods, adding more parameters this way becomes
cluttered and hard to maintain.

Collapse these parameters into a 'flags' parameter, and adjust the
callers to provide flags as necessary.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit-graph.c
builtin/commit.c
builtin/gc.c
commit-graph.c
commit-graph.h

index 2a1c4d701fcb50605b46c441dd16729f8b7c6605..d8efa5bab276a816bef48e9cb3891ccc0cb81aad 100644 (file)
@@ -142,6 +142,7 @@ static int graph_write(int argc, const char **argv)
        struct string_list *commit_hex = NULL;
        struct string_list lines;
        int result = 0;
+       unsigned int flags = COMMIT_GRAPH_PROGRESS;
 
        static struct option builtin_commit_graph_write_options[] = {
                OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -166,11 +167,13 @@ static int graph_write(int argc, const char **argv)
                die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
        if (!opts.obj_dir)
                opts.obj_dir = get_object_directory();
+       if (opts.append)
+               flags |= COMMIT_GRAPH_APPEND;
 
        read_replace_refs = 0;
 
        if (opts.reachable)
-               return write_commit_graph_reachable(opts.obj_dir, opts.append, 1);
+               return write_commit_graph_reachable(opts.obj_dir, flags);
 
        string_list_init(&lines, 0);
        if (opts.stdin_packs || opts.stdin_commits) {
@@ -190,8 +193,7 @@ static int graph_write(int argc, const char **argv)
        if (write_commit_graph(opts.obj_dir,
                               pack_indexes,
                               commit_hex,
-                              opts.append,
-                              1))
+                              flags))
                result = 1;
 
        UNLEAK(lines);
index b9ea7222fae4d6caf0f7ab6f975179922f5e2293..b001ef565ddcb179a3696dac21ec023751313a7d 100644 (file)
@@ -1670,7 +1670,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                      "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, 0))
+           write_commit_graph_reachable(get_object_directory(), 0))
                return 1;
 
        repo_rerere(the_repository, 0);
index 3984addf73c48a53afb3f8546836733acb77f53e..df2573f124d5fd818b92a39c81e9fd62338986c7 100644 (file)
@@ -665,8 +665,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        }
 
        if (gc_write_commit_graph &&
-           write_commit_graph_reachable(get_object_directory(), 0,
-                                        !quiet && !daemonized))
+           write_commit_graph_reachable(get_object_directory(),
+                                        !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0))
                return 1;
 
        if (auto_gc && too_many_loose_objects())
index 1b58d1da149ae80c971326d0069e17477d5022c2..fc40b531afc04a00a9d1caf158250a110525b3ff 100644 (file)
@@ -851,15 +851,14 @@ static int add_ref_to_list(const char *refname,
        return 0;
 }
 
-int write_commit_graph_reachable(const char *obj_dir, int append,
-                                int report_progress)
+int write_commit_graph_reachable(const char *obj_dir, unsigned int flags)
 {
        struct string_list list = STRING_LIST_INIT_DUP;
        int result;
 
        for_each_ref(add_ref_to_list, &list);
        result = write_commit_graph(obj_dir, NULL, &list,
-                                   append, report_progress);
+                                   flags);
 
        string_list_clear(&list, 0);
        return result;
@@ -868,7 +867,7 @@ int write_commit_graph_reachable(const char *obj_dir, int append,
 int write_commit_graph(const char *obj_dir,
                       struct string_list *pack_indexes,
                       struct string_list *commit_hex,
-                      int append, int report_progress)
+                      unsigned int flags)
 {
        struct packed_oid_list oids;
        struct packed_commit_list commits;
@@ -887,6 +886,8 @@ int write_commit_graph(const char *obj_dir,
        struct strbuf progress_title = STRBUF_INIT;
        unsigned long approx_nr_objects;
        int res = 0;
+       int append = flags & COMMIT_GRAPH_APPEND;
+       int report_progress = flags & COMMIT_GRAPH_PROGRESS;
 
        if (!commit_graph_compatible(the_repository))
                return 0;
index 869717ca19f19294e28ca01096a1ba0e51e2e0a1..01538b5cf59986ada4e8fa69552ed8ba8f33112e 100644 (file)
@@ -65,18 +65,20 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
  */
 int generation_numbers_enabled(struct repository *r);
 
+#define COMMIT_GRAPH_APPEND     (1 << 0)
+#define COMMIT_GRAPH_PROGRESS   (1 << 1)
+
 /*
  * The write_commit_graph* methods return zero on success
  * and a negative value on failure. Note that if the repository
  * is not compatible with the commit-graph feature, then the
  * methods will return 0 without writing a commit-graph.
  */
-int write_commit_graph_reachable(const char *obj_dir, int append,
-                                 int report_progress);
+int write_commit_graph_reachable(const char *obj_dir, unsigned int flags);
 int write_commit_graph(const char *obj_dir,
                       struct string_list *pack_indexes,
                       struct string_list *commit_hex,
-                      int append, int report_progress);
+                      unsigned int flags);
 
 int verify_commit_graph(struct repository *r, struct commit_graph *g);