Skip to content

Commit 544b58b

Browse files
derrickstoleegitster
authored andcommitted
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'. We will soon expand the possible options to send to these methods, so instead of complicating the parameter list, first simplify it. Collapse these parameters into a 'flags' parameter, and adjust the callers to provide flags as necessary. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent efeb229 commit 544b58b

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

builtin/commit-graph.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static int graph_write(int argc, const char **argv)
142142
struct string_list *commit_hex = NULL;
143143
struct string_list lines;
144144
int result;
145+
int flags = COMMIT_GRAPH_PROGRESS;
145146

146147
static struct option builtin_commit_graph_write_options[] = {
147148
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -166,11 +167,13 @@ static int graph_write(int argc, const char **argv)
166167
die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
167168
if (!opts.obj_dir)
168169
opts.obj_dir = get_object_directory();
170+
if (opts.append)
171+
flags |= COMMIT_GRAPH_APPEND;
169172

170173
read_replace_refs = 0;
171174

172175
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);
174177

175178
string_list_init(&lines, 0);
176179
if (opts.stdin_packs || opts.stdin_commits) {
@@ -190,8 +193,7 @@ static int graph_write(int argc, const char **argv)
190193
result = write_commit_graph(opts.obj_dir,
191194
pack_indexes,
192195
commit_hex,
193-
opts.append,
194-
1);
196+
flags);
195197

196198
UNLEAK(lines);
197199
return result;

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16701670
"not exceeded, and then \"git reset HEAD\" to recover."));
16711671

16721672
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))
16741674
return 1;
16751675

16761676
repo_rerere(the_repository, 0);

builtin/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
665665
}
666666

667667
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))
670670
return 1;
671671

672672
if (auto_gc && too_many_loose_objects())

commit-graph.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,14 @@ static int add_ref_to_list(const char *refname,
851851
return 0;
852852
}
853853

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)
856855
{
857856
struct string_list list = STRING_LIST_INIT_DUP;
858857
int result;
859858

860859
for_each_ref(add_ref_to_list, &list);
861860
result = write_commit_graph(obj_dir, NULL, &list,
862-
append, report_progress);
861+
flags);
863862

864863
string_list_clear(&list, 0);
865864
return result;
@@ -868,7 +867,7 @@ int write_commit_graph_reachable(const char *obj_dir, int append,
868867
int write_commit_graph(const char *obj_dir,
869868
struct string_list *pack_indexes,
870869
struct string_list *commit_hex,
871-
int append, int report_progress)
870+
unsigned int flags)
872871
{
873872
struct packed_oid_list oids;
874873
struct packed_commit_list commits;
@@ -887,6 +886,8 @@ int write_commit_graph(const char *obj_dir,
887886
struct strbuf progress_title = STRBUF_INIT;
888887
unsigned long approx_nr_objects;
889888
int res = 0;
889+
int append = flags & COMMIT_GRAPH_APPEND;
890+
int report_progress = flags & COMMIT_GRAPH_PROGRESS;
890891

891892
if (!commit_graph_compatible(the_repository))
892893
return 0;

commit-graph.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
6565
*/
6666
int generation_numbers_enabled(struct repository *r);
6767

68-
int write_commit_graph_reachable(const char *obj_dir, int append,
69-
int report_progress);
68+
#define COMMIT_GRAPH_APPEND (1 << 0)
69+
#define COMMIT_GRAPH_PROGRESS (1 << 1)
70+
71+
int write_commit_graph_reachable(const char *obj_dir, unsigned int flags);
7072
int write_commit_graph(const char *obj_dir,
7173
struct string_list *pack_indexes,
7274
struct string_list *commit_hex,
73-
int append, int report_progress);
75+
unsigned int flags);
7476

7577
int verify_commit_graph(struct repository *r, struct commit_graph *g);
7678

0 commit comments

Comments
 (0)