Skip to content

Commit c0049ca

Browse files
peffgitster
authored andcommitted
diff: drop useless return values in git-diff helpers
Since git-diff has many diff modes, it dispatches to many helpers to perform each one. But every helper simply returns "0", as it exits directly if there are serious errors (and options like --exit-code are handled afterwards). So let's get rid of these useless return values, which makes the code flow more clear. There's very little chance that we'd later want to propagate errors instead of dying immediately. These are all static-local helpers for the git-diff program implementing its various modes. More "lib-ified" code would directly call the underlying functions. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25bd3ac commit c0049ca

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

builtin/diff.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ static void stuff_change(struct diff_options *opt,
7777
diff_queue(&diff_queued_diff, one, two);
7878
}
7979

80-
static int builtin_diff_b_f(struct rev_info *revs,
81-
int argc, const char **argv UNUSED,
82-
struct object_array_entry **blob)
80+
static void builtin_diff_b_f(struct rev_info *revs,
81+
int argc, const char **argv UNUSED,
82+
struct object_array_entry **blob)
8383
{
8484
/* Blob vs file in the working tree*/
8585
struct stat st;
@@ -109,12 +109,11 @@ static int builtin_diff_b_f(struct rev_info *revs,
109109
path);
110110
diffcore_std(&revs->diffopt);
111111
diff_flush(&revs->diffopt);
112-
return 0;
113112
}
114113

115-
static int builtin_diff_blobs(struct rev_info *revs,
116-
int argc, const char **argv UNUSED,
117-
struct object_array_entry **blob)
114+
static void builtin_diff_blobs(struct rev_info *revs,
115+
int argc, const char **argv UNUSED,
116+
struct object_array_entry **blob)
118117
{
119118
const unsigned mode = canon_mode(S_IFREG | 0644);
120119

@@ -134,11 +133,10 @@ static int builtin_diff_blobs(struct rev_info *revs,
134133
blob_path(blob[0]), blob_path(blob[1]));
135134
diffcore_std(&revs->diffopt);
136135
diff_flush(&revs->diffopt);
137-
return 0;
138136
}
139137

140-
static int builtin_diff_index(struct rev_info *revs,
141-
int argc, const char **argv)
138+
static void builtin_diff_index(struct rev_info *revs,
139+
int argc, const char **argv)
142140
{
143141
unsigned int option = 0;
144142
while (1 < argc) {
@@ -169,13 +167,12 @@ static int builtin_diff_index(struct rev_info *revs,
169167
die_errno("repo_read_cache");
170168
}
171169
run_diff_index(revs, option);
172-
return 0;
173170
}
174171

175-
static int builtin_diff_tree(struct rev_info *revs,
176-
int argc, const char **argv,
177-
struct object_array_entry *ent0,
178-
struct object_array_entry *ent1)
172+
static void builtin_diff_tree(struct rev_info *revs,
173+
int argc, const char **argv,
174+
struct object_array_entry *ent0,
175+
struct object_array_entry *ent1)
179176
{
180177
const struct object_id *(oid[2]);
181178
struct object_id mb_oid;
@@ -208,13 +205,12 @@ static int builtin_diff_tree(struct rev_info *revs,
208205
}
209206
diff_tree_oid(oid[0], oid[1], "", &revs->diffopt);
210207
log_tree_diff_flush(revs);
211-
return 0;
212208
}
213209

214-
static int builtin_diff_combined(struct rev_info *revs,
215-
int argc, const char **argv UNUSED,
216-
struct object_array_entry *ent,
217-
int ents, int first_non_parent)
210+
static void builtin_diff_combined(struct rev_info *revs,
211+
int argc, const char **argv UNUSED,
212+
struct object_array_entry *ent,
213+
int ents, int first_non_parent)
218214
{
219215
struct oid_array parents = OID_ARRAY_INIT;
220216
int i;
@@ -235,7 +231,6 @@ static int builtin_diff_combined(struct rev_info *revs,
235231
}
236232
diff_tree_combined(&ent[first_non_parent].item->oid, &parents, revs);
237233
oid_array_clear(&parents);
238-
return 0;
239234
}
240235

241236
static void refresh_index_quietly(void)
@@ -253,7 +248,7 @@ static void refresh_index_quietly(void)
253248
repo_update_index_if_able(the_repository, &lock_file);
254249
}
255250

256-
static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
251+
static void builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
257252
{
258253
unsigned int options = 0;
259254

@@ -291,7 +286,6 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
291286
die_errno("repo_read_index_preload");
292287
}
293288
run_diff_files(revs, options);
294-
return 0;
295289
}
296290

297291
struct symdiff {
@@ -405,7 +399,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
405399
int blobs = 0, paths = 0;
406400
struct object_array_entry *blob[2];
407401
int nongit = 0, no_index = 0;
408-
int result = 0;
402+
int result;
409403
struct symdiff sdiff;
410404

411405
/*
@@ -584,17 +578,17 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
584578
if (!ent.nr) {
585579
switch (blobs) {
586580
case 0:
587-
result = builtin_diff_files(&rev, argc, argv);
581+
builtin_diff_files(&rev, argc, argv);
588582
break;
589583
case 1:
590584
if (paths != 1)
591585
usage(builtin_diff_usage);
592-
result = builtin_diff_b_f(&rev, argc, argv, blob);
586+
builtin_diff_b_f(&rev, argc, argv, blob);
593587
break;
594588
case 2:
595589
if (paths)
596590
usage(builtin_diff_usage);
597-
result = builtin_diff_blobs(&rev, argc, argv, blob);
591+
builtin_diff_blobs(&rev, argc, argv, blob);
598592
break;
599593
default:
600594
usage(builtin_diff_usage);
@@ -603,18 +597,18 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
603597
else if (blobs)
604598
usage(builtin_diff_usage);
605599
else if (ent.nr == 1)
606-
result = builtin_diff_index(&rev, argc, argv);
600+
builtin_diff_index(&rev, argc, argv);
607601
else if (ent.nr == 2) {
608602
if (sdiff.warn)
609603
warning(_("%s...%s: multiple merge bases, using %s"),
610604
sdiff.left, sdiff.right, sdiff.base);
611-
result = builtin_diff_tree(&rev, argc, argv,
612-
&ent.objects[0], &ent.objects[1]);
605+
builtin_diff_tree(&rev, argc, argv,
606+
&ent.objects[0], &ent.objects[1]);
613607
} else
614-
result = builtin_diff_combined(&rev, argc, argv,
615-
ent.objects, ent.nr,
616-
first_non_parent);
617-
result = diff_result_code(&rev.diffopt, result);
608+
builtin_diff_combined(&rev, argc, argv,
609+
ent.objects, ent.nr,
610+
first_non_parent);
611+
result = diff_result_code(&rev.diffopt, 0);
618612
if (1 < rev.diffopt.skip_stat_unmatch)
619613
refresh_index_quietly();
620614
release_revisions(&rev);

0 commit comments

Comments
 (0)