Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <sys/queue.h>
20 #include <sys/uio.h>
21 #include <sys/socket.h>
22 #include <sys/wait.h>
23 #include <sys/syslimits.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdint.h>
31 #include <sha1.h>
32 #include <zlib.h>
33 #include <ctype.h>
34 #include <limits.h>
35 #include <imsg.h>
36 #include <time.h>
38 #include "got_error.h"
39 #include "got_object.h"
40 #include "got_repository.h"
41 #include "got_opentemp.h"
43 #include "got_lib_sha1.h"
44 #include "got_lib_delta.h"
45 #include "got_lib_pack.h"
46 #include "got_lib_path.h"
47 #include "got_lib_inflate.h"
48 #include "got_lib_object.h"
49 #include "got_lib_privsep.h"
50 #include "got_lib_object_idcache.h"
51 #include "got_lib_object_cache.h"
52 #include "got_lib_object_parse.h"
53 #include "got_lib_repository.h"
55 #ifndef MIN
56 #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
57 #endif
59 int
60 got_object_id_cmp(struct got_object_id *id1, struct got_object_id *id2)
61 {
62 return memcmp(id1->sha1, id2->sha1, SHA1_DIGEST_LENGTH);
63 }
65 struct got_object_id *
66 got_object_id_dup(struct got_object_id *id1)
67 {
68 struct got_object_id *id2;
70 id2 = malloc(sizeof(*id2));
71 if (id2 == NULL)
72 return NULL;
73 memcpy(id2, id1, sizeof(*id2));
74 return id2;
75 }
77 struct got_object_id *
78 got_object_get_id(struct got_object *obj)
79 {
80 return &obj->id;
81 }
83 const struct got_error *
84 got_object_get_id_str(char **outbuf, struct got_object *obj)
85 {
86 return got_object_id_str(outbuf, &obj->id);
87 }
89 int
90 got_object_get_type(struct got_object *obj)
91 {
92 switch (obj->type) {
93 case GOT_OBJ_TYPE_COMMIT:
94 case GOT_OBJ_TYPE_TREE:
95 case GOT_OBJ_TYPE_BLOB:
96 case GOT_OBJ_TYPE_TAG:
97 return obj->type;
98 default:
99 abort();
100 break;
103 /* not reached */
104 return 0;
107 static const struct got_error *
108 object_path(char **path, struct got_object_id *id, struct got_repository *repo)
110 const struct got_error *err = NULL;
111 char *hex = NULL;
112 char *path_objects = got_repo_get_path_objects(repo);
114 *path = NULL;
116 if (path_objects == NULL)
117 return got_error_from_errno();
119 err = got_object_id_str(&hex, id);
120 if (err)
121 goto done;
123 if (asprintf(path, "%s/%.2x/%s", path_objects,
124 id->sha1[0], hex + 2) == -1)
125 err = got_error_from_errno();
127 done:
128 free(hex);
129 free(path_objects);
130 return err;
133 static const struct got_error *
134 open_loose_object(int *fd, struct got_object *obj, struct got_repository *repo)
136 const struct got_error *err = NULL;
137 char *path;
139 err = object_path(&path, &obj->id, repo);
140 if (err)
141 return err;
142 *fd = open(path, O_RDONLY | O_NOFOLLOW, GOT_DEFAULT_FILE_MODE);
143 if (*fd == -1) {
144 err = got_error_from_errno();
145 goto done;
147 done:
148 free(path);
149 return err;
152 static const struct got_error *
153 get_packfile_path(char **path_packfile, struct got_packidx *packidx)
155 size_t size;
157 /* Packfile path contains ".pack" instead of ".idx", so add one byte. */
158 size = strlen(packidx->path_packidx) + 2;
159 if (size < GOT_PACKFILE_NAMELEN + 1)
160 return got_error(GOT_ERR_BAD_PATH);
162 *path_packfile = calloc(size, sizeof(**path_packfile));
163 if (*path_packfile == NULL)
164 return got_error_from_errno();
166 /* Copy up to and excluding ".idx". */
167 if (strlcpy(*path_packfile, packidx->path_packidx,
168 size - strlen(GOT_PACKIDX_SUFFIX) - 1) >= size)
169 return got_error(GOT_ERR_NO_SPACE);
171 if (strlcat(*path_packfile, GOT_PACKFILE_SUFFIX, size) >= size)
172 return got_error(GOT_ERR_NO_SPACE);
174 return NULL;
177 static const struct got_error *
178 open_packed_object(struct got_object **obj, struct got_object_id *id,
179 struct got_repository *repo)
181 const struct got_error *err = NULL;
182 struct got_pack *pack = NULL;
183 struct got_packidx *packidx = NULL;
184 int idx;
185 char *path_packfile;
187 err = got_repo_search_packidx(&packidx, &idx, repo, id);
188 if (err)
189 return err;
191 err = get_packfile_path(&path_packfile, packidx);
192 if (err)
193 return err;
195 pack = got_repo_get_cached_pack(repo, path_packfile);
196 if (pack == NULL) {
197 err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
198 if (err)
199 goto done;
202 err = got_object_packed_read_privsep(obj, repo, pack, packidx, idx, id);
203 if (err)
204 goto done;
206 err = got_repo_cache_pack(NULL, repo, (*obj)->path_packfile, packidx);
207 done:
208 free(path_packfile);
209 return err;
212 const struct got_error *
213 got_object_open(struct got_object **obj, struct got_repository *repo,
214 struct got_object_id *id)
216 const struct got_error *err = NULL;
217 char *path;
218 int fd;
220 *obj = got_repo_get_cached_object(repo, id);
221 if (*obj != NULL) {
222 (*obj)->refcnt++;
223 return NULL;
226 err = open_packed_object(obj, id, repo);
227 if (err && err->code != GOT_ERR_NO_OBJ)
228 return err;
229 if (*obj) {
230 (*obj)->refcnt++;
231 return got_repo_cache_object(repo, id, *obj);
234 err = object_path(&path, id, repo);
235 if (err)
236 return err;
238 fd = open(path, O_RDONLY | O_NOFOLLOW, GOT_DEFAULT_FILE_MODE);
239 if (fd == -1) {
240 if (errno == ENOENT)
241 err = got_error(GOT_ERR_NO_OBJ);
242 else
243 err = got_error_from_errno();
244 goto done;
245 } else {
246 err = got_object_read_header_privsep(obj, repo, fd);
247 if (err)
248 goto done;
249 memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
252 (*obj)->refcnt++;
253 err = got_repo_cache_object(repo, id, *obj);
254 done:
255 free(path);
256 if (fd != -1)
257 close(fd);
258 return err;
262 const struct got_error *
263 got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
264 const char *id_str)
266 struct got_object_id id;
268 if (!got_parse_sha1_digest(id.sha1, id_str))
269 return got_error(GOT_ERR_BAD_OBJ_ID_STR);
271 return got_object_open(obj, repo, &id);
274 static const struct got_error *
275 open_commit(struct got_commit_object **commit,
276 struct got_repository *repo, struct got_object *obj, int check_cache)
278 const struct got_error *err = NULL;
280 if (check_cache) {
281 *commit = got_repo_get_cached_commit(repo, &obj->id);
282 if (*commit != NULL) {
283 (*commit)->refcnt++;
284 return NULL;
286 } else
287 *commit = NULL;
289 if (obj->type != GOT_OBJ_TYPE_COMMIT)
290 return got_error(GOT_ERR_OBJ_TYPE);
292 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
293 struct got_pack *pack;
294 pack = got_repo_get_cached_pack(repo, obj->path_packfile);
295 if (pack == NULL) {
296 err = got_repo_cache_pack(&pack, repo,
297 obj->path_packfile, NULL);
298 if (err)
299 return err;
301 err = got_object_read_packed_commit_privsep(commit, obj, pack);
302 } else {
303 int fd;
304 err = open_loose_object(&fd, obj, repo);
305 if (err)
306 return err;
307 err = got_object_read_commit_privsep(commit, obj, fd, repo);
308 close(fd);
311 if (err == NULL) {
312 (*commit)->refcnt++;
313 err = got_repo_cache_commit(repo, &obj->id, *commit);
316 return err;
319 const struct got_error *
320 got_object_open_as_commit(struct got_commit_object **commit,
321 struct got_repository *repo, struct got_object_id *id)
323 const struct got_error *err;
324 struct got_object *obj;
326 *commit = got_repo_get_cached_commit(repo, id);
327 if (*commit != NULL) {
328 (*commit)->refcnt++;
329 return NULL;
332 err = got_object_open(&obj, repo, id);
333 if (err)
334 return err;
335 if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
336 err = got_error(GOT_ERR_OBJ_TYPE);
337 goto done;
340 err = open_commit(commit, repo, obj, 0);
341 done:
342 got_object_close(obj);
343 return err;
346 const struct got_error *
347 got_object_commit_open(struct got_commit_object **commit,
348 struct got_repository *repo, struct got_object *obj)
350 return open_commit(commit, repo, obj, 1);
353 const struct got_error *
354 got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
356 const struct got_error *err = NULL;
358 *qid = calloc(1, sizeof(**qid));
359 if (*qid == NULL)
360 return got_error_from_errno();
362 (*qid)->id = got_object_id_dup(id);
363 if ((*qid)->id == NULL) {
364 err = got_error_from_errno();
365 got_object_qid_free(*qid);
366 *qid = NULL;
367 return err;
370 return NULL;
373 static const struct got_error *
374 open_tree(struct got_tree_object **tree,
375 struct got_repository *repo, struct got_object *obj, int check_cache)
377 const struct got_error *err = NULL;
379 if (check_cache) {
380 *tree = got_repo_get_cached_tree(repo, &obj->id);
381 if (*tree != NULL) {
382 (*tree)->refcnt++;
383 return NULL;
385 } else
386 *tree = NULL;
388 if (obj->type != GOT_OBJ_TYPE_TREE)
389 return got_error(GOT_ERR_OBJ_TYPE);
391 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
392 struct got_pack *pack;
393 pack = got_repo_get_cached_pack(repo, obj->path_packfile);
394 if (pack == NULL) {
395 err = got_repo_cache_pack(&pack, repo,
396 obj->path_packfile, NULL);
397 if (err)
398 return err;
400 err = got_object_read_packed_tree_privsep(tree, obj, pack);
401 } else {
402 int fd;
403 err = open_loose_object(&fd, obj, repo);
404 if (err)
405 return err;
406 err = got_object_read_tree_privsep(tree, obj, fd, repo);
407 close(fd);
410 if (err == NULL) {
411 (*tree)->refcnt++;
412 err = got_repo_cache_tree(repo, &obj->id, *tree);
415 return err;
418 const struct got_error *
419 got_object_open_as_tree(struct got_tree_object **tree,
420 struct got_repository *repo, struct got_object_id *id)
422 const struct got_error *err;
423 struct got_object *obj;
425 *tree = got_repo_get_cached_tree(repo, id);
426 if (*tree != NULL) {
427 (*tree)->refcnt++;
428 return NULL;
431 err = got_object_open(&obj, repo, id);
432 if (err)
433 return err;
434 if (got_object_get_type(obj) != GOT_OBJ_TYPE_TREE) {
435 err = got_error(GOT_ERR_OBJ_TYPE);
436 goto done;
439 err = open_tree(tree, repo, obj, 0);
440 done:
441 got_object_close(obj);
442 return err;
445 const struct got_error *
446 got_object_tree_open(struct got_tree_object **tree,
447 struct got_repository *repo, struct got_object *obj)
449 return open_tree(tree, repo, obj, 1);
452 const struct got_tree_entries *
453 got_object_tree_get_entries(struct got_tree_object *tree)
455 return &tree->entries;
458 static const struct got_error *
459 read_packed_blob_privsep(size_t *size, int outfd, struct got_object *obj,
460 struct got_pack *pack)
462 const struct got_error *err = NULL;
463 int outfd_child;
464 int basefd, accumfd; /* temporary files for delta application */
466 basefd = got_opentempfd();
467 if (basefd == -1)
468 return got_error_from_errno();
469 accumfd = got_opentempfd();
470 if (accumfd == -1)
471 return got_error_from_errno();
473 outfd_child = dup(outfd);
474 if (outfd_child == -1)
475 return got_error_from_errno();
477 err = got_privsep_send_obj_req(pack->privsep_child->ibuf, -1, obj);
478 if (err)
479 return err;
481 err = got_privsep_send_blob_outfd(pack->privsep_child->ibuf,
482 outfd_child);
483 if (err) {
484 close(outfd_child);
485 return err;
487 err = got_privsep_send_tmpfd(pack->privsep_child->ibuf,
488 basefd);
489 if (err) {
490 close(basefd);
491 close(accumfd);
492 close(outfd_child);
493 return err;
496 err = got_privsep_send_tmpfd(pack->privsep_child->ibuf,
497 accumfd);
498 if (err) {
499 close(accumfd);
500 close(outfd_child);
501 return err;
504 err = got_privsep_recv_blob(size, pack->privsep_child->ibuf);
505 if (err)
506 return err;
508 if (lseek(outfd, SEEK_SET, 0) == -1)
509 err = got_error_from_errno();
511 return err;
514 const struct got_error *
515 got_object_blob_open(struct got_blob_object **blob,
516 struct got_repository *repo, struct got_object *obj, size_t blocksize)
518 const struct got_error *err = NULL;
519 int outfd;
520 size_t size;
521 struct stat sb;
523 if (obj->type != GOT_OBJ_TYPE_BLOB)
524 return got_error(GOT_ERR_OBJ_TYPE);
526 if (blocksize < obj->hdrlen)
527 return got_error(GOT_ERR_NO_SPACE);
529 *blob = calloc(1, sizeof(**blob));
530 if (*blob == NULL)
531 return got_error_from_errno();
533 outfd = got_opentempfd();
534 if (outfd == -1)
535 return got_error_from_errno();
537 (*blob)->read_buf = malloc(blocksize);
538 if ((*blob)->read_buf == NULL) {
539 err = got_error_from_errno();
540 goto done;
542 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
543 struct got_pack *pack;
544 pack = got_repo_get_cached_pack(repo, obj->path_packfile);
545 if (pack == NULL) {
546 err = got_repo_cache_pack(&pack, repo,
547 obj->path_packfile, NULL);
548 if (err)
549 goto done;
551 err = read_packed_blob_privsep(&size, outfd, obj, pack);
552 if (err)
553 goto done;
554 obj->size = size;
555 } else {
556 int infd;
558 err = open_loose_object(&infd, obj, repo);
559 if (err)
560 goto done;
562 err = got_object_read_blob_privsep(&size, outfd, infd, repo);
563 close(infd);
564 if (err)
565 goto done;
567 if (size != obj->hdrlen + obj->size) {
568 err = got_error(GOT_ERR_PRIVSEP_LEN);
569 goto done;
573 if (fstat(outfd, &sb) == -1) {
574 err = got_error_from_errno();
575 goto done;
578 if (sb.st_size != obj->hdrlen + obj->size) {
579 err = got_error(GOT_ERR_PRIVSEP_LEN);
580 goto done;
583 (*blob)->f = fdopen(outfd, "rb");
584 if ((*blob)->f == NULL) {
585 err = got_error_from_errno();
586 close(outfd);
587 goto done;
590 (*blob)->hdrlen = obj->hdrlen;
591 (*blob)->blocksize = blocksize;
592 memcpy(&(*blob)->id.sha1, obj->id.sha1, SHA1_DIGEST_LENGTH);
594 done:
595 if (err) {
596 if (*blob) {
597 if ((*blob)->f)
598 fclose((*blob)->f);
599 free((*blob)->read_buf);
600 free(*blob);
601 *blob = NULL;
602 } else if (outfd != -1)
603 close(outfd);
605 return err;
608 const struct got_error *
609 got_object_open_as_blob(struct got_blob_object **blob,
610 struct got_repository *repo, struct got_object_id *id,
611 size_t blocksize)
613 const struct got_error *err;
614 struct got_object *obj;
616 *blob = NULL;
618 err = got_object_open(&obj, repo, id);
619 if (err)
620 return err;
621 if (got_object_get_type(obj) != GOT_OBJ_TYPE_BLOB) {
622 err = got_error(GOT_ERR_OBJ_TYPE);
623 goto done;
626 err = got_object_blob_open(blob, repo, obj, blocksize);
627 done:
628 got_object_close(obj);
629 return err;
632 void
633 got_object_blob_close(struct got_blob_object *blob)
635 free(blob->read_buf);
636 fclose(blob->f);
637 free(blob);
640 char *
641 got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
643 return got_sha1_digest_to_str(blob->id.sha1, buf, size);
646 size_t
647 got_object_blob_get_hdrlen(struct got_blob_object *blob)
649 return blob->hdrlen;
652 const uint8_t *
653 got_object_blob_get_read_buf(struct got_blob_object *blob)
655 return blob->read_buf;
658 const struct got_error *
659 got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
661 size_t n;
663 n = fread(blob->read_buf, 1, blob->blocksize, blob->f);
664 if (n == 0 && ferror(blob->f))
665 return got_ferror(blob->f, GOT_ERR_IO);
666 *outlenp = n;
667 return NULL;
670 const struct got_error *
671 got_object_blob_dump_to_file(size_t *total_len, size_t *nlines,
672 FILE *outfile, struct got_blob_object *blob)
674 const struct got_error *err = NULL;
675 size_t len, hdrlen;
676 const uint8_t *buf;
677 int i;
679 if (total_len)
680 *total_len = 0;
681 if (nlines)
682 *nlines = 0;
684 hdrlen = got_object_blob_get_hdrlen(blob);
685 do {
686 err = got_object_blob_read_block(&len, blob);
687 if (err)
688 return err;
689 if (len == 0)
690 break;
691 if (total_len)
692 *total_len += len;
693 buf = got_object_blob_get_read_buf(blob);
694 if (nlines) {
695 for (i = 0; i < len; i++) {
696 if (buf[i] == '\n')
697 (*nlines)++;
700 /* Skip blob object header first time around. */
701 fwrite(buf + hdrlen, len - hdrlen, 1, outfile);
702 hdrlen = 0;
703 } while (len != 0);
705 fflush(outfile);
706 rewind(outfile);
708 return NULL;
711 static struct got_tree_entry *
712 find_entry_by_name(struct got_tree_object *tree, const char *name, size_t len)
714 struct got_tree_entry *te;
716 SIMPLEQ_FOREACH(te, &tree->entries.head, entry) {
717 if (strncmp(te->name, name, len) == 0 && te->name[len] == '\0')
718 return te;
720 return NULL;
723 const struct got_error *
724 got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
725 struct got_object_id *commit_id, const char *path)
727 const struct got_error *err = NULL;
728 struct got_commit_object *commit = NULL;
729 struct got_tree_object *tree = NULL;
730 struct got_tree_entry *te = NULL;
731 const char *seg, *s;
732 size_t seglen, len = strlen(path);
734 *id = NULL;
736 /* We are expecting an absolute in-repository path. */
737 if (path[0] != '/')
738 return got_error(GOT_ERR_NOT_ABSPATH);
740 err = got_object_open_as_commit(&commit, repo, commit_id);
741 if (err)
742 goto done;
744 /* Handle opening of root of commit's tree. */
745 if (path[1] == '\0') {
746 *id = got_object_id_dup(commit->tree_id);
747 if (*id == NULL)
748 err = got_error_from_errno();
749 goto done;
752 err = got_object_open_as_tree(&tree, repo, commit->tree_id);
753 if (err)
754 goto done;
756 s = path;
757 s++; /* skip leading '/' */
758 len--;
759 seg = s;
760 seglen = 0;
761 while (len > 0) {
762 struct got_tree_object *next_tree;
764 if (*s != '/') {
765 s++;
766 len--;
767 seglen++;
768 if (*s)
769 continue;
772 te = find_entry_by_name(tree, seg, seglen);
773 if (te == NULL) {
774 err = got_error(GOT_ERR_NO_OBJ);
775 goto done;
778 if (len == 0)
779 break;
781 seg = s + 1;
782 seglen = 0;
783 s++;
784 len--;
785 if (*s) {
786 err = got_object_open_as_tree(&next_tree, repo,
787 te->id);
788 te = NULL;
789 if (err)
790 goto done;
791 got_object_tree_close(tree);
792 tree = next_tree;
796 if (te) {
797 *id = got_object_id_dup(te->id);
798 if (*id == NULL)
799 return got_error_from_errno();
800 } else
801 err = got_error(GOT_ERR_NO_OBJ);
802 done:
803 if (commit)
804 got_object_commit_close(commit);
805 if (tree)
806 got_object_tree_close(tree);
807 return err;
810 const struct got_error *
811 got_object_tree_path_changed(int *changed,
812 struct got_tree_object *tree01, struct got_tree_object *tree02,
813 const char *path, struct got_repository *repo)
815 const struct got_error *err = NULL;
816 struct got_tree_object *tree1 = NULL, *tree2 = NULL;
817 struct got_tree_entry *te1 = NULL, *te2 = NULL;
818 const char *seg, *s;
819 size_t seglen, len = strlen(path);
821 *changed = 0;
823 /* We are expecting an absolute in-repository path. */
824 if (path[0] != '/')
825 return got_error(GOT_ERR_NOT_ABSPATH);
827 /* We not do support comparing the root path. */
828 if (path[1] == '\0')
829 return got_error(GOT_ERR_BAD_PATH);
831 tree1 = tree01;
832 tree2 = tree02;
833 s = path;
834 s++; /* skip leading '/' */
835 len--;
836 seg = s;
837 seglen = 0;
838 while (len > 0) {
839 struct got_tree_object *next_tree1, *next_tree2;
841 if (*s != '/') {
842 s++;
843 len--;
844 seglen++;
845 if (*s)
846 continue;
849 te1 = find_entry_by_name(tree1, seg, seglen);
850 if (te1 == NULL) {
851 err = got_error(GOT_ERR_NO_OBJ);
852 goto done;
855 te2 = find_entry_by_name(tree2, seg, seglen);
856 if (te2 == NULL) {
857 *changed = 1;
858 goto done;
861 if (te1->mode != te2->mode) {
862 *changed = 1;
863 goto done;
866 if (got_object_id_cmp(te1->id, te2->id) == 0) {
867 *changed = 0;
868 goto done;
871 if (len == 0) { /* final path element */
872 *changed = 1;
873 goto done;
876 seg = s + 1;
877 s++;
878 len--;
879 seglen = 0;
880 if (*s) {
881 err = got_object_open_as_tree(&next_tree1, repo,
882 te1->id);
883 te1 = NULL;
884 if (err)
885 goto done;
886 if (tree1 != tree01)
887 got_object_tree_close(tree1);
888 tree1 = next_tree1;
890 err = got_object_open_as_tree(&next_tree2, repo,
891 te2->id);
892 te2 = NULL;
893 if (err)
894 goto done;
895 if (tree2 != tree02)
896 got_object_tree_close(tree2);
897 tree2 = next_tree2;
900 done:
901 if (tree1 && tree1 != tree01)
902 got_object_tree_close(tree1);
903 if (tree2 && tree2 != tree02)
904 got_object_tree_close(tree2);
905 return err;