Skip to content

Commit 0ee3cb8

Browse files
szedergitster
authored andcommitted
diff.h: drop diff_tree_oid() & friends' return value
ll_diff_tree_oid() has only ever returned 0 [1], so it's return value is basically useless. It's only caller diff_tree_oid() has only ever returned the return value of ll_diff_tree_oid() as-is [2], so its return value is just as useless. Most of diff_tree_oid()'s callers simply ignore its return value, except: - diff_root_tree_oid() is a thin wrapper around diff_tree_oid() and returns with its return value, but all of diff_root_tree_oid()'s callers ignore its return value. - rev_compare_tree() and rev_same_tree_as_empty() do look at the return value in a condition, but, since the return value is always 0, the former's < 0 condition is never fulfilled, while the latter's >= 0 condition is always fulfilled. So let's drop the return value of ll_diff_tree_oid(), diff_tree_oid() and diff_root_tree_oid(), and drop those conditions from rev_compare_tree() and rev_same_tree_as_empty() as well. [1] ll_diff_tree_oid() and its ancestors have been returning only 0 ever since it was introduced as diff_tree() in 9174026 (Add "diff-tree" program to show which files have changed between two trees., 2005-04-09). [2] diff_tree_oid() traces back to diff-tree.c:main() in 9174026 as well. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1df15f8 commit 0ee3cb8

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

diff.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ struct combine_diff_path *diff_tree_paths(
431431
struct combine_diff_path *p, const struct object_id *oid,
432432
const struct object_id **parents_oid, int nparent,
433433
struct strbuf *base, struct diff_options *opt);
434-
int diff_tree_oid(const struct object_id *old_oid,
435-
const struct object_id *new_oid,
436-
const char *base, struct diff_options *opt);
437-
int diff_root_tree_oid(const struct object_id *new_oid, const char *base,
438-
struct diff_options *opt);
434+
void diff_tree_oid(const struct object_id *old_oid,
435+
const struct object_id *new_oid,
436+
const char *base, struct diff_options *opt);
437+
void diff_root_tree_oid(const struct object_id *new_oid, const char *base,
438+
struct diff_options *opt);
439439

440440
struct combine_diff_path {
441441
struct combine_diff_path *next;

revision.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,7 @@ static int rev_compare_tree(struct rev_info *revs,
791791

792792
tree_difference = REV_TREE_SAME;
793793
revs->pruning.flags.has_changes = 0;
794-
if (diff_tree_oid(&t1->object.oid, &t2->object.oid, "",
795-
&revs->pruning) < 0)
796-
return REV_TREE_DIFFERENT;
794+
diff_tree_oid(&t1->object.oid, &t2->object.oid, "", &revs->pruning);
797795

798796
if (!nth_parent)
799797
if (bloom_ret == 1 && tree_difference == REV_TREE_SAME)
@@ -804,17 +802,16 @@ static int rev_compare_tree(struct rev_info *revs,
804802

805803
static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
806804
{
807-
int retval;
808805
struct tree *t1 = get_commit_tree(commit);
809806

810807
if (!t1)
811808
return 0;
812809

813810
tree_difference = REV_TREE_SAME;
814811
revs->pruning.flags.has_changes = 0;
815-
retval = diff_tree_oid(NULL, &t1->object.oid, "", &revs->pruning);
812+
diff_tree_oid(NULL, &t1->object.oid, "", &revs->pruning);
816813

817-
return retval >= 0 && (tree_difference == REV_TREE_SAME);
814+
return tree_difference == REV_TREE_SAME;
818815
}
819816

820817
struct treesame_state {

tree-diff.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ static struct combine_diff_path *ll_diff_tree_paths(
2929
struct combine_diff_path *p, const struct object_id *oid,
3030
const struct object_id **parents_oid, int nparent,
3131
struct strbuf *base, struct diff_options *opt);
32-
static int ll_diff_tree_oid(const struct object_id *old_oid,
33-
const struct object_id *new_oid,
34-
struct strbuf *base, struct diff_options *opt);
32+
static void ll_diff_tree_oid(const struct object_id *old_oid,
33+
const struct object_id *new_oid,
34+
struct strbuf *base, struct diff_options *opt);
3535

3636
/*
3737
* Compare two tree entries, taking into account only path/S_ISDIR(mode),
@@ -679,9 +679,9 @@ static void try_to_follow_renames(const struct object_id *old_oid,
679679
q->nr = 1;
680680
}
681681

682-
static int ll_diff_tree_oid(const struct object_id *old_oid,
683-
const struct object_id *new_oid,
684-
struct strbuf *base, struct diff_options *opt)
682+
static void ll_diff_tree_oid(const struct object_id *old_oid,
683+
const struct object_id *new_oid,
684+
struct strbuf *base, struct diff_options *opt)
685685
{
686686
struct combine_diff_path phead, *p;
687687
pathchange_fn_t pathchange_old = opt->pathchange;
@@ -697,29 +697,27 @@ static int ll_diff_tree_oid(const struct object_id *old_oid,
697697
}
698698

699699
opt->pathchange = pathchange_old;
700-
return 0;
701700
}
702701

703-
int diff_tree_oid(const struct object_id *old_oid,
704-
const struct object_id *new_oid,
705-
const char *base_str, struct diff_options *opt)
702+
void diff_tree_oid(const struct object_id *old_oid,
703+
const struct object_id *new_oid,
704+
const char *base_str, struct diff_options *opt)
706705
{
707706
struct strbuf base;
708-
int retval;
709707

710708
strbuf_init(&base, PATH_MAX);
711709
strbuf_addstr(&base, base_str);
712710

713-
retval = ll_diff_tree_oid(old_oid, new_oid, &base, opt);
711+
ll_diff_tree_oid(old_oid, new_oid, &base, opt);
714712
if (!*base_str && opt->flags.follow_renames && diff_might_be_rename())
715713
try_to_follow_renames(old_oid, new_oid, &base, opt);
716714

717715
strbuf_release(&base);
718-
719-
return retval;
720716
}
721717

722-
int diff_root_tree_oid(const struct object_id *new_oid, const char *base, struct diff_options *opt)
718+
void diff_root_tree_oid(const struct object_id *new_oid,
719+
const char *base,
720+
struct diff_options *opt)
723721
{
724-
return diff_tree_oid(NULL, new_oid, base, opt);
722+
diff_tree_oid(NULL, new_oid, base, opt);
725723
}

0 commit comments

Comments
 (0)