Blob


1 /*
2 * Copyright (c) 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>
21 #include <ctype.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdint.h>
29 #include <sha1.h>
30 #include <unistd.h>
31 #include <zlib.h>
33 #include "got_error.h"
34 #include "got_object.h"
35 #include "got_repository.h"
36 #include "got_opentemp.h"
37 #include "got_path.h"
39 #include "got_lib_sha1.h"
40 #include "got_lib_deflate.h"
41 #include "got_lib_delta.h"
42 #include "got_lib_object.h"
43 #include "got_lib_object_parse.h"
44 #include "got_lib_lockfile.h"
46 #ifndef nitems
47 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
48 #endif
50 static const struct got_error *
51 create_object_file(struct got_object_id *id, FILE *content,
52 struct got_repository *repo)
53 {
54 const struct got_error *err = NULL, *unlock_err = NULL;
55 char *objpath = NULL, *tmppath = NULL;
56 FILE *tmpfile = NULL;
57 struct got_lockfile *lf = NULL;
58 size_t tmplen = 0;
60 err = got_object_get_path(&objpath, id, repo);
61 if (err)
62 return err;
64 err = got_opentemp_named(&tmppath, &tmpfile, objpath);
65 if (err) {
66 char *parent_path;
67 if (!(err->code == GOT_ERR_ERRNO && errno == ENOENT))
68 goto done;
69 err = got_path_dirname(&parent_path, objpath);
70 if (err)
71 goto done;
72 err = got_path_mkdir(parent_path);
73 free(parent_path);
74 if (err)
75 goto done;
76 err = got_opentemp_named(&tmppath, &tmpfile, objpath);
77 if (err)
78 goto done;
79 }
81 if (fchmod(fileno(tmpfile), GOT_DEFAULT_FILE_MODE) != 0) {
82 err = got_error_from_errno2("fchmod", tmppath);
83 goto done;
84 }
86 err = got_deflate_to_file(&tmplen, content, tmpfile, NULL);
87 if (err)
88 goto done;
90 err = got_lockfile_lock(&lf, objpath, -1);
91 if (err)
92 goto done;
94 if (rename(tmppath, objpath) != 0) {
95 err = got_error_from_errno3("rename", tmppath, objpath);
96 goto done;
97 }
98 free(tmppath);
99 tmppath = NULL;
100 done:
101 free(objpath);
102 if (tmppath) {
103 if (unlink(tmppath) != 0 && err == NULL)
104 err = got_error_from_errno2("unlink", tmppath);
105 free(tmppath);
107 if (tmpfile && fclose(tmpfile) == EOF && err == NULL)
108 err = got_error_from_errno("fclose");
109 if (lf)
110 unlock_err = got_lockfile_unlock(lf, -1);
111 return err ? err : unlock_err;
114 const struct got_error *
115 got_object_blob_file_create(struct got_object_id **id, FILE **blobfile,
116 const char *ondisk_path)
118 const struct got_error *err = NULL;
119 char *header = NULL;
120 int fd = -1;
121 struct stat sb;
122 SHA1_CTX sha1_ctx;
123 size_t headerlen = 0, n;
125 *id = NULL;
126 *blobfile = NULL;
128 SHA1Init(&sha1_ctx);
130 fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
131 if (fd == -1) {
132 if (!got_err_open_nofollow_on_symlink())
133 return got_error_from_errno2("open", ondisk_path);
135 if (lstat(ondisk_path, &sb) == -1) {
136 err = got_error_from_errno2("lstat", ondisk_path);
137 goto done;
139 } else if (fstat(fd, &sb) == -1) {
140 err = got_error_from_errno2("fstat", ondisk_path);
141 goto done;
144 if (asprintf(&header, "%s %lld", GOT_OBJ_LABEL_BLOB,
145 (long long)sb.st_size) == -1) {
146 err = got_error_from_errno("asprintf");
147 goto done;
149 headerlen = strlen(header) + 1;
150 SHA1Update(&sha1_ctx, header, headerlen);
152 *blobfile = got_opentemp();
153 if (*blobfile == NULL) {
154 err = got_error_from_errno("got_opentemp");
155 goto done;
158 n = fwrite(header, 1, headerlen, *blobfile);
159 if (n != headerlen) {
160 err = got_ferror(*blobfile, GOT_ERR_IO);
161 goto done;
163 for (;;) {
164 char buf[PATH_MAX * 8];
165 ssize_t inlen;
167 if (S_ISLNK(sb.st_mode)) {
168 inlen = readlink(ondisk_path, buf, sizeof(buf));
169 if (inlen == -1) {
170 err = got_error_from_errno("readlink");
171 goto done;
173 } else {
174 inlen = read(fd, buf, sizeof(buf));
175 if (inlen == -1) {
176 err = got_error_from_errno("read");
177 goto done;
180 if (inlen == 0)
181 break; /* EOF */
182 SHA1Update(&sha1_ctx, buf, inlen);
183 n = fwrite(buf, 1, inlen, *blobfile);
184 if (n != inlen) {
185 err = got_ferror(*blobfile, GOT_ERR_IO);
186 goto done;
188 if (S_ISLNK(sb.st_mode))
189 break;
192 *id = malloc(sizeof(**id));
193 if (*id == NULL) {
194 err = got_error_from_errno("malloc");
195 goto done;
197 SHA1Final((*id)->sha1, &sha1_ctx);
199 if (fflush(*blobfile) != 0) {
200 err = got_error_from_errno("fflush");
201 goto done;
203 rewind(*blobfile);
204 done:
205 free(header);
206 if (fd != -1 && close(fd) == -1 && err == NULL)
207 err = got_error_from_errno("close");
208 if (err) {
209 free(*id);
210 *id = NULL;
211 if (*blobfile) {
212 fclose(*blobfile);
213 *blobfile = NULL;
216 return err;
219 const struct got_error *
220 got_object_blob_create(struct got_object_id **id, const char *ondisk_path,
221 struct got_repository *repo)
223 const struct got_error *err = NULL;
224 FILE *blobfile = NULL;
226 err = got_object_blob_file_create(id, &blobfile, ondisk_path);
227 if (err)
228 return err;
230 err = create_object_file(*id, blobfile, repo);
231 if (fclose(blobfile) == EOF && err == NULL)
232 err = got_error_from_errno("fclose");
233 if (err) {
234 free(*id);
235 *id = NULL;
237 return err;
240 static const struct got_error *
241 te_mode2str(char *buf, size_t len, struct got_tree_entry *te)
243 int ret;
244 mode_t mode;
246 /*
247 * Some Git implementations are picky about modes seen in tree entries.
248 * For best compatibility we normalize the file/directory mode here.
249 */
250 if (S_ISREG(te->mode)) {
251 mode = GOT_DEFAULT_FILE_MODE;
252 if (te->mode & (S_IXUSR | S_IXGRP | S_IXOTH))
253 mode |= S_IXUSR | S_IXGRP | S_IXOTH;
254 } else if (got_object_tree_entry_is_submodule(te))
255 mode = S_IFDIR | S_IFLNK;
256 else if (S_ISLNK(te->mode))
257 mode = S_IFLNK; /* Git leaves all the other bits unset. */
258 else if (S_ISDIR(te->mode))
259 mode = S_IFDIR; /* Git leaves all the other bits unset. */
260 else
261 return got_error(GOT_ERR_BAD_FILETYPE);
263 ret = snprintf(buf, len, "%o ", mode);
264 if (ret == -1 || ret >= len)
265 return got_error(GOT_ERR_NO_SPACE);
266 return NULL;
269 /*
270 * Git expects directory tree entries to be sorted with an imaginary slash
271 * appended to their name, and will break otherwise. Let's be nice.
272 * This function is intended to be used with mergesort(3) to sort an
273 * array of pointers to struct got_tree_entry objects.
274 */
275 static int
276 sort_tree_entries_the_way_git_likes_it(const void *arg1, const void *arg2)
278 struct got_tree_entry * const *te1 = arg1;
279 struct got_tree_entry * const *te2 = arg2;
280 char name1[NAME_MAX + 2];
281 char name2[NAME_MAX + 2];
283 strlcpy(name1, (*te1)->name, sizeof(name1));
284 strlcpy(name2, (*te2)->name, sizeof(name2));
285 if (S_ISDIR((*te1)->mode))
286 strlcat(name1, "/", sizeof(name1));
287 if (S_ISDIR((*te2)->mode))
288 strlcat(name2, "/", sizeof(name2));
289 return strcmp(name1, name2);
292 const struct got_error *
293 got_object_tree_create(struct got_object_id **id,
294 struct got_pathlist_head *paths, int nentries, struct got_repository *repo)
296 const struct got_error *err = NULL;
297 char modebuf[sizeof("100644 ")];
298 SHA1_CTX sha1_ctx;
299 char *header = NULL;
300 size_t headerlen, len = 0, n;
301 FILE *treefile = NULL;
302 struct got_pathlist_entry *pe;
303 struct got_tree_entry **sorted_entries;
304 struct got_tree_entry *te;
305 int i;
307 *id = NULL;
309 SHA1Init(&sha1_ctx);
311 sorted_entries = calloc(nentries, sizeof(struct got_tree_entry *));
312 if (sorted_entries == NULL)
313 return got_error_from_errno("calloc");
315 i = 0;
316 TAILQ_FOREACH(pe, paths, entry)
317 sorted_entries[i++] = pe->data;
318 mergesort(sorted_entries, nentries, sizeof(struct got_tree_entry *),
319 sort_tree_entries_the_way_git_likes_it);
321 for (i = 0; i < nentries; i++) {
322 te = sorted_entries[i];
323 err = te_mode2str(modebuf, sizeof(modebuf), te);
324 if (err)
325 goto done;
326 len += strlen(modebuf) + strlen(te->name) + 1 +
327 SHA1_DIGEST_LENGTH;
330 if (asprintf(&header, "%s %zd", GOT_OBJ_LABEL_TREE, len) == -1) {
331 err = got_error_from_errno("asprintf");
332 goto done;
334 headerlen = strlen(header) + 1;
335 SHA1Update(&sha1_ctx, header, headerlen);
337 treefile = got_opentemp();
338 if (treefile == NULL) {
339 err = got_error_from_errno("got_opentemp");
340 goto done;
343 n = fwrite(header, 1, headerlen, treefile);
344 if (n != headerlen) {
345 err = got_ferror(treefile, GOT_ERR_IO);
346 goto done;
349 for (i = 0; i < nentries; i++) {
350 te = sorted_entries[i];
351 err = te_mode2str(modebuf, sizeof(modebuf), te);
352 if (err)
353 goto done;
354 len = strlen(modebuf);
355 n = fwrite(modebuf, 1, len, treefile);
356 if (n != len) {
357 err = got_ferror(treefile, GOT_ERR_IO);
358 goto done;
360 SHA1Update(&sha1_ctx, modebuf, len);
362 len = strlen(te->name) + 1; /* must include NUL */
363 n = fwrite(te->name, 1, len, treefile);
364 if (n != len) {
365 err = got_ferror(treefile, GOT_ERR_IO);
366 goto done;
368 SHA1Update(&sha1_ctx, te->name, len);
370 len = SHA1_DIGEST_LENGTH;
371 n = fwrite(te->id.sha1, 1, len, treefile);
372 if (n != len) {
373 err = got_ferror(treefile, GOT_ERR_IO);
374 goto done;
376 SHA1Update(&sha1_ctx, te->id.sha1, len);
379 *id = malloc(sizeof(**id));
380 if (*id == NULL) {
381 err = got_error_from_errno("malloc");
382 goto done;
384 SHA1Final((*id)->sha1, &sha1_ctx);
386 if (fflush(treefile) != 0) {
387 err = got_error_from_errno("fflush");
388 goto done;
390 rewind(treefile);
392 err = create_object_file(*id, treefile, repo);
393 done:
394 free(header);
395 free(sorted_entries);
396 if (treefile && fclose(treefile) == EOF && err == NULL)
397 err = got_error_from_errno("fclose");
398 if (err) {
399 free(*id);
400 *id = NULL;
402 return err;
405 const struct got_error *
406 got_object_commit_create(struct got_object_id **id,
407 struct got_object_id *tree_id, struct got_object_id_queue *parent_ids,
408 int nparents, const char *author, time_t author_time,
409 const char *committer, time_t committer_time,
410 const char *logmsg, struct got_repository *repo)
412 const struct got_error *err = NULL;
413 SHA1_CTX sha1_ctx;
414 char *header = NULL, *tree_str = NULL;
415 char *author_str = NULL, *committer_str = NULL;
416 char *id_str = NULL;
417 size_t headerlen, len = 0, n;
418 FILE *commitfile = NULL;
419 struct got_object_qid *qid;
420 char *msg0, *msg;
422 *id = NULL;
424 SHA1Init(&sha1_ctx);
426 msg0 = strdup(logmsg);
427 if (msg0 == NULL)
428 return got_error_from_errno("strdup");
429 msg = msg0;
431 while (isspace((unsigned char)msg[0]))
432 msg++;
433 len = strlen(msg);
434 while (len > 0 && isspace((unsigned char)msg[len - 1])) {
435 msg[len - 1] = '\0';
436 len--;
439 if (asprintf(&author_str, "%s%s %lld +0000\n",
440 GOT_COMMIT_LABEL_AUTHOR, author, (long long)author_time) == -1)
441 return got_error_from_errno("asprintf");
443 if (asprintf(&committer_str, "%s%s %lld +0000\n",
444 GOT_COMMIT_LABEL_COMMITTER, committer ? committer : author,
445 (long long)(committer ? committer_time : author_time))
446 == -1) {
447 err = got_error_from_errno("asprintf");
448 goto done;
451 len = strlen(GOT_COMMIT_LABEL_TREE) + SHA1_DIGEST_STRING_LENGTH +
452 nparents *
453 (strlen(GOT_COMMIT_LABEL_PARENT) + SHA1_DIGEST_STRING_LENGTH) +
454 + strlen(author_str) + strlen(committer_str) + 2 + strlen(msg);
456 if (asprintf(&header, "%s %zd", GOT_OBJ_LABEL_COMMIT, len) == -1) {
457 err = got_error_from_errno("asprintf");
458 goto done;
460 headerlen = strlen(header) + 1;
461 SHA1Update(&sha1_ctx, header, headerlen);
463 commitfile = got_opentemp();
464 if (commitfile == NULL) {
465 err = got_error_from_errno("got_opentemp");
466 goto done;
469 n = fwrite(header, 1, headerlen, commitfile);
470 if (n != headerlen) {
471 err = got_ferror(commitfile, GOT_ERR_IO);
472 goto done;
475 err = got_object_id_str(&id_str, tree_id);
476 if (err)
477 goto done;
478 if (asprintf(&tree_str, "%s%s\n", GOT_COMMIT_LABEL_TREE, id_str)
479 == -1) {
480 err = got_error_from_errno("asprintf");
481 goto done;
483 len = strlen(tree_str);
484 SHA1Update(&sha1_ctx, tree_str, len);
485 n = fwrite(tree_str, 1, len, commitfile);
486 if (n != len) {
487 err = got_ferror(commitfile, GOT_ERR_IO);
488 goto done;
491 if (parent_ids) {
492 free(id_str);
493 id_str = NULL;
494 STAILQ_FOREACH(qid, parent_ids, entry) {
495 char *parent_str = NULL;
497 err = got_object_id_str(&id_str, qid->id);
498 if (err)
499 goto done;
500 if (asprintf(&parent_str, "%s%s\n",
501 GOT_COMMIT_LABEL_PARENT, id_str) == -1) {
502 err = got_error_from_errno("asprintf");
503 goto done;
505 len = strlen(parent_str);
506 SHA1Update(&sha1_ctx, parent_str, len);
507 n = fwrite(parent_str, 1, len, commitfile);
508 if (n != len) {
509 err = got_ferror(commitfile, GOT_ERR_IO);
510 free(parent_str);
511 goto done;
513 free(parent_str);
514 free(id_str);
515 id_str = NULL;
519 len = strlen(author_str);
520 SHA1Update(&sha1_ctx, author_str, len);
521 n = fwrite(author_str, 1, len, commitfile);
522 if (n != len) {
523 err = got_ferror(commitfile, GOT_ERR_IO);
524 goto done;
527 len = strlen(committer_str);
528 SHA1Update(&sha1_ctx, committer_str, len);
529 n = fwrite(committer_str, 1, len, commitfile);
530 if (n != len) {
531 err = got_ferror(commitfile, GOT_ERR_IO);
532 goto done;
535 SHA1Update(&sha1_ctx, "\n", 1);
536 n = fwrite("\n", 1, 1, commitfile);
537 if (n != 1) {
538 err = got_ferror(commitfile, GOT_ERR_IO);
539 goto done;
542 len = strlen(msg);
543 SHA1Update(&sha1_ctx, msg, len);
544 n = fwrite(msg, 1, len, commitfile);
545 if (n != len) {
546 err = got_ferror(commitfile, GOT_ERR_IO);
547 goto done;
550 SHA1Update(&sha1_ctx, "\n", 1);
551 n = fwrite("\n", 1, 1, commitfile);
552 if (n != 1) {
553 err = got_ferror(commitfile, GOT_ERR_IO);
554 goto done;
557 *id = malloc(sizeof(**id));
558 if (*id == NULL) {
559 err = got_error_from_errno("malloc");
560 goto done;
562 SHA1Final((*id)->sha1, &sha1_ctx);
564 if (fflush(commitfile) != 0) {
565 err = got_error_from_errno("fflush");
566 goto done;
568 rewind(commitfile);
570 err = create_object_file(*id, commitfile, repo);
571 done:
572 free(id_str);
573 free(msg0);
574 free(header);
575 free(tree_str);
576 free(author_str);
577 free(committer_str);
578 if (commitfile && fclose(commitfile) == EOF && err == NULL)
579 err = got_error_from_errno("fclose");
580 if (err) {
581 free(*id);
582 *id = NULL;
584 return err;
587 const struct got_error *
588 got_object_tag_create(struct got_object_id **id,
589 const char *tag_name, struct got_object_id *object_id, const char *tagger,
590 time_t tagger_time, const char *tagmsg, struct got_repository *repo)
592 const struct got_error *err = NULL;
593 SHA1_CTX sha1_ctx;
594 char *header = NULL;
595 char *tag_str = NULL, *tagger_str = NULL;
596 char *id_str = NULL, *obj_str = NULL, *type_str = NULL;
597 size_t headerlen, len = 0, n;
598 FILE *tagfile = NULL;
599 char *msg0 = NULL, *msg;
600 const char *obj_type_str;
601 int obj_type;
603 *id = NULL;
605 SHA1Init(&sha1_ctx);
607 err = got_object_id_str(&id_str, object_id);
608 if (err)
609 goto done;
610 if (asprintf(&obj_str, "%s%s\n", GOT_TAG_LABEL_OBJECT, id_str) == -1) {
611 err = got_error_from_errno("asprintf");
612 goto done;
615 err = got_object_get_type(&obj_type, repo, object_id);
616 if (err)
617 goto done;
619 switch (obj_type) {
620 case GOT_OBJ_TYPE_BLOB:
621 obj_type_str = GOT_OBJ_LABEL_BLOB;
622 break;
623 case GOT_OBJ_TYPE_TREE:
624 obj_type_str = GOT_OBJ_LABEL_TREE;
625 break;
626 case GOT_OBJ_TYPE_COMMIT:
627 obj_type_str = GOT_OBJ_LABEL_COMMIT;
628 break;
629 case GOT_OBJ_TYPE_TAG:
630 obj_type_str = GOT_OBJ_LABEL_TAG;
631 break;
632 default:
633 err = got_error(GOT_ERR_OBJ_TYPE);
634 goto done;
637 if (asprintf(&type_str, "%s%s\n", GOT_TAG_LABEL_TYPE,
638 obj_type_str) == -1) {
639 err = got_error_from_errno("asprintf");
640 goto done;
643 if (asprintf(&tag_str, "%s%s\n", GOT_TAG_LABEL_TAG, tag_name) == -1) {
644 err = got_error_from_errno("asprintf");
645 goto done;
648 if (asprintf(&tagger_str, "%s%s %lld +0000\n",
649 GOT_TAG_LABEL_TAGGER, tagger, (long long)tagger_time) == -1)
650 return got_error_from_errno("asprintf");
652 msg0 = strdup(tagmsg);
653 if (msg0 == NULL) {
654 err = got_error_from_errno("strdup");
655 goto done;
657 msg = msg0;
659 while (isspace((unsigned char)msg[0]))
660 msg++;
662 len = strlen(obj_str) + strlen(type_str) + strlen(tag_str) +
663 strlen(tagger_str) + 1 + strlen(msg) + 1;
665 if (asprintf(&header, "%s %zd", GOT_OBJ_LABEL_TAG, len) == -1) {
666 err = got_error_from_errno("asprintf");
667 goto done;
670 headerlen = strlen(header) + 1;
671 SHA1Update(&sha1_ctx, header, headerlen);
673 tagfile = got_opentemp();
674 if (tagfile == NULL) {
675 err = got_error_from_errno("got_opentemp");
676 goto done;
679 n = fwrite(header, 1, headerlen, tagfile);
680 if (n != headerlen) {
681 err = got_ferror(tagfile, GOT_ERR_IO);
682 goto done;
684 len = strlen(obj_str);
685 SHA1Update(&sha1_ctx, obj_str, len);
686 n = fwrite(obj_str, 1, len, tagfile);
687 if (n != len) {
688 err = got_ferror(tagfile, GOT_ERR_IO);
689 goto done;
691 len = strlen(type_str);
692 SHA1Update(&sha1_ctx, type_str, len);
693 n = fwrite(type_str, 1, len, tagfile);
694 if (n != len) {
695 err = got_ferror(tagfile, GOT_ERR_IO);
696 goto done;
699 len = strlen(tag_str);
700 SHA1Update(&sha1_ctx, tag_str, len);
701 n = fwrite(tag_str, 1, len, tagfile);
702 if (n != len) {
703 err = got_ferror(tagfile, GOT_ERR_IO);
704 goto done;
707 len = strlen(tagger_str);
708 SHA1Update(&sha1_ctx, tagger_str, len);
709 n = fwrite(tagger_str, 1, len, tagfile);
710 if (n != len) {
711 err = got_ferror(tagfile, GOT_ERR_IO);
712 goto done;
715 SHA1Update(&sha1_ctx, "\n", 1);
716 n = fwrite("\n", 1, 1, tagfile);
717 if (n != 1) {
718 err = got_ferror(tagfile, GOT_ERR_IO);
719 goto done;
722 len = strlen(msg);
723 SHA1Update(&sha1_ctx, msg, len);
724 n = fwrite(msg, 1, len, tagfile);
725 if (n != len) {
726 err = got_ferror(tagfile, GOT_ERR_IO);
727 goto done;
730 SHA1Update(&sha1_ctx, "\n", 1);
731 n = fwrite("\n", 1, 1, tagfile);
732 if (n != 1) {
733 err = got_ferror(tagfile, GOT_ERR_IO);
734 goto done;
737 *id = malloc(sizeof(**id));
738 if (*id == NULL) {
739 err = got_error_from_errno("malloc");
740 goto done;
742 SHA1Final((*id)->sha1, &sha1_ctx);
744 if (fflush(tagfile) != 0) {
745 err = got_error_from_errno("fflush");
746 goto done;
748 rewind(tagfile);
750 err = create_object_file(*id, tagfile, repo);
751 done:
752 free(msg0);
753 free(header);
754 free(obj_str);
755 free(tagger_str);
756 if (tagfile && fclose(tagfile) == EOF && err == NULL)
757 err = got_error_from_errno("fclose");
758 if (err) {
759 free(*id);
760 *id = NULL;
762 return err;