add output file argument to got_diff_tree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
diff --git a/include/got_diff.h b/include/got_diff.h
index 78322cd..f7ac2b2 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -17,4 +17,4 @@
const struct got_error *got_diff_blob(struct got_blob_object *,
struct got_blob_object *, const char *, const char *, FILE *);
const struct got_error *got_diff_tree(struct got_tree_object *,
- struct got_tree_object *, struct got_repository *);
+ struct got_tree_object *, struct got_repository *, FILE *);
diff --git a/lib/diff.c b/lib/diff.c
index 0cb5c03..01ccbc4 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -134,7 +134,8 @@ match_entry_by_name(struct got_tree_entry *te1, struct got_tree_object *tree2)
}
static const struct got_error *
-diff_added_blob(struct got_object_id *id, struct got_repository *repo)
+diff_added_blob(struct got_object_id *id, struct got_repository *repo,
+ FILE *outfile)
{
const struct got_error *err;
struct got_blob_object *blob;
@@ -147,12 +148,12 @@ diff_added_blob(struct got_object_id *id, struct got_repository *repo)
if (err != NULL)
return err;
- return got_diff_blob(NULL, blob, NULL, NULL, stdout);
+ return got_diff_blob(NULL, blob, NULL, NULL, outfile);
}
static const struct got_error *
diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
- struct got_repository *repo)
+ struct got_repository *repo, FILE *outfile)
{
const struct got_error *err;
struct got_object *obj1 = NULL;
@@ -190,7 +191,7 @@ diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
goto done;
}
- err = got_diff_blob(blob1, blob2, NULL, NULL, stdout);
+ err = got_diff_blob(blob1, blob2, NULL, NULL, outfile);
done:
if (obj1)
@@ -205,7 +206,8 @@ done:
}
static const struct got_error *
-diff_deleted_blob(struct got_object_id *id, struct got_repository *repo)
+diff_deleted_blob(struct got_object_id *id, struct got_repository *repo,
+ FILE *outfile)
{
const struct got_error *err;
struct got_blob_object *blob;
@@ -218,11 +220,12 @@ diff_deleted_blob(struct got_object_id *id, struct got_repository *repo)
if (err != NULL)
return err;
- return got_diff_blob(blob, NULL, NULL, NULL, stdout);
+ return got_diff_blob(blob, NULL, NULL, NULL, outfile);
}
static const struct got_error *
-diff_added_tree(struct got_object_id *id, struct got_repository *repo)
+diff_added_tree(struct got_object_id *id, struct got_repository *repo,
+ FILE *outfile)
{
const struct got_error *err = NULL;
struct got_object *treeobj = NULL;
@@ -241,7 +244,7 @@ diff_added_tree(struct got_object_id *id, struct got_repository *repo)
if (err)
goto done;
- err = got_diff_tree(NULL, tree, repo);
+ err = got_diff_tree(NULL, tree, repo, outfile);
done:
if (tree)
@@ -253,7 +256,7 @@ done:
static const struct got_error *
diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
- struct got_repository *repo)
+ struct got_repository *repo, FILE *outfile)
{
const struct got_error *err = NULL;
struct got_object *treeobj1 = NULL;
@@ -287,7 +290,7 @@ diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
if (err)
goto done;
- err = got_diff_tree(tree1, tree2, repo);
+ err = got_diff_tree(tree1, tree2, repo, outfile);
done:
if (tree1)
@@ -302,7 +305,7 @@ done:
}
static const struct got_error *
-diff_deleted_tree(struct got_object_id *id, struct got_repository *repo)
+diff_deleted_tree(struct got_object_id *id, struct got_repository *repo, FILE *outfile)
{
const struct got_error *err = NULL;
struct got_object *treeobj = NULL;
@@ -321,7 +324,7 @@ diff_deleted_tree(struct got_object_id *id, struct got_repository *repo)
if (err)
goto done;
- err = got_diff_tree(tree, NULL, repo);
+ err = got_diff_tree(tree, NULL, repo, outfile);
done:
if (tree)
@@ -332,7 +335,8 @@ done:
}
static const struct got_error *
-diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2)
+diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2,
+ FILE *outfile)
{
/* XXX TODO */
return NULL;
@@ -340,7 +344,7 @@ diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2)
static const struct got_error *
diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2,
- struct got_repository *repo)
+ struct got_repository *repo, FILE *outfile)
{
const struct got_error *err;
struct got_tree_entry *te2;
@@ -349,24 +353,26 @@ diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2,
te2 = match_entry_by_name(te1, tree2);
if (te2 == NULL) {
if (S_ISDIR(te1->mode))
- return diff_deleted_tree(&te1->id, repo);
- return diff_deleted_blob(&te1->id, repo);
+ return diff_deleted_tree(&te1->id, repo, outfile);
+ return diff_deleted_blob(&te1->id, repo, outfile);
}
if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
if (got_object_id_cmp(&te1->id, &te2->id) != 0)
- return diff_modified_tree(&te1->id, &te2->id, repo);
+ return diff_modified_tree(&te1->id, &te2->id, repo,
+ outfile);
} else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
if (got_object_id_cmp(&te1->id, &te2->id) != 0)
- return diff_modified_blob(&te1->id, &te2->id, repo);
+ return diff_modified_blob(&te1->id, &te2->id, repo,
+ outfile);
}
- return diff_kind_mismatch(&te1->id, &te2->id);
+ return diff_kind_mismatch(&te1->id, &te2->id, outfile);
}
static const struct got_error *
diff_entry_new_old(struct got_tree_entry *te2, struct got_tree_object *tree1,
- struct got_repository *repo)
+ struct got_repository *repo, FILE *outfile)
{
const struct got_error *err;
struct got_tree_entry *te1;
@@ -376,13 +382,13 @@ diff_entry_new_old(struct got_tree_entry *te2, struct got_tree_object *tree1,
return NULL;
if (S_ISDIR(te2->mode))
- return diff_added_tree(&te2->id, repo);
- return diff_added_blob(&te2->id, repo);
+ return diff_added_tree(&te2->id, repo, outfile);
+ return diff_added_blob(&te2->id, repo, outfile);
}
const struct got_error *
got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
- struct got_repository *repo)
+ struct got_repository *repo, FILE *outfile)
{
const struct got_error *err = NULL;
struct got_tree_entry *te1 = NULL;
@@ -395,13 +401,13 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
do {
if (te1) {
- err = diff_entry_old_new(te1, tree2, repo);
+ err = diff_entry_old_new(te1, tree2, repo, outfile);
if (err)
break;
}
if (te2) {
- err = diff_entry_new_old(te2, tree1, repo);
+ err = diff_entry_new_old(te2, tree1, repo, outfile);
if (err)
break;
}
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index d3822a3..562ce42 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -385,7 +385,7 @@ repo_diff_tree(const char *repo_path)
return 0;
test_printf("\n");
- got_diff_tree(tree1, tree2, repo);
+ got_diff_tree(tree1, tree2, repo, stdout);
test_printf("\n");
got_object_tree_close(tree1);