Blame


1 7b19e0f1 2017-11-05 stsp /*
2 7b19e0f1 2017-11-05 stsp * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
3 7b19e0f1 2017-11-05 stsp *
4 7b19e0f1 2017-11-05 stsp * Permission to use, copy, modify, and distribute this software for any
5 7b19e0f1 2017-11-05 stsp * purpose with or without fee is hereby granted, provided that the above
6 7b19e0f1 2017-11-05 stsp * copyright notice and this permission notice appear in all copies.
7 7b19e0f1 2017-11-05 stsp *
8 7b19e0f1 2017-11-05 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7b19e0f1 2017-11-05 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7b19e0f1 2017-11-05 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7b19e0f1 2017-11-05 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7b19e0f1 2017-11-05 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7b19e0f1 2017-11-05 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7b19e0f1 2017-11-05 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7b19e0f1 2017-11-05 stsp */
16 7b19e0f1 2017-11-05 stsp
17 0ffeb3c2 2017-11-26 stsp #include <sys/stat.h>
18 d1cda826 2017-11-06 stsp #include <sys/queue.h>
19 d1cda826 2017-11-06 stsp
20 4027f31a 2017-11-04 stsp #include <stdio.h>
21 4027f31a 2017-11-04 stsp #include <stdlib.h>
22 4027f31a 2017-11-04 stsp #include <sha1.h>
23 68482ea3 2017-11-27 stsp #include <zlib.h>
24 4027f31a 2017-11-04 stsp
25 4027f31a 2017-11-04 stsp #include "got_error.h"
26 11995603 2017-11-05 stsp #include "got_object.h"
27 4027f31a 2017-11-04 stsp #include "got_refs.h"
28 4027f31a 2017-11-04 stsp #include "got_repository.h"
29 68482ea3 2017-11-27 stsp #include "got_sha1.h"
30 f78b0693 2017-11-29 stsp #include "got_diff.h"
31 4027f31a 2017-11-04 stsp
32 4027f31a 2017-11-04 stsp #define RUN_TEST(expr, name) \
33 a1fd68d8 2018-01-12 stsp if (!(expr)) { printf("test %s failed\n", (name)); failure = 1; }
34 4027f31a 2017-11-04 stsp
35 4027f31a 2017-11-04 stsp #define GOT_REPO_PATH "../../../"
36 4027f31a 2017-11-04 stsp
37 bfab4d9a 2017-11-12 stsp static const struct got_error *
38 bfab4d9a 2017-11-12 stsp print_commit_object(struct got_object *, struct got_repository *);
39 1c852fbe 2017-11-12 stsp
40 1c852fbe 2017-11-12 stsp static const struct got_error *
41 bfab4d9a 2017-11-12 stsp print_parent_commits(struct got_commit_object *commit,
42 bfab4d9a 2017-11-12 stsp struct got_repository *repo)
43 bfab4d9a 2017-11-12 stsp {
44 bfab4d9a 2017-11-12 stsp struct got_parent_id *pid;
45 bfab4d9a 2017-11-12 stsp const struct got_error *err;
46 bfab4d9a 2017-11-12 stsp struct got_object *obj;
47 bfab4d9a 2017-11-12 stsp
48 bfab4d9a 2017-11-12 stsp SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) {
49 bfab4d9a 2017-11-12 stsp err = got_object_open(&obj, repo, &pid->id);
50 bfab4d9a 2017-11-12 stsp if (err != NULL)
51 bfab4d9a 2017-11-12 stsp return err;
52 bfab4d9a 2017-11-12 stsp if (obj->type != GOT_OBJ_TYPE_COMMIT)
53 bfab4d9a 2017-11-12 stsp return got_error(GOT_ERR_OBJ_TYPE);
54 bfab4d9a 2017-11-12 stsp print_commit_object(obj, repo);
55 bfab4d9a 2017-11-12 stsp got_object_close(obj);
56 bfab4d9a 2017-11-12 stsp }
57 bfab4d9a 2017-11-12 stsp
58 bfab4d9a 2017-11-12 stsp return NULL;
59 bfab4d9a 2017-11-12 stsp }
60 bfab4d9a 2017-11-12 stsp
61 bfab4d9a 2017-11-12 stsp static const struct got_error *
62 f715ca7f 2017-11-27 stsp print_tree_object(struct got_object *obj, char *parent,
63 f715ca7f 2017-11-27 stsp struct got_repository *repo)
64 0ffeb3c2 2017-11-26 stsp {
65 0ffeb3c2 2017-11-26 stsp struct got_tree_object *tree;
66 f715ca7f 2017-11-27 stsp struct got_tree_entry *te;
67 0ffeb3c2 2017-11-26 stsp const struct got_error *err;
68 f715ca7f 2017-11-27 stsp char hex[SHA1_DIGEST_STRING_LENGTH];
69 0ffeb3c2 2017-11-26 stsp
70 0ffeb3c2 2017-11-26 stsp err = got_object_tree_open(&tree, repo, obj);
71 0ffeb3c2 2017-11-26 stsp if (err != NULL)
72 0ffeb3c2 2017-11-26 stsp return err;
73 0ffeb3c2 2017-11-26 stsp
74 f715ca7f 2017-11-27 stsp SIMPLEQ_FOREACH(te, &tree->entries, entry) {
75 f715ca7f 2017-11-27 stsp struct got_object *treeobj;
76 f715ca7f 2017-11-27 stsp char *next_parent;
77 f715ca7f 2017-11-27 stsp
78 f715ca7f 2017-11-27 stsp if (!S_ISDIR(te->mode)) {
79 f715ca7f 2017-11-27 stsp printf("%s %s/%s\n",
80 f715ca7f 2017-11-27 stsp got_object_id_str(&te->id, hex, sizeof(hex)),
81 f715ca7f 2017-11-27 stsp parent, te->name);
82 f715ca7f 2017-11-27 stsp continue;
83 f715ca7f 2017-11-27 stsp }
84 f715ca7f 2017-11-27 stsp printf("%s %s/%s\n",
85 f715ca7f 2017-11-27 stsp got_object_id_str(&te->id, hex, sizeof(hex)),
86 f715ca7f 2017-11-27 stsp parent, te->name);
87 f715ca7f 2017-11-27 stsp
88 f715ca7f 2017-11-27 stsp err = got_object_open(&treeobj, repo, &te->id);
89 f715ca7f 2017-11-27 stsp if (err != NULL)
90 f715ca7f 2017-11-27 stsp break;
91 f715ca7f 2017-11-27 stsp
92 f715ca7f 2017-11-27 stsp if (treeobj->type != GOT_OBJ_TYPE_TREE) {
93 f715ca7f 2017-11-27 stsp err = got_error(GOT_ERR_OBJ_TYPE);
94 f715ca7f 2017-11-27 stsp got_object_close(treeobj);
95 f715ca7f 2017-11-27 stsp break;
96 f715ca7f 2017-11-27 stsp }
97 f715ca7f 2017-11-27 stsp
98 f715ca7f 2017-11-27 stsp if (asprintf(&next_parent, "%s/%s", parent, te->name) == -1) {
99 f715ca7f 2017-11-27 stsp err = got_error(GOT_ERR_NO_MEM);
100 f715ca7f 2017-11-27 stsp got_object_close(treeobj);
101 f715ca7f 2017-11-27 stsp break;
102 f715ca7f 2017-11-27 stsp }
103 f715ca7f 2017-11-27 stsp
104 f715ca7f 2017-11-27 stsp err = print_tree_object(treeobj, next_parent, repo);
105 f715ca7f 2017-11-27 stsp free(next_parent);
106 f715ca7f 2017-11-27 stsp if (err) {
107 f715ca7f 2017-11-27 stsp got_object_close(treeobj);
108 f715ca7f 2017-11-27 stsp break;
109 f715ca7f 2017-11-27 stsp }
110 f715ca7f 2017-11-27 stsp
111 f715ca7f 2017-11-27 stsp got_object_close(treeobj);
112 f715ca7f 2017-11-27 stsp }
113 f715ca7f 2017-11-27 stsp
114 0ffeb3c2 2017-11-26 stsp got_object_tree_close(tree);
115 f715ca7f 2017-11-27 stsp return err;
116 0ffeb3c2 2017-11-26 stsp }
117 0ffeb3c2 2017-11-26 stsp
118 0ffeb3c2 2017-11-26 stsp static const struct got_error *
119 1c852fbe 2017-11-12 stsp print_commit_object(struct got_object *obj, struct got_repository *repo)
120 1c852fbe 2017-11-12 stsp {
121 1c852fbe 2017-11-12 stsp struct got_commit_object *commit;
122 1c852fbe 2017-11-12 stsp struct got_parent_id *pid;
123 1c852fbe 2017-11-12 stsp char buf[SHA1_DIGEST_STRING_LENGTH];
124 1c852fbe 2017-11-12 stsp const struct got_error *err;
125 0ffeb3c2 2017-11-26 stsp struct got_object* treeobj;
126 1c852fbe 2017-11-12 stsp
127 1c852fbe 2017-11-12 stsp err = got_object_commit_open(&commit, repo, obj);
128 1c852fbe 2017-11-12 stsp if (err != NULL)
129 1c852fbe 2017-11-12 stsp return err;
130 1c852fbe 2017-11-12 stsp
131 1c852fbe 2017-11-12 stsp printf("tree: %s\n",
132 1c852fbe 2017-11-12 stsp got_object_id_str(&commit->tree_id, buf, sizeof(buf)));
133 1c852fbe 2017-11-12 stsp printf("parent%s: ", (commit->nparents == 1) ? "" : "s");
134 1c852fbe 2017-11-12 stsp SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) {
135 1c852fbe 2017-11-12 stsp printf("%s\n",
136 1c852fbe 2017-11-12 stsp got_object_id_str(&pid->id, buf, sizeof(buf)));
137 1c852fbe 2017-11-12 stsp }
138 1c852fbe 2017-11-12 stsp printf("author: %s\n", commit->author);
139 1c852fbe 2017-11-12 stsp printf("committer: %s\n", commit->committer);
140 1c852fbe 2017-11-12 stsp printf("log: %s\n", commit->logmsg);
141 bfab4d9a 2017-11-12 stsp
142 0ffeb3c2 2017-11-26 stsp err = got_object_open(&treeobj, repo, &commit->tree_id);
143 0ffeb3c2 2017-11-26 stsp if (err != NULL)
144 0ffeb3c2 2017-11-26 stsp return err;
145 f715ca7f 2017-11-27 stsp if (treeobj->type == GOT_OBJ_TYPE_TREE) {
146 f715ca7f 2017-11-27 stsp print_tree_object(treeobj, "", repo);
147 f715ca7f 2017-11-27 stsp printf("\n");
148 f715ca7f 2017-11-27 stsp }
149 0ffeb3c2 2017-11-26 stsp got_object_close(treeobj);
150 0ffeb3c2 2017-11-26 stsp
151 bfab4d9a 2017-11-12 stsp err = print_parent_commits(commit, repo);
152 1c852fbe 2017-11-12 stsp got_object_commit_close(commit);
153 1c852fbe 2017-11-12 stsp
154 bfab4d9a 2017-11-12 stsp return err;
155 1c852fbe 2017-11-12 stsp }
156 1c852fbe 2017-11-12 stsp
157 4027f31a 2017-11-04 stsp static int
158 bfab4d9a 2017-11-12 stsp repo_read_log(const char *repo_path)
159 11995603 2017-11-05 stsp {
160 11995603 2017-11-05 stsp const struct got_error *err;
161 11995603 2017-11-05 stsp struct got_repository *repo;
162 11995603 2017-11-05 stsp struct got_reference *head_ref;
163 11995603 2017-11-05 stsp struct got_object_id *id;
164 ab9a70b2 2017-11-06 stsp struct got_object *obj;
165 d71d75ad 2017-11-05 stsp char buf[SHA1_DIGEST_STRING_LENGTH];
166 11995603 2017-11-05 stsp int ret;
167 11995603 2017-11-05 stsp
168 11995603 2017-11-05 stsp err = got_repo_open(&repo, repo_path);
169 11995603 2017-11-05 stsp if (err != NULL || repo == NULL)
170 11995603 2017-11-05 stsp return 0;
171 11995603 2017-11-05 stsp err = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
172 11995603 2017-11-05 stsp if (err != NULL || head_ref == NULL)
173 11995603 2017-11-05 stsp return 0;
174 11995603 2017-11-05 stsp err = got_ref_resolve(&id, repo, head_ref);
175 11995603 2017-11-05 stsp if (err != NULL || head_ref == NULL)
176 11995603 2017-11-05 stsp return 0;
177 d71d75ad 2017-11-05 stsp printf("HEAD is at %s\n", got_object_id_str(id, buf, sizeof(buf)));
178 ab9a70b2 2017-11-06 stsp err = got_object_open(&obj, repo, id);
179 ab9a70b2 2017-11-06 stsp if (err != NULL || obj == NULL)
180 ab9a70b2 2017-11-06 stsp return 0;
181 1c852fbe 2017-11-12 stsp if (obj->type == GOT_OBJ_TYPE_COMMIT)
182 1c852fbe 2017-11-12 stsp print_commit_object(obj, repo);
183 ab9a70b2 2017-11-06 stsp got_object_close(obj);
184 11995603 2017-11-05 stsp free(id);
185 11995603 2017-11-05 stsp got_ref_close(head_ref);
186 11995603 2017-11-05 stsp got_repo_close(repo);
187 11995603 2017-11-05 stsp return 1;
188 11995603 2017-11-05 stsp }
189 11995603 2017-11-05 stsp
190 68482ea3 2017-11-27 stsp static int
191 68482ea3 2017-11-27 stsp repo_read_blob(const char *repo_path)
192 68482ea3 2017-11-27 stsp {
193 68482ea3 2017-11-27 stsp const char *blob_sha1 = "141f5fdc96126c1f4195558560a3c915e3d9b4c3";
194 68482ea3 2017-11-27 stsp const struct got_error *err;
195 68482ea3 2017-11-27 stsp struct got_repository *repo;
196 68482ea3 2017-11-27 stsp struct got_object_id id;
197 68482ea3 2017-11-27 stsp struct got_object *obj;
198 68482ea3 2017-11-27 stsp struct got_blob_object *blob;
199 68482ea3 2017-11-27 stsp char hex[SHA1_DIGEST_STRING_LENGTH];
200 68482ea3 2017-11-27 stsp int i;
201 68482ea3 2017-11-27 stsp size_t len;
202 68482ea3 2017-11-27 stsp
203 68482ea3 2017-11-27 stsp if (!got_parse_sha1_digest(id.sha1, blob_sha1))
204 68482ea3 2017-11-27 stsp return 0;
205 68482ea3 2017-11-27 stsp
206 68482ea3 2017-11-27 stsp err = got_repo_open(&repo, repo_path);
207 68482ea3 2017-11-27 stsp if (err != NULL || repo == NULL)
208 68482ea3 2017-11-27 stsp return 0;
209 68482ea3 2017-11-27 stsp err = got_object_open(&obj, repo, &id);
210 68482ea3 2017-11-27 stsp if (err != NULL || obj == NULL)
211 68482ea3 2017-11-27 stsp return 0;
212 68482ea3 2017-11-27 stsp if (obj->type != GOT_OBJ_TYPE_BLOB)
213 68482ea3 2017-11-27 stsp return 0;
214 68482ea3 2017-11-27 stsp
215 68482ea3 2017-11-27 stsp err = got_object_blob_open(&blob, repo, obj, 64);
216 68482ea3 2017-11-27 stsp if (err != NULL)
217 68482ea3 2017-11-27 stsp return 0;
218 68482ea3 2017-11-27 stsp
219 68482ea3 2017-11-27 stsp putchar('\n');
220 68482ea3 2017-11-27 stsp do {
221 68482ea3 2017-11-27 stsp err = got_object_blob_read_block(blob, &len);
222 68482ea3 2017-11-27 stsp if (err)
223 68482ea3 2017-11-27 stsp break;
224 68482ea3 2017-11-27 stsp for (i = 0; i < len; i++)
225 68482ea3 2017-11-27 stsp putchar(blob->zb.outbuf[i]);
226 68482ea3 2017-11-27 stsp } while (len != 0);
227 68482ea3 2017-11-27 stsp putchar('\n');
228 68482ea3 2017-11-27 stsp
229 68482ea3 2017-11-27 stsp got_object_blob_close(blob);
230 68482ea3 2017-11-27 stsp got_object_close(obj);
231 7d283eee 2017-11-29 stsp got_repo_close(repo);
232 7d283eee 2017-11-29 stsp return (err == NULL);
233 7d283eee 2017-11-29 stsp }
234 7d283eee 2017-11-29 stsp
235 7d283eee 2017-11-29 stsp static int
236 7d283eee 2017-11-29 stsp repo_diff_blob(const char *repo_path)
237 7d283eee 2017-11-29 stsp {
238 7d283eee 2017-11-29 stsp const char *blob1_sha1 = "141f5fdc96126c1f4195558560a3c915e3d9b4c3";
239 7d283eee 2017-11-29 stsp const char *blob2_sha1 = "de7eb21b21c7823a753261aadf7cba35c9580fbf";
240 7d283eee 2017-11-29 stsp const struct got_error *err;
241 7d283eee 2017-11-29 stsp struct got_repository *repo;
242 7d283eee 2017-11-29 stsp struct got_object_id id1;
243 7d283eee 2017-11-29 stsp struct got_object_id id2;
244 7d283eee 2017-11-29 stsp struct got_object *obj1;
245 7d283eee 2017-11-29 stsp struct got_object *obj2;
246 7d283eee 2017-11-29 stsp struct got_blob_object *blob1;
247 7d283eee 2017-11-29 stsp struct got_blob_object *blob2;
248 7d283eee 2017-11-29 stsp char hex[SHA1_DIGEST_STRING_LENGTH];
249 7d283eee 2017-11-29 stsp int i;
250 7d283eee 2017-11-29 stsp size_t len;
251 7d283eee 2017-11-29 stsp
252 7d283eee 2017-11-29 stsp if (!got_parse_sha1_digest(id1.sha1, blob1_sha1))
253 7d283eee 2017-11-29 stsp return 0;
254 7d283eee 2017-11-29 stsp if (!got_parse_sha1_digest(id2.sha1, blob2_sha1))
255 7d283eee 2017-11-29 stsp return 0;
256 7d283eee 2017-11-29 stsp
257 7d283eee 2017-11-29 stsp err = got_repo_open(&repo, repo_path);
258 7d283eee 2017-11-29 stsp if (err != NULL || repo == NULL)
259 7d283eee 2017-11-29 stsp return 0;
260 7d283eee 2017-11-29 stsp
261 7d283eee 2017-11-29 stsp err = got_object_open(&obj1, repo, &id1);
262 7d283eee 2017-11-29 stsp if (err != NULL || obj1 == NULL)
263 7d283eee 2017-11-29 stsp return 0;
264 7d283eee 2017-11-29 stsp if (obj1->type != GOT_OBJ_TYPE_BLOB)
265 7d283eee 2017-11-29 stsp return 0;
266 7d283eee 2017-11-29 stsp err = got_object_open(&obj2, repo, &id2);
267 7d283eee 2017-11-29 stsp if (err != NULL || obj2 == NULL)
268 7d283eee 2017-11-29 stsp return 0;
269 7d283eee 2017-11-29 stsp if (obj2->type != GOT_OBJ_TYPE_BLOB)
270 7d283eee 2017-11-29 stsp return 0;
271 7d283eee 2017-11-29 stsp
272 7d283eee 2017-11-29 stsp err = got_object_blob_open(&blob1, repo, obj1, 512);
273 7d283eee 2017-11-29 stsp if (err != NULL)
274 7d283eee 2017-11-29 stsp return 0;
275 7d283eee 2017-11-29 stsp
276 7d283eee 2017-11-29 stsp err = got_object_blob_open(&blob2, repo, obj2, 512);
277 7d283eee 2017-11-29 stsp if (err != NULL)
278 7d283eee 2017-11-29 stsp return 0;
279 7d283eee 2017-11-29 stsp
280 7d283eee 2017-11-29 stsp putchar('\n');
281 62136d3a 2017-11-29 stsp got_diff_blob(blob1, blob2, NULL, NULL, stdout);
282 7d283eee 2017-11-29 stsp putchar('\n');
283 7d283eee 2017-11-29 stsp
284 7d283eee 2017-11-29 stsp got_object_blob_close(blob1);
285 7d283eee 2017-11-29 stsp got_object_blob_close(blob2);
286 98abbc84 2017-11-30 stsp got_object_close(obj1);
287 98abbc84 2017-11-30 stsp got_object_close(obj2);
288 98abbc84 2017-11-30 stsp got_repo_close(repo);
289 98abbc84 2017-11-30 stsp return (err == NULL);
290 98abbc84 2017-11-30 stsp }
291 98abbc84 2017-11-30 stsp
292 98abbc84 2017-11-30 stsp static int
293 98abbc84 2017-11-30 stsp repo_diff_tree(const char *repo_path)
294 98abbc84 2017-11-30 stsp {
295 4a0235dd 2017-11-30 stsp const char *tree1_sha1 = "1efc41caf761a0a1f119d0c5121eedcb2e7a88c3";
296 a3e2cbea 2017-12-01 stsp const char *tree2_sha1 = "4aa8f2933839ff8a8fb3f905a4c232d22c6ff5f3";
297 98abbc84 2017-11-30 stsp const struct got_error *err;
298 98abbc84 2017-11-30 stsp struct got_repository *repo;
299 98abbc84 2017-11-30 stsp struct got_object_id id1;
300 98abbc84 2017-11-30 stsp struct got_object_id id2;
301 98abbc84 2017-11-30 stsp struct got_object *obj1;
302 98abbc84 2017-11-30 stsp struct got_object *obj2;
303 98abbc84 2017-11-30 stsp struct got_tree_object *tree1;
304 98abbc84 2017-11-30 stsp struct got_tree_object *tree2;
305 98abbc84 2017-11-30 stsp char hex[SHA1_DIGEST_STRING_LENGTH];
306 98abbc84 2017-11-30 stsp int i;
307 98abbc84 2017-11-30 stsp size_t len;
308 98abbc84 2017-11-30 stsp
309 4a0235dd 2017-11-30 stsp if (!got_parse_sha1_digest(id1.sha1, tree1_sha1))
310 98abbc84 2017-11-30 stsp return 0;
311 4a0235dd 2017-11-30 stsp if (!got_parse_sha1_digest(id2.sha1, tree2_sha1))
312 98abbc84 2017-11-30 stsp return 0;
313 98abbc84 2017-11-30 stsp
314 98abbc84 2017-11-30 stsp err = got_repo_open(&repo, repo_path);
315 98abbc84 2017-11-30 stsp if (err != NULL || repo == NULL)
316 98abbc84 2017-11-30 stsp return 0;
317 98abbc84 2017-11-30 stsp
318 98abbc84 2017-11-30 stsp err = got_object_open(&obj1, repo, &id1);
319 98abbc84 2017-11-30 stsp if (err != NULL || obj1 == NULL)
320 98abbc84 2017-11-30 stsp return 0;
321 98abbc84 2017-11-30 stsp if (obj1->type != GOT_OBJ_TYPE_TREE)
322 98abbc84 2017-11-30 stsp return 0;
323 98abbc84 2017-11-30 stsp err = got_object_open(&obj2, repo, &id2);
324 98abbc84 2017-11-30 stsp if (err != NULL || obj2 == NULL)
325 98abbc84 2017-11-30 stsp return 0;
326 98abbc84 2017-11-30 stsp if (obj2->type != GOT_OBJ_TYPE_TREE)
327 98abbc84 2017-11-30 stsp return 0;
328 98abbc84 2017-11-30 stsp
329 98abbc84 2017-11-30 stsp err = got_object_tree_open(&tree1, repo, obj1);
330 98abbc84 2017-11-30 stsp if (err != NULL)
331 98abbc84 2017-11-30 stsp return 0;
332 98abbc84 2017-11-30 stsp
333 98abbc84 2017-11-30 stsp err = got_object_tree_open(&tree2, repo, obj2);
334 98abbc84 2017-11-30 stsp if (err != NULL)
335 98abbc84 2017-11-30 stsp return 0;
336 98abbc84 2017-11-30 stsp
337 98abbc84 2017-11-30 stsp putchar('\n');
338 98abbc84 2017-11-30 stsp got_diff_tree(tree1, tree2, repo);
339 98abbc84 2017-11-30 stsp putchar('\n');
340 98abbc84 2017-11-30 stsp
341 98abbc84 2017-11-30 stsp got_object_tree_close(tree1);
342 98abbc84 2017-11-30 stsp got_object_tree_close(tree2);
343 7d283eee 2017-11-29 stsp got_object_close(obj1);
344 7d283eee 2017-11-29 stsp got_object_close(obj2);
345 68482ea3 2017-11-27 stsp got_repo_close(repo);
346 68482ea3 2017-11-27 stsp return (err == NULL);
347 68482ea3 2017-11-27 stsp }
348 68482ea3 2017-11-27 stsp
349 4027f31a 2017-11-04 stsp int
350 4027f31a 2017-11-04 stsp main(int argc, const char *argv[])
351 4027f31a 2017-11-04 stsp {
352 4027f31a 2017-11-04 stsp int failure = 0;
353 4027f31a 2017-11-04 stsp const char *repo_path;
354 4027f31a 2017-11-04 stsp
355 4027f31a 2017-11-04 stsp if (argc == 1)
356 4027f31a 2017-11-04 stsp repo_path = GOT_REPO_PATH;
357 4027f31a 2017-11-04 stsp else if (argc == 2)
358 4027f31a 2017-11-04 stsp repo_path = argv[1];
359 4027f31a 2017-11-04 stsp else {
360 4027f31a 2017-11-04 stsp fprintf(stderr, "usage: repository_test [REPO_PATH]\n");
361 4027f31a 2017-11-04 stsp return 1;
362 4027f31a 2017-11-04 stsp }
363 4027f31a 2017-11-04 stsp
364 bfab4d9a 2017-11-12 stsp RUN_TEST(repo_read_log(repo_path), "read_log");
365 68482ea3 2017-11-27 stsp RUN_TEST(repo_read_blob(repo_path), "read_blob");
366 7d283eee 2017-11-29 stsp RUN_TEST(repo_diff_blob(repo_path), "diff_blob");
367 98abbc84 2017-11-30 stsp RUN_TEST(repo_diff_tree(repo_path), "diff_tree");
368 4027f31a 2017-11-04 stsp
369 4027f31a 2017-11-04 stsp return failure ? 1 : 0;
370 4027f31a 2017-11-04 stsp }