[PATCH 1/2] tree-diff: make diff_tree return void

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



diff_tree (which runs a diff between two trees) always returns 0 and
dies on errors.  Some day it may change to change it to return -1 on
error but it will be easy to adjust callers then and until then the
return value is just confusing.

This way at least callers are consistent in ignoring the return value
and new readers don't have to wonder if diff_tree returns its diff
result like "diff --exit-code" would.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 diff.h      |    2 +-
 revision.c  |    5 ++---
 tree-diff.c |   13 +++++--------
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/diff.h b/diff.h
index 007a055..4fde7f3 100644
--- a/diff.h
+++ b/diff.h
@@ -163,7 +163,7 @@ extern const char mime_boundary_leader[];
 
 extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
 extern void diff_tree_release_paths(struct diff_options *);
-extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
+extern void diff_tree(struct tree_desc *t1, struct tree_desc *t2,
 		     const char *base, struct diff_options *opt);
 extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
 			  const char *base, struct diff_options *opt);
diff --git a/revision.c b/revision.c
index 86d2470..a6e78c9 100644
--- a/revision.c
+++ b/revision.c
@@ -337,7 +337,6 @@ static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct
 
 static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
 {
-	int retval;
 	void *tree;
 	unsigned long size;
 	struct tree_desc empty, real;
@@ -354,10 +353,10 @@ static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
 
 	tree_difference = REV_TREE_SAME;
 	DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES);
-	retval = diff_tree(&empty, &real, "", &revs->pruning);
+	diff_tree(&empty, &real, "", &revs->pruning);
 	free(tree);
 
-	return retval >= 0 && (tree_difference == REV_TREE_SAME);
+	return tree_difference == REV_TREE_SAME;
 }
 
 static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
diff --git a/tree-diff.c b/tree-diff.c
index 3954281..d1a7ae9 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -138,7 +138,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
 	}
 }
 
-int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
+void diff_tree(struct tree_desc *t1, struct tree_desc *t2,
 	      const char *base_str, struct diff_options *opt)
 {
 	struct strbuf base;
@@ -190,7 +190,6 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
 	}
 
 	strbuf_release(&base);
-	return 0;
 }
 
 /*
@@ -285,7 +284,6 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
 	void *tree1, *tree2;
 	struct tree_desc t1, t2;
 	unsigned long size1, size2;
-	int retval;
 
 	tree1 = read_object_with_reference(old, tree_type, &size1, NULL);
 	if (!tree1)
@@ -295,7 +293,7 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
 		die("unable to read destination tree (%s)", sha1_to_hex(new));
 	init_tree_desc(&t1, tree1, size1);
 	init_tree_desc(&t2, tree2, size2);
-	retval = diff_tree(&t1, &t2, base, opt);
+	diff_tree(&t1, &t2, base, opt);
 	if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) {
 		init_tree_desc(&t1, tree1, size1);
 		init_tree_desc(&t2, tree2, size2);
@@ -303,12 +301,11 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
 	}
 	free(tree1);
 	free(tree2);
-	return retval;
+	return 0;
 }
 
 int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_options *opt)
 {
-	int retval;
 	void *tree;
 	unsigned long size;
 	struct tree_desc empty, real;
@@ -319,9 +316,9 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
 	init_tree_desc(&real, tree, size);
 
 	init_tree_desc(&empty, "", 0);
-	retval = diff_tree(&empty, &real, base, opt);
+	diff_tree(&empty, &real, base, opt);
 	free(tree);
-	return retval;
+	return 0;
 }
 
 void diff_tree_release_paths(struct diff_options *opt)
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]