commit-graph: collapse parameters into flags

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>

Derrick Stolee committed Jun 12, 2019 at 06:29 UTC 5af803945212af875670582ff153ee05ec368b83
5 files changed +18 -13
builtin/commit-graph.c
+5 -3
@@ -142,6 +142,7 @@ static int graph_write(int argc, const char **argv)
142 struct string_list *commit_hex = NULL;
143 struct string_list lines;
144 int result = 0;
145 + unsigned int flags = COMMIT_GRAPH_PROGRESS;
146
147 static struct option builtin_commit_graph_write_options[] = {
148 OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -166,11 +167,13 @@ static int graph_write(int argc, const char **argv)
167 die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
168 if (!opts.obj_dir)
169 opts.obj_dir = get_object_directory();
170 + if (opts.append)
171 + flags |= COMMIT_GRAPH_APPEND;
172
173 read_replace_refs = 0;
174
175 if (opts.reachable)
173 - return write_commit_graph_reachable(opts.obj_dir, opts.append, 1);
176 + return write_commit_graph_reachable(opts.obj_dir, flags);
177
178 string_list_init(&lines, 0);
179 if (opts.stdin_packs || opts.stdin_commits) {
@@ -190,8 +193,7 @@ static int graph_write(int argc, const char **argv)
193 if (write_commit_graph(opts.obj_dir,
194 pack_indexes,
195 commit_hex,
193 - opts.append,
194 - 1))
196 + flags))
197 result = 1;
198
199 UNLEAK(lines);
builtin/commit.c
+1 -1
@@ -1670,7 +1670,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1670 "not exceeded, and then \"git reset HEAD\" to recover."));
1671
1672 if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
1673 - write_commit_graph_reachable(get_object_directory(), 0, 0))
1673 + write_commit_graph_reachable(get_object_directory(), 0))
1674 return 1;
1675
1676 repo_rerere(the_repository, 0);
builtin/gc.c
+2 -2
@@ -665,8 +665,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
665 }
666
667 if (gc_write_commit_graph &&
668 - write_commit_graph_reachable(get_object_directory(), 0,
669 - !quiet && !daemonized))
668 + write_commit_graph_reachable(get_object_directory(),
669 + !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0))
670 return 1;
671
672 if (auto_gc && too_many_loose_objects())
commit-graph.c
+5 -4
@@ -851,15 +851,14 @@ static int add_ref_to_list(const char *refname,
851 return 0;
852 }
853
854 -int write_commit_graph_reachable(const char *obj_dir, int append,
855 - int report_progress)
854 +int write_commit_graph_reachable(const char *obj_dir, unsigned int flags)
855 {
856 struct string_list list = STRING_LIST_INIT_DUP;
857 int result;
858
859 for_each_ref(add_ref_to_list, &list);
860 result = write_commit_graph(obj_dir, NULL, &list,
862 - append, report_progress);
861 + flags);
862
863 string_list_clear(&list, 0);
864 return result;
@@ -868,7 +867,7 @@ int write_commit_graph_reachable(const char *obj_dir, int append,
867 int write_commit_graph(const char *obj_dir,
868 struct string_list *pack_indexes,
869 struct string_list *commit_hex,
871 - int append, int report_progress)
870 + unsigned int flags)
871 {
872 struct packed_oid_list oids;
873 struct packed_commit_list commits;
@@ -887,6 +886,8 @@ int write_commit_graph(const char *obj_dir,
886 struct strbuf progress_title = STRBUF_INIT;
887 unsigned long approx_nr_objects;
888 int res = 0;
889 + int append = flags & COMMIT_GRAPH_APPEND;
890 + int report_progress = flags & COMMIT_GRAPH_PROGRESS;
891
892 if (!commit_graph_compatible(the_repository))
893 return 0;
commit-graph.h
+5 -3
@@ -65,18 +65,20 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
65 */
66 int generation_numbers_enabled(struct repository *r);
67
68 +#define COMMIT_GRAPH_APPEND (1 << 0)
69 +#define COMMIT_GRAPH_PROGRESS (1 << 1)
70 +
71 /*
72 * The write_commit_graph* methods return zero on success
73 * and a negative value on failure. Note that if the repository
74 * is not compatible with the commit-graph feature, then the
75 * methods will return 0 without writing a commit-graph.
76 */
74 -int write_commit_graph_reachable(const char *obj_dir, int append,
75 - int report_progress);
77 +int write_commit_graph_reachable(const char *obj_dir, unsigned int flags);
78 int write_commit_graph(const char *obj_dir,
79 struct string_list *pack_indexes,
80 struct string_list *commit_hex,
79 - int append, int report_progress);
81 + unsigned int flags);
82
83 int verify_commit_graph(struct repository *r, struct commit_graph *g);
84