Blob


1 /*
2 * Copyright (c) 2018, 2019 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/tree.h>
21 #include <sys/uio.h>
22 #include <sys/mman.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sha1.h>
30 #include <unistd.h>
31 #include <zlib.h>
32 #include <libgen.h>
33 #include <limits.h>
34 #include <imsg.h>
36 #include "got_error.h"
37 #include "got_object.h"
38 #include "got_repository.h"
39 #include "got_opentemp.h"
40 #include "got_path.h"
42 #include "got_lib_sha1.h"
43 #include "got_lib_delta.h"
44 #include "got_lib_inflate.h"
45 #include "got_lib_object.h"
46 #include "got_lib_privsep.h"
47 #include "got_lib_object_idcache.h"
48 #include "got_lib_object_cache.h"
49 #include "got_lib_object_parse.h"
50 #include "got_lib_pack.h"
51 #include "got_lib_repository.h"
53 #ifndef MIN
54 #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
55 #endif
57 #ifndef nitems
58 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
59 #endif
61 struct got_object_id *
62 got_object_get_id(struct got_object *obj)
63 {
64 return &obj->id;
65 }
67 const struct got_error *
68 got_object_get_id_str(char **outbuf, struct got_object *obj)
69 {
70 return got_object_id_str(outbuf, &obj->id);
71 }
73 const struct got_error *
74 got_object_get_type(int *type, struct got_repository *repo,
75 struct got_object_id *id)
76 {
77 const struct got_error *err = NULL;
78 struct got_object *obj;
80 err = got_object_open(&obj, repo, id);
81 if (err)
82 return err;
84 switch (obj->type) {
85 case GOT_OBJ_TYPE_COMMIT:
86 case GOT_OBJ_TYPE_TREE:
87 case GOT_OBJ_TYPE_BLOB:
88 case GOT_OBJ_TYPE_TAG:
89 *type = obj->type;
90 break;
91 default:
92 err = got_error(GOT_ERR_OBJ_TYPE);
93 break;
94 }
96 got_object_close(obj);
97 return err;
98 }
100 const struct got_error *
101 got_object_get_path(char **path, struct got_object_id *id,
102 struct got_repository *repo)
104 const struct got_error *err = NULL;
105 char *hex = NULL;
106 char *path_objects;
108 *path = NULL;
110 path_objects = got_repo_get_path_objects(repo);
111 if (path_objects == NULL)
112 return got_error_from_errno("got_repo_get_path_objects");
114 err = got_object_id_str(&hex, id);
115 if (err)
116 goto done;
118 if (asprintf(path, "%s/%.2x/%s", path_objects,
119 id->sha1[0], hex + 2) == -1)
120 err = got_error_from_errno("asprintf");
122 done:
123 free(hex);
124 free(path_objects);
125 return err;
128 const struct got_error *
129 got_object_open_loose_fd(int *fd, struct got_object_id *id,
130 struct got_repository *repo)
132 const struct got_error *err = NULL;
133 char *path;
135 err = got_object_get_path(&path, id, repo);
136 if (err)
137 return err;
138 *fd = open(path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
139 if (*fd == -1) {
140 err = got_error_from_errno2("open", path);
141 goto done;
143 done:
144 free(path);
145 return err;
148 const struct got_error *
149 got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
150 const char *id_str)
152 struct got_object_id id;
154 if (!got_parse_sha1_digest(id.sha1, id_str))
155 return got_error_path(id_str, GOT_ERR_BAD_OBJ_ID_STR);
157 return got_object_open(obj, repo, &id);
160 const struct got_error *
161 got_object_resolve_id_str(struct got_object_id **id,
162 struct got_repository *repo, const char *id_str)
164 const struct got_error *err = NULL;
165 struct got_object *obj;
167 err = got_object_open_by_id_str(&obj, repo, id_str);
168 if (err)
169 return err;
171 *id = got_object_id_dup(got_object_get_id(obj));
172 got_object_close(obj);
173 if (*id == NULL)
174 return got_error_from_errno("got_object_id_dup");
176 return NULL;
179 const struct got_error *
180 got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
182 *qid = calloc(1, sizeof(**qid));
183 if (*qid == NULL)
184 return got_error_from_errno("calloc");
186 memcpy(&(*qid)->id, id, sizeof((*qid)->id));
187 return NULL;
190 const struct got_error *
191 got_object_id_queue_copy(const struct got_object_id_queue *src,
192 struct got_object_id_queue *dest)
194 const struct got_error *err;
195 struct got_object_qid *qid;
197 STAILQ_FOREACH(qid, src, entry) {
198 struct got_object_qid *new;
199 /*
200 * Deep-copy the object ID only. Let the caller deal
201 * with setting up the new->data pointer if needed.
202 */
203 err = got_object_qid_alloc(&new, &qid->id);
204 if (err) {
205 got_object_id_queue_free(dest);
206 return err;
208 STAILQ_INSERT_TAIL(dest, new, entry);
211 return NULL;
214 int
215 got_object_tree_get_nentries(struct got_tree_object *tree)
217 return tree->nentries;
220 struct got_tree_entry *
221 got_object_tree_get_first_entry(struct got_tree_object *tree)
223 return got_object_tree_get_entry(tree, 0);
226 struct got_tree_entry *
227 got_object_tree_get_last_entry(struct got_tree_object *tree)
229 return got_object_tree_get_entry(tree, tree->nentries - 1);
232 struct got_tree_entry *
233 got_object_tree_get_entry(struct got_tree_object *tree, int i)
235 if (i < 0 || i >= tree->nentries)
236 return NULL;
237 return &tree->entries[i];
240 mode_t
241 got_tree_entry_get_mode(struct got_tree_entry *te)
243 return te->mode;
246 const char *
247 got_tree_entry_get_name(struct got_tree_entry *te)
249 return &te->name[0];
252 struct got_object_id *
253 got_tree_entry_get_id(struct got_tree_entry *te)
255 return &te->id;
258 const struct got_error *
259 got_object_blob_read_to_str(char **s, struct got_blob_object *blob)
261 const struct got_error *err = NULL;
262 size_t len, totlen, hdrlen, offset;
264 *s = NULL;
266 hdrlen = got_object_blob_get_hdrlen(blob);
267 totlen = 0;
268 offset = 0;
269 do {
270 char *p;
272 err = got_object_blob_read_block(&len, blob);
273 if (err)
274 return err;
276 if (len == 0)
277 break;
279 totlen += len - hdrlen;
280 p = realloc(*s, totlen + 1);
281 if (p == NULL) {
282 err = got_error_from_errno("realloc");
283 free(*s);
284 *s = NULL;
285 return err;
287 *s = p;
288 /* Skip blob object header first time around. */
289 memcpy(*s + offset,
290 got_object_blob_get_read_buf(blob) + hdrlen, len - hdrlen);
291 hdrlen = 0;
292 offset = totlen;
293 } while (len > 0);
295 (*s)[totlen] = '\0';
296 return NULL;
299 const struct got_error *
300 got_tree_entry_get_symlink_target(char **link_target, struct got_tree_entry *te,
301 struct got_repository *repo)
303 const struct got_error *err = NULL;
304 struct got_blob_object *blob = NULL;
305 int fd = -1;
307 *link_target = NULL;
309 if (!got_object_tree_entry_is_symlink(te))
310 return got_error(GOT_ERR_TREE_ENTRY_TYPE);
312 fd = got_opentempfd();
313 if (fd == -1) {
314 err = got_error_from_errno("got_opentempfd");
315 goto done;
318 err = got_object_open_as_blob(&blob, repo,
319 got_tree_entry_get_id(te), PATH_MAX, fd);
320 if (err)
321 goto done;
323 err = got_object_blob_read_to_str(link_target, blob);
324 done:
325 if (fd != -1 && close(fd) == -1 && err == NULL)
326 err = got_error_from_errno("close");
327 if (blob)
328 got_object_blob_close(blob);
329 if (err) {
330 free(*link_target);
331 *link_target = NULL;
333 return err;
336 int
337 got_tree_entry_get_index(struct got_tree_entry *te)
339 return te->idx;
342 struct got_tree_entry *
343 got_tree_entry_get_next(struct got_tree_object *tree,
344 struct got_tree_entry *te)
346 return got_object_tree_get_entry(tree, te->idx + 1);
349 struct got_tree_entry *
350 got_tree_entry_get_prev(struct got_tree_object *tree,
351 struct got_tree_entry *te)
353 return got_object_tree_get_entry(tree, te->idx - 1);
356 const struct got_error *
357 got_object_blob_close(struct got_blob_object *blob)
359 const struct got_error *err = NULL;
360 free(blob->read_buf);
361 if (blob->f && fclose(blob->f) == EOF)
362 err = got_error_from_errno("fclose");
363 free(blob->data);
364 free(blob);
365 return err;
368 void
369 got_object_blob_rewind(struct got_blob_object *blob)
371 if (blob->f)
372 rewind(blob->f);
375 char *
376 got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
378 return got_sha1_digest_to_str(blob->id.sha1, buf, size);
381 size_t
382 got_object_blob_get_hdrlen(struct got_blob_object *blob)
384 return blob->hdrlen;
387 const uint8_t *
388 got_object_blob_get_read_buf(struct got_blob_object *blob)
390 return blob->read_buf;
393 const struct got_error *
394 got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
396 size_t n;
398 n = fread(blob->read_buf, 1, blob->blocksize, blob->f);
399 if (n == 0 && ferror(blob->f))
400 return got_ferror(blob->f, GOT_ERR_IO);
401 *outlenp = n;
402 return NULL;
405 const struct got_error *
406 got_object_blob_dump_to_file(off_t *filesize, int *nlines,
407 off_t **line_offsets, FILE *outfile, struct got_blob_object *blob)
409 const struct got_error *err = NULL;
410 size_t n, len, hdrlen;
411 const uint8_t *buf;
412 int i;
413 const int alloc_chunksz = 512;
414 size_t nalloc = 0;
415 off_t off = 0, total_len = 0;
417 if (line_offsets)
418 *line_offsets = NULL;
419 if (filesize)
420 *filesize = 0;
421 if (nlines)
422 *nlines = 0;
424 hdrlen = got_object_blob_get_hdrlen(blob);
425 do {
426 err = got_object_blob_read_block(&len, blob);
427 if (err)
428 return err;
429 if (len == 0)
430 break;
431 buf = got_object_blob_get_read_buf(blob);
432 i = hdrlen;
433 if (nlines) {
434 if (line_offsets && *line_offsets == NULL) {
435 /* Have some data but perhaps no '\n'. */
436 *nlines = 1;
437 nalloc = alloc_chunksz;
438 *line_offsets = calloc(nalloc,
439 sizeof(**line_offsets));
440 if (*line_offsets == NULL)
441 return got_error_from_errno("calloc");
443 /* Skip forward over end of first line. */
444 while (i < len) {
445 if (buf[i] == '\n')
446 break;
447 i++;
450 /* Scan '\n' offsets in remaining chunk of data. */
451 while (i < len) {
452 if (buf[i] != '\n') {
453 i++;
454 continue;
456 (*nlines)++;
457 if (line_offsets && nalloc < *nlines) {
458 size_t n = *nlines + alloc_chunksz;
459 off_t *o = recallocarray(*line_offsets,
460 nalloc, n, sizeof(**line_offsets));
461 if (o == NULL) {
462 free(*line_offsets);
463 *line_offsets = NULL;
464 return got_error_from_errno(
465 "recallocarray");
467 *line_offsets = o;
468 nalloc = n;
470 if (line_offsets) {
471 off = total_len + i - hdrlen + 1;
472 (*line_offsets)[*nlines - 1] = off;
474 i++;
477 /* Skip blob object header first time around. */
478 n = fwrite(buf + hdrlen, 1, len - hdrlen, outfile);
479 if (n != len - hdrlen)
480 return got_ferror(outfile, GOT_ERR_IO);
481 total_len += len - hdrlen;
482 hdrlen = 0;
483 } while (len != 0);
485 if (fflush(outfile) != 0)
486 return got_error_from_errno("fflush");
487 rewind(outfile);
489 if (filesize)
490 *filesize = total_len;
492 return NULL;
495 const char *
496 got_object_tag_get_name(struct got_tag_object *tag)
498 return tag->tag;
501 int
502 got_object_tag_get_object_type(struct got_tag_object *tag)
504 return tag->obj_type;
507 struct got_object_id *
508 got_object_tag_get_object_id(struct got_tag_object *tag)
510 return &tag->id;
513 time_t
514 got_object_tag_get_tagger_time(struct got_tag_object *tag)
516 return tag->tagger_time;
519 time_t
520 got_object_tag_get_tagger_gmtoff(struct got_tag_object *tag)
522 return tag->tagger_gmtoff;
525 const char *
526 got_object_tag_get_tagger(struct got_tag_object *tag)
528 return tag->tagger;
531 const char *
532 got_object_tag_get_message(struct got_tag_object *tag)
534 return tag->tagmsg;
537 static struct got_tree_entry *
538 find_entry_by_name(struct got_tree_object *tree, const char *name, size_t len)
540 int i;
542 /* Note that tree entries are sorted in strncmp() order. */
543 for (i = 0; i < tree->nentries; i++) {
544 struct got_tree_entry *te = &tree->entries[i];
545 int cmp = strncmp(te->name, name, len);
546 if (cmp < 0)
547 continue;
548 if (cmp > 0)
549 break;
550 if (te->name[len] == '\0')
551 return te;
553 return NULL;
556 struct got_tree_entry *
557 got_object_tree_find_entry(struct got_tree_object *tree, const char *name)
559 return find_entry_by_name(tree, name, strlen(name));
562 const struct got_error *
563 got_object_tree_find_path(struct got_object_id **id, mode_t *mode,
564 struct got_repository *repo, struct got_tree_object *tree,
565 const char *path)
567 const struct got_error *err = NULL;
568 struct got_tree_object *subtree = NULL;
569 struct got_tree_entry *te = NULL;
570 const char *seg, *s;
571 size_t seglen;
573 *id = NULL;
575 s = path;
576 while (s[0] == '/')
577 s++;
578 seg = s;
579 seglen = 0;
580 subtree = tree;
581 while (*s) {
582 struct got_tree_object *next_tree;
584 if (*s != '/') {
585 s++;
586 seglen++;
587 if (*s)
588 continue;
591 te = find_entry_by_name(subtree, seg, seglen);
592 if (te == NULL) {
593 err = got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
594 goto done;
597 if (*s == '\0')
598 break;
600 seg = s + 1;
601 seglen = 0;
602 s++;
603 if (*s) {
604 err = got_object_open_as_tree(&next_tree, repo,
605 &te->id);
606 te = NULL;
607 if (err)
608 goto done;
609 if (subtree != tree)
610 got_object_tree_close(subtree);
611 subtree = next_tree;
615 if (te) {
616 *id = got_object_id_dup(&te->id);
617 if (*id == NULL)
618 return got_error_from_errno("got_object_id_dup");
619 if (mode)
620 *mode = te->mode;
621 } else
622 err = got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
623 done:
624 if (subtree && subtree != tree)
625 got_object_tree_close(subtree);
626 return err;
629 const struct got_error *
630 got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
631 struct got_commit_object *commit, const char *path)
633 const struct got_error *err = NULL;
634 struct got_tree_object *tree = NULL;
636 *id = NULL;
638 /* Handle opening of root of commit's tree. */
639 if (got_path_is_root_dir(path)) {
640 *id = got_object_id_dup(commit->tree_id);
641 if (*id == NULL)
642 err = got_error_from_errno("got_object_id_dup");
643 } else {
644 err = got_object_open_as_tree(&tree, repo, commit->tree_id);
645 if (err)
646 goto done;
647 err = got_object_tree_find_path(id, NULL, repo, tree, path);
649 done:
650 if (tree)
651 got_object_tree_close(tree);
652 return err;
655 /*
656 * Normalize file mode bits to avoid false positive tree entry differences
657 * in case tree entries have unexpected mode bits set.
658 */
659 static mode_t
660 normalize_mode_for_comparison(mode_t mode)
662 /*
663 * For directories, the only relevant bit is the IFDIR bit.
664 * This allows us to detect paths changing from a directory
665 * to a file and vice versa.
666 */
667 if (S_ISDIR(mode))
668 return mode & S_IFDIR;
670 /*
671 * For symlinks, the only relevant bit is the IFLNK bit.
672 * This allows us to detect paths changing from a symlinks
673 * to a file or directory and vice versa.
674 */
675 if (S_ISLNK(mode))
676 return mode & S_IFLNK;
678 /* For files, the only change we care about is the executable bit. */
679 return mode & S_IXUSR;
682 const struct got_error *
683 got_object_tree_path_changed(int *changed,
684 struct got_tree_object *tree01, struct got_tree_object *tree02,
685 const char *path, struct got_repository *repo)
687 const struct got_error *err = NULL;
688 struct got_tree_object *tree1 = NULL, *tree2 = NULL;
689 struct got_tree_entry *te1 = NULL, *te2 = NULL;
690 const char *seg, *s;
691 size_t seglen;
693 *changed = 0;
695 /* We not do support comparing the root path. */
696 if (got_path_is_root_dir(path))
697 return got_error_path(path, GOT_ERR_BAD_PATH);
699 tree1 = tree01;
700 tree2 = tree02;
701 s = path;
702 while (*s == '/')
703 s++;
704 seg = s;
705 seglen = 0;
706 while (*s) {
707 struct got_tree_object *next_tree1, *next_tree2;
708 mode_t mode1, mode2;
710 if (*s != '/') {
711 s++;
712 seglen++;
713 if (*s)
714 continue;
717 te1 = find_entry_by_name(tree1, seg, seglen);
718 if (te1 == NULL) {
719 err = got_error(GOT_ERR_NO_OBJ);
720 goto done;
723 if (tree2)
724 te2 = find_entry_by_name(tree2, seg, seglen);
726 if (te2) {
727 mode1 = normalize_mode_for_comparison(te1->mode);
728 mode2 = normalize_mode_for_comparison(te2->mode);
729 if (mode1 != mode2) {
730 *changed = 1;
731 goto done;
734 if (got_object_id_cmp(&te1->id, &te2->id) == 0) {
735 *changed = 0;
736 goto done;
740 if (*s == '\0') { /* final path element */
741 *changed = 1;
742 goto done;
745 seg = s + 1;
746 s++;
747 seglen = 0;
748 if (*s) {
749 err = got_object_open_as_tree(&next_tree1, repo,
750 &te1->id);
751 te1 = NULL;
752 if (err)
753 goto done;
754 if (tree1 != tree01)
755 got_object_tree_close(tree1);
756 tree1 = next_tree1;
758 if (te2) {
759 err = got_object_open_as_tree(&next_tree2, repo,
760 &te2->id);
761 te2 = NULL;
762 if (err)
763 goto done;
764 if (tree2 != tree02)
765 got_object_tree_close(tree2);
766 tree2 = next_tree2;
767 } else if (tree2) {
768 if (tree2 != tree02)
769 got_object_tree_close(tree2);
770 tree2 = NULL;
774 done:
775 if (tree1 && tree1 != tree01)
776 got_object_tree_close(tree1);
777 if (tree2 && tree2 != tree02)
778 got_object_tree_close(tree2);
779 return err;
782 const struct got_error *
783 got_object_tree_entry_dup(struct got_tree_entry **new_te,
784 struct got_tree_entry *te)
786 const struct got_error *err = NULL;
788 *new_te = calloc(1, sizeof(**new_te));
789 if (*new_te == NULL)
790 return got_error_from_errno("calloc");
792 (*new_te)->mode = te->mode;
793 memcpy((*new_te)->name, te->name, sizeof((*new_te)->name));
794 memcpy(&(*new_te)->id, &te->id, sizeof((*new_te)->id));
795 return err;
798 int
799 got_object_tree_entry_is_submodule(struct got_tree_entry *te)
801 return (te->mode & S_IFMT) == (S_IFDIR | S_IFLNK);
804 int
805 got_object_tree_entry_is_symlink(struct got_tree_entry *te)
807 /* S_IFDIR check avoids confusing symlinks with submodules. */
808 return ((te->mode & (S_IFDIR | S_IFLNK)) == S_IFLNK);
811 static const struct got_error *
812 resolve_symlink(char **link_target, const char *path,
813 struct got_commit_object *commit, struct got_repository *repo)
815 const struct got_error *err = NULL;
816 char buf[PATH_MAX];
817 char *name, *parent_path = NULL;
818 struct got_object_id *tree_obj_id = NULL;
819 struct got_tree_object *tree = NULL;
820 struct got_tree_entry *te = NULL;
822 *link_target = NULL;
824 if (strlcpy(buf, path, sizeof(buf)) >= sizeof(buf))
825 return got_error(GOT_ERR_NO_SPACE);
827 name = basename(buf);
828 if (name == NULL)
829 return got_error_from_errno2("basename", path);
831 err = got_path_dirname(&parent_path, path);
832 if (err)
833 return err;
835 err = got_object_id_by_path(&tree_obj_id, repo, commit,
836 parent_path);
837 if (err) {
838 if (err->code == GOT_ERR_NO_TREE_ENTRY) {
839 /* Display the complete path in error message. */
840 err = got_error_path(path, err->code);
842 goto done;
845 err = got_object_open_as_tree(&tree, repo, tree_obj_id);
846 if (err)
847 goto done;
849 te = got_object_tree_find_entry(tree, name);
850 if (te == NULL) {
851 err = got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
852 goto done;
855 if (got_object_tree_entry_is_symlink(te)) {
856 err = got_tree_entry_get_symlink_target(link_target, te, repo);
857 if (err)
858 goto done;
859 if (!got_path_is_absolute(*link_target)) {
860 char *abspath;
861 if (asprintf(&abspath, "%s/%s", parent_path,
862 *link_target) == -1) {
863 err = got_error_from_errno("asprintf");
864 goto done;
866 free(*link_target);
867 *link_target = malloc(PATH_MAX);
868 if (*link_target == NULL) {
869 err = got_error_from_errno("malloc");
870 goto done;
872 err = got_canonpath(abspath, *link_target, PATH_MAX);
873 free(abspath);
874 if (err)
875 goto done;
878 done:
879 free(parent_path);
880 free(tree_obj_id);
881 if (tree)
882 got_object_tree_close(tree);
883 if (err) {
884 free(*link_target);
885 *link_target = NULL;
887 return err;
890 const struct got_error *
891 got_object_resolve_symlinks(char **link_target, const char *path,
892 struct got_commit_object *commit, struct got_repository *repo)
894 const struct got_error *err = NULL;
895 char *next_target = NULL;
896 int max_recursion = 40; /* matches Git */
898 *link_target = NULL;
900 do {
901 err = resolve_symlink(&next_target,
902 *link_target ? *link_target : path, commit, repo);
903 if (err)
904 break;
905 if (next_target) {
906 free(*link_target);
907 if (--max_recursion == 0) {
908 err = got_error_path(path, GOT_ERR_RECURSION);
909 *link_target = NULL;
910 break;
912 *link_target = next_target;
914 } while (next_target);
916 return err;
919 void
920 got_object_commit_retain(struct got_commit_object *commit)
922 commit->refcnt++;