add per-worktree got.conf(5) file in the .got directory; ok millert
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
diff --git a/got/Makefile b/got/Makefile
index 27b8780..c244659 100644
--- a/got/Makefile
+++ b/got/Makefile
@@ -8,7 +8,8 @@ SRCS= got.c blame.c commit_graph.c delta.c diff.c \
object_idset.c object_parse.c opentemp.c path.c pack.c \
privsep.c reference.c repository.c sha1.c worktree.c \
inflate.c buf.c rcsutil.c diff3.c lockfile.c \
- deflate.c object_create.c delta_cache.c fetch.c
+ deflate.c object_create.c delta_cache.c fetch.c \
+ gotconfig.c
MAN = ${PROG}.1 got-worktree.5 git-repository.5
CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib
diff --git a/got/git-repository.5 b/got/git-repository.5
index c3d8db9..bd2b0ae 100644
--- a/got/git-repository.5
+++ b/got/git-repository.5
@@ -162,6 +162,11 @@ See
.Xr git-config 1 .
.It Pa description
A human-readable description of the repository.
+.It Pa got.conf
+Configuration file for
+.Xr got 1 .
+See
+.Xr got.conf 5 .
.It Pa hooks/
This directory contains hook scripts to run when certain events occur.
.It Pa index
@@ -201,6 +206,7 @@ was bare.
.Xr deflate 3 ,
.Xr SHA1 3 ,
.Xr got-worktree 5
+.Xr got.conf 5
.Sh HISTORY
The Git repository format was initially designed by Linus Torvalds in 2005
and has since been extended by various people involved in the development
diff --git a/got/got-worktree.5 b/got/got-worktree.5
index 49ede63..8f8ac0e 100644
--- a/got/got-worktree.5
+++ b/got/got-worktree.5
@@ -161,6 +161,11 @@ SHA1 hex-string representation of the current base commit.
File status information.
.It Pa format
Work tree format number.
+.It Pa got.conf
+Configuration file for
+.Xr got 1 .
+See
+.Xr got.conf 5 .
.It Pa head-ref
Name of the reference to the current branch.
.It Pa lock
@@ -178,4 +183,5 @@ A universal unique identifier for the work tree.
.Xr stat 2 ,
.Xr umask 2 ,
.Xr lockf 3 ,
-.Xr git-repository 5
+.Xr git-repository 5 ,
+.Xr got.conf 5
diff --git a/got/got.1 b/got/got.1
index fc2c196..19a06c8 100644
--- a/got/got.1
+++ b/got/got.1
@@ -315,9 +315,9 @@ If no
is specified,
.Dq origin
will be used.
-The remote repository's URL is obtained from the corresponding entry in the
+The remote repository's URL is obtained from the corresponding entry in
.Xr got.conf 5
-or
+or Git's
.Pa config
file of the local repository, as created by
.Cm got clone .
@@ -1930,18 +1930,15 @@ attempts to reject
.Ev GOT_AUTHOR
environment variables with a missing email address.
.Pp
-If present,
-configuration settings in
-.Xr got.conf 5 ,
-or Git's
+.Ev GOT_AUTHOR will be overriden by configuration settings in
+.Xr got.conf 5
+or by Git's
.Dv user.name
and
.Dv user.email
configuration settings in the repository's
.Pa .git/config
-file,
-will override the value of
-.Ev GOT_AUTHOR .
+file.
The
.Dv user.name
and
@@ -1970,8 +1967,24 @@ This variable will be silently ignored if it is set to a non-numeric value.
.It Pa got.conf
Repository-wide configuration settings for
.Nm .
-If present, this configuration file is located in the root directory
-of a Git repository and supersedes any relevant settings in Git's
+If present, a
+.Xr got.conf 5
+configuration file located in the root directory of a Git repository
+supersedes any relevant settings in Git's
+.Pa config
+file.
+.Pp
+.It Pa .got/got.conf
+Worktree-specific configuration settings for
+.Nm .
+If present, a
+.Xr got.conf
+configuration file in the
+.Pa .got
+meta-data directory of a work tree supersedes any relevant settings in
+the repository's
+.Xr got.conf 5
+configuration file and Git's
.Pa config
file.
.El
diff --git a/got/got.c b/got/got.c
index 0ddfc1d..da2b116 100644
--- a/got/got.c
+++ b/got/got.c
@@ -54,6 +54,7 @@
#include "got_blame.h"
#include "got_privsep.h"
#include "got_opentemp.h"
+#include "got_gotconfig.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@@ -518,14 +519,33 @@ import_progress(void *arg, const char *path)
}
static const struct got_error *
-get_author(char **author, struct got_repository *repo)
+get_author(char **author, struct got_repository *repo,
+ struct got_worktree *worktree)
{
const struct got_error *err = NULL;
- const char *got_author, *name, *email;
+ const char *got_author = NULL, *name, *email;
+ const struct got_gotconfig *worktree_conf = NULL, *repo_conf = NULL;
*author = NULL;
- got_author = got_repo_get_gotconfig_author(repo);
+ if (worktree)
+ worktree_conf = got_worktree_get_gotconfig(worktree);
+ repo_conf = got_repo_get_gotconfig(repo);
+
+ /*
+ * Priority of potential author information sources, from most
+ * significant to least significant:
+ * 1) work tree's .got/got.conf file
+ * 2) repository's got.conf file
+ * 3) repository's git config file
+ * 4) environment variables
+ * 5) global git config files (in user's home directory or /etc)
+ */
+
+ if (worktree_conf)
+ got_author = got_gotconfig_get_author(worktree_conf);
+ if (got_author == NULL)
+ got_author = got_gotconfig_get_author(repo_conf);
if (got_author == NULL) {
name = got_repo_get_gitconfig_author_name(repo);
email = got_repo_get_gitconfig_author_email(repo);
@@ -674,7 +694,7 @@ cmd_import(int argc, char *argv[])
if (error)
goto done;
- error = get_author(&author, repo);
+ error = get_author(&author, repo, NULL);
if (error)
return error;
@@ -1656,7 +1676,8 @@ done:
static const struct got_error *
delete_missing_refs(struct got_pathlist_head *their_refs,
- struct got_pathlist_head *their_symrefs, struct got_remote_repo *remote,
+ struct got_pathlist_head *their_symrefs,
+ const struct got_remote_repo *remote,
int verbosity, struct got_repository *repo)
{
const struct got_error *err = NULL, *unlock_err;
@@ -1782,11 +1803,12 @@ cmd_fetch(int argc, char *argv[])
const char *remote_name;
char *proto = NULL, *host = NULL, *port = NULL;
char *repo_name = NULL, *server_path = NULL;
- struct got_remote_repo *remotes, *remote = NULL;
+ const struct got_remote_repo *remotes, *remote = NULL;
int nremotes;
char *id_str = NULL;
struct got_repository *repo = NULL;
struct got_worktree *worktree = NULL;
+ const struct got_gotconfig *repo_conf = NULL, *worktree_conf = NULL;
struct got_pathlist_head refs, symrefs, wanted_branches, wanted_refs;
struct got_pathlist_entry *pe;
struct got_object_id *pack_hash = NULL;
@@ -1903,23 +1925,41 @@ cmd_fetch(int argc, char *argv[])
if (error)
goto done;
- got_repo_get_gotconfig_remotes(&nremotes, &remotes, repo);
- for (i = 0; i < nremotes; i++) {
- remote = &remotes[i];
- if (strcmp(remote->name, remote_name) == 0)
- break;
+ if (worktree) {
+ worktree_conf = got_worktree_get_gotconfig(worktree);
+ if (worktree_conf) {
+ got_gotconfig_get_remotes(&nremotes, &remotes,
+ worktree_conf);
+ for (i = 0; i < nremotes; i++) {
+ remote = &remotes[i];
+ if (strcmp(remote->name, remote_name) == 0)
+ break;
+ }
+ }
+ }
+ if (remote == NULL) {
+ repo_conf = got_repo_get_gotconfig(repo);
+ if (repo_conf) {
+ got_gotconfig_get_remotes(&nremotes, &remotes,
+ repo_conf);
+ for (i = 0; i < nremotes; i++) {
+ remote = &remotes[i];
+ if (strcmp(remote->name, remote_name) == 0)
+ break;
+ }
+ }
}
- if (i == nremotes) {
+ if (remote == NULL) {
got_repo_get_gitconfig_remotes(&nremotes, &remotes, repo);
for (i = 0; i < nremotes; i++) {
remote = &remotes[i];
if (strcmp(remote->name, remote_name) == 0)
break;
}
- if (i == nremotes) {
- error = got_error_path(remote_name, GOT_ERR_NO_REMOTE);
- goto done;
- }
+ }
+ if (remote == NULL) {
+ error = got_error_path(remote_name, GOT_ERR_NO_REMOTE);
+ goto done;
}
error = got_fetch_parse_uri(&proto, &host, &port, &server_path,
@@ -5689,8 +5729,8 @@ done:
}
static const struct got_error *
-add_tag(struct got_repository *repo, const char *tag_name,
- const char *commit_arg, const char *tagmsg_arg)
+add_tag(struct got_repository *repo, struct got_worktree *worktree,
+ const char *tag_name, const char *commit_arg, const char *tagmsg_arg)
{
const struct got_error *err = NULL;
struct got_object_id *commit_id = NULL, *tag_id = NULL;
@@ -5708,7 +5748,7 @@ add_tag(struct got_repository *repo, const char *tag_name,
if (tag_name[0] == '-')
return got_error_path(tag_name, GOT_ERR_REF_NAME_MINUS);
- err = get_author(&tagger, repo);
+ err = get_author(&tagger, repo, worktree);
if (err)
return err;
@@ -5928,7 +5968,7 @@ cmd_tag(int argc, char *argv[])
goto done;
}
- error = add_tag(repo, tag_name,
+ error = add_tag(repo, worktree, tag_name,
commit_id_str ? commit_id_str : commit_id_arg, tagmsg);
}
done:
@@ -6636,7 +6676,7 @@ cmd_commit(int argc, char *argv[])
if (error != NULL)
goto done;
- error = get_author(&author, repo);
+ error = get_author(&author, repo, worktree);
if (error)
return error;
diff --git a/got/got.conf.5 b/got/got.conf.5
index d6d11e4..734c258 100644
--- a/got/got.conf.5
+++ b/got/got.conf.5
@@ -24,6 +24,15 @@
is the run-time configuration file for
.Xr got 1 .
.Pp
+.Nm
+may be present in the root directory of a Git repository for
+repository-wide settings, or in the
+.Pa .got
+meta-data directory of a work tree to override repository-wide
+settings for
+.Xr got 1
+commands executed within this work tree.
+.Pp
The file format is line-based, with one configuration directive per line.
Any lines beginning with a
.Sq #
@@ -144,13 +153,27 @@ remote "origin" {
.Sh FILES
.Bl -tag -width Ds -compact
.It Pa got.conf
-If present, the
+If present,
+.Nm
+located in the root directory of a Git repository supersedes any relevant
+settings in Git's
+.Pa config
+file.
+.Pp
+.It Pa .got/got.conf
+If present,
+.Nm
+located in the
+.Pa .got
+meta-data directory of a
+.Xr got 1
+work tree supersedes any relevant settings in the repository's
.Nm
-configuration file is located in the root directory of a Git repository
-and supersedes any relevant settings in Git's
+configuration file and Git's
.Pa config
file.
.El
.Sh SEE ALSO
.Xr got 1 ,
-.Xr git-repository 5
+.Xr git-repository 5,
+.Xr got-worktree 5
diff --git a/gotweb/Makefile b/gotweb/Makefile
index f22b8bb..86cf8bc 100644
--- a/gotweb/Makefile
+++ b/gotweb/Makefile
@@ -11,7 +11,7 @@ SRCS = gotweb.c parse.y blame.c commit_graph.c delta.c diff.c \
object_idset.c object_parse.c opentemp.c path.c pack.c \
privsep.c reference.c repository.c sha1.c worktree.c \
inflate.c buf.c rcsutil.c diff3.c lockfile.c \
- deflate.c object_create.c delta_cache.c
+ deflate.c object_create.c delta_cache.c gotconfig.c
MAN = ${PROG}.conf.5 ${PROG}.8
CPPFLAGS += -I${.CURDIR}/../include -I${.CURDIR}/../lib -I${.CURDIR} \
diff --git a/include/got_gotconfig.h b/include/got_gotconfig.h
new file mode 100644
index 0000000..3dbe5d7
--- /dev/null
+++ b/include/got_gotconfig.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+struct got_gotconfig;
+
+/*
+ * Obtain the commit author parsed from got.conf.
+ * Return NULL if no configuration file or author could be found.
+ */
+const char *got_gotconfig_get_author(const struct got_gotconfig *);
+
+/*
+ * Obtain the list of remote repositories parsed from got.conf.
+ * Return 0 and NULL if no configuration file or remote repository
+ * could be found.
+ */
+void got_gotconfig_get_remotes(int *, const struct got_remote_repo **,
+ const struct got_gotconfig *);
diff --git a/include/got_repository.h b/include/got_repository.h
index bc9bddc..2b10479 100644
--- a/include/got_repository.h
+++ b/include/got_repository.h
@@ -59,16 +59,15 @@ struct got_remote_repo {
int mirror_references;
};
-/* Obtain the commit author if parsed from got.conf, else NULL. */
-const char *got_repo_get_gotconfig_author(struct got_repository *);
-
/* Obtain the list of remote repositories parsed from gitconfig. */
-void got_repo_get_gitconfig_remotes(int *, struct got_remote_repo **,
+void got_repo_get_gitconfig_remotes(int *, const struct got_remote_repo **,
struct got_repository *);
-/* Obtain the list of remote repositories parsed from got.conf. */
-void got_repo_get_gotconfig_remotes(int *, struct got_remote_repo **,
- struct got_repository *);
+/*
+ * Obtain a parsed representation of this repository's got.conf file.
+ * Return NULL if this configuration file could not be read.
+ */
+const struct got_gotconfig *got_repo_get_gotconfig(struct got_repository *);
/*
* Obtain paths to various directories within a repository.
diff --git a/include/got_worktree.h b/include/got_worktree.h
index c655d81..24fddd5 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -108,6 +108,12 @@ struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
struct got_repository *, struct got_object_id *);
+/*
+ * Obtain a parsed representation of this worktree's got.conf file.
+ * Return NULL if this configuration file could not be read.
+ */
+const struct got_gotconfig *got_worktree_get_gotconfig(struct got_worktree *);
+
/* A callback function which is invoked when a path is checked out. */
typedef const struct got_error *(*got_worktree_checkout_cb)(void *,
unsigned char, const char *);
diff --git a/lib/got_lib_gotconfig.h b/lib/got_lib_gotconfig.h
new file mode 100644
index 0000000..5e02aa1
--- /dev/null
+++ b/lib/got_lib_gotconfig.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define GOT_GOTCONFIG_FILENAME "got.conf"
+
+struct got_gotconfig {
+ char *author;
+ int nremotes;
+ struct got_remote_repo *remotes;
+};
+
+const struct got_error *got_gotconfig_read(struct got_gotconfig **,
+ const char *);
+void got_gotconfig_free(struct got_gotconfig *);
diff --git a/lib/got_lib_repository.h b/lib/got_lib_repository.h
index 53390ef..87f2558 100644
--- a/lib/got_lib_repository.h
+++ b/lib/got_lib_repository.h
@@ -21,7 +21,6 @@
#define GOT_REFS_DIR "refs"
#define GOT_HEAD_FILE "HEAD"
#define GOT_GITCONFIG "config"
-#define GOT_GOTCONFIG "got.conf"
/* Other files and directories inside the git directory. */
#define GOT_FETCH_HEAD_FILE "FETCH_HEAD"
@@ -67,9 +66,7 @@ struct got_repository {
char *gitconfig_owner;
/* Settings read from got.conf. */
- char *gotconfig_author;
- int ngotconfig_remotes;
- struct got_remote_repo *gotconfig_remotes;
+ struct got_gotconfig *gotconfig;
};
const struct got_error*got_repo_cache_object(struct got_repository *,
diff --git a/lib/got_lib_worktree.h b/lib/got_lib_worktree.h
index c45a958..067bac2 100644
--- a/lib/got_lib_worktree.h
+++ b/lib/got_lib_worktree.h
@@ -33,6 +33,12 @@ struct got_worktree {
* shared lock must be upgraded to an exclusive lock.
*/
int lockfd;
+
+ /* Absolute path to worktree's got.conf file. */
+ char *gotconfig_path;
+
+ /* Settings read from got.conf. */
+ struct got_gotconfig *gotconfig;
};
struct got_commitable {
diff --git a/lib/gotconfig.c b/lib/gotconfig.c
new file mode 100644
index 0000000..c52b0ab
--- /dev/null
+++ b/lib/gotconfig.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <imsg.h>
+#include <sha1.h>
+#include <limits.h>
+
+#include "got_error.h"
+#include "got_object.h"
+#include "got_repository.h"
+
+#include "got_lib_delta.h"
+#include "got_lib_object.h"
+#include "got_lib_privsep.h"
+#include "got_lib_gotconfig.h"
+
+const struct got_error *
+got_gotconfig_read(struct got_gotconfig **conf, const char *gotconfig_path)
+{
+ const struct got_error *err = NULL, *child_err = NULL;
+ int fd = -1;
+ int imsg_fds[2] = { -1, -1 };
+ pid_t pid;
+ struct imsgbuf *ibuf;
+
+ *conf = calloc(1, sizeof(**conf));
+ if (*conf == NULL)
+ return got_error_from_errno("calloc");
+
+ fd = open(gotconfig_path, O_RDONLY);
+ if (fd == -1) {
+ if (errno == ENOENT)
+ return NULL;
+ return got_error_from_errno2("open", gotconfig_path);
+ }
+
+ ibuf = calloc(1, sizeof(*ibuf));
+ if (ibuf == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
+ err = got_error_from_errno("socketpair");
+ goto done;
+ }
+
+ pid = fork();
+ if (pid == -1) {
+ err = got_error_from_errno("fork");
+ goto done;
+ } else if (pid == 0) {
+ got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GOTCONFIG,
+ gotconfig_path);
+ /* not reached */
+ }
+
+ if (close(imsg_fds[1]) == -1) {
+ err = got_error_from_errno("close");
+ goto done;
+ }
+ imsg_fds[1] = -1;
+ imsg_init(ibuf, imsg_fds[0]);
+
+ err = got_privsep_send_gotconfig_parse_req(ibuf, fd);
+ if (err)
+ goto done;
+ fd = -1;
+
+ err = got_privsep_send_gotconfig_author_req(ibuf);
+ if (err)
+ goto done;
+
+ err = got_privsep_recv_gotconfig_str(&(*conf)->author, ibuf);
+ if (err)
+ goto done;
+
+ err = got_privsep_send_gotconfig_remotes_req(ibuf);
+ if (err)
+ goto done;
+
+ err = got_privsep_recv_gotconfig_remotes(&(*conf)->remotes,
+ &(*conf)->nremotes, ibuf);
+ if (err)
+ goto done;
+
+ imsg_clear(ibuf);
+ err = got_privsep_send_stop(imsg_fds[0]);
+ child_err = got_privsep_wait_for_child(pid);
+ if (child_err && err == NULL)
+ err = child_err;
+done:
+ if (imsg_fds[0] != -1 && close(imsg_fds[0]) == -1 && err == NULL)
+ err = got_error_from_errno("close");
+ if (imsg_fds[1] != -1 && close(imsg_fds[1]) == -1 && err == NULL)
+ err = got_error_from_errno("close");
+ if (fd != -1 && close(fd) == -1 && err == NULL)
+ err = got_error_from_errno2("close", gotconfig_path);
+ if (err) {
+ got_gotconfig_free(*conf);
+ *conf = NULL;
+ }
+ free(ibuf);
+ return err;
+}
+
+void
+got_gotconfig_free(struct got_gotconfig *conf)
+{
+ int i;
+
+ free(conf->author);
+
+ for (i = 0; i < conf->nremotes; i++) {
+ free(conf->remotes[i].name);
+ free(conf->remotes[i].url);
+ }
+ free(conf->remotes);
+ free(conf);
+}
+
+const char *
+got_gotconfig_get_author(const struct got_gotconfig *conf)
+{
+ return conf->author;
+}
+
+void
+got_gotconfig_get_remotes(int *nremotes, const struct got_remote_repo **remotes,
+ const struct got_gotconfig *conf)
+{
+ *nremotes = conf->nremotes;
+ *remotes = conf->remotes;
+}
diff --git a/lib/repository.c b/lib/repository.c
index 803b580..84e9477 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -60,6 +60,7 @@
#include "got_lib_sha1.h"
#include "got_lib_object_cache.h"
#include "got_lib_repository.h"
+#include "got_lib_gotconfig.h"
#ifndef nitems
#define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
@@ -164,29 +165,21 @@ got_repo_get_path_gitconfig(struct got_repository *repo)
char *
got_repo_get_path_gotconfig(struct got_repository *repo)
{
- return get_path_git_child(repo, GOT_GOTCONFIG);
+ return get_path_git_child(repo, GOT_GOTCONFIG_FILENAME);
}
-void
-got_repo_get_gitconfig_remotes(int *nremotes, struct got_remote_repo **remotes,
- struct got_repository *repo)
-{
- *nremotes = repo->ngitconfig_remotes;
- *remotes = repo->gitconfig_remotes;
-}
-
-const char *
-got_repo_get_gotconfig_author(struct got_repository *repo)
+const struct got_gotconfig *
+got_repo_get_gotconfig(struct got_repository *repo)
{
- return repo->gotconfig_author;
+ return repo->gotconfig;
}
void
-got_repo_get_gotconfig_remotes(int *nremotes, struct got_remote_repo **remotes,
- struct got_repository *repo)
+got_repo_get_gitconfig_remotes(int *nremotes,
+ const struct got_remote_repo **remotes, struct got_repository *repo)
{
- *nremotes = repo->ngotconfig_remotes;
- *remotes = repo->gotconfig_remotes;
+ *nremotes = repo->ngitconfig_remotes;
+ *remotes = repo->gitconfig_remotes;
}
static int
@@ -539,107 +532,6 @@ done:
}
static const struct got_error *
-parse_gotconfig_file(char **author,
- struct got_remote_repo **remotes, int *nremotes,
- const char *gotconfig_path)
-{
- const struct got_error *err = NULL, *child_err = NULL;
- int fd = -1;
- int imsg_fds[2] = { -1, -1 };
- pid_t pid;
- struct imsgbuf *ibuf;
-
- if (author)
- *author = NULL;
- if (remotes)
- *remotes = NULL;
- if (nremotes)
- *nremotes = 0;
-
- fd = open(gotconfig_path, O_RDONLY);
- if (fd == -1) {
- if (errno == ENOENT)
- return NULL;
- return got_error_from_errno2("open", gotconfig_path);
- }
-
- ibuf = calloc(1, sizeof(*ibuf));
- if (ibuf == NULL) {
- err = got_error_from_errno("calloc");
- goto done;
- }
-
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
- err = got_error_from_errno("socketpair");
- goto done;
- }
-
- pid = fork();
- if (pid == -1) {
- err = got_error_from_errno("fork");
- goto done;
- } else if (pid == 0) {
- got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GOTCONFIG,
- gotconfig_path);
- /* not reached */
- }
-
- if (close(imsg_fds[1]) == -1) {
- err = got_error_from_errno("close");
- goto done;
- }
- imsg_fds[1] = -1;
- imsg_init(ibuf, imsg_fds[0]);
-
- err = got_privsep_send_gotconfig_parse_req(ibuf, fd);
- if (err)
- goto done;
- fd = -1;
-
- if (author) {
- err = got_privsep_send_gotconfig_author_req(ibuf);
- if (err)
- goto done;
-
- err = got_privsep_recv_gotconfig_str(author, ibuf);
- if (err)
- goto done;
- }
-
- if (remotes && nremotes) {
- err = got_privsep_send_gotconfig_remotes_req(ibuf);
- if (err)
- goto done;
-
- err = got_privsep_recv_gotconfig_remotes(remotes,
- nremotes, ibuf);
- if (err)
- goto done;
- }
-
- imsg_clear(ibuf);
- err = got_privsep_send_stop(imsg_fds[0]);
- child_err = got_privsep_wait_for_child(pid);
- if (child_err && err == NULL)
- err = child_err;
-done:
- if (imsg_fds[0] != -1 && close(imsg_fds[0]) == -1 && err == NULL)
- err = got_error_from_errno("close");
- if (imsg_fds[1] != -1 && close(imsg_fds[1]) == -1 && err == NULL)
- err = got_error_from_errno("close");
- if (fd != -1 && close(fd) == -1 && err == NULL)
- err = got_error_from_errno2("close", gotconfig_path);
- if (err) {
- if (author) {
- free(*author);
- *author = NULL;
- }
- }
- free(ibuf);
- return err;
-}
-
-static const struct got_error *
read_gotconfig(struct got_repository *repo)
{
const struct got_error *err = NULL;
@@ -649,9 +541,7 @@ read_gotconfig(struct got_repository *repo)
if (gotconfig_path == NULL)
return got_error_from_errno("got_repo_get_path_gotconfig");
- err = parse_gotconfig_file(&repo->gotconfig_author,
- &repo->gotconfig_remotes, &repo->ngotconfig_remotes,
- gotconfig_path);
+ err = got_gotconfig_read(&repo->gotconfig, gotconfig_path);
free(gotconfig_path);
return err;
}
@@ -788,12 +678,8 @@ got_repo_close(struct got_repository *repo)
err = got_error_from_errno("close");
}
- free(repo->gotconfig_author);
- for (i = 0; i < repo->ngotconfig_remotes; i++) {
- free(repo->gotconfig_remotes[i].name);
- free(repo->gotconfig_remotes[i].url);
- }
- free(repo->gotconfig_remotes);
+ if (repo->gotconfig)
+ got_gotconfig_free(repo->gotconfig);
free(repo->gitconfig_author_name);
free(repo->gitconfig_author_email);
for (i = 0; i < repo->ngitconfig_remotes; i++) {
diff --git a/lib/worktree.c b/lib/worktree.c
index 3d078a5..cade3cf 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -55,6 +55,7 @@
#include "got_lib_object_create.h"
#include "got_lib_object_idset.h"
#include "got_lib_diff.h"
+#include "got_lib_gotconfig.h"
#ifndef MIN
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
@@ -416,6 +417,18 @@ open_worktree(struct got_worktree **worktree, const char *path)
err = read_meta_file(&(*worktree)->head_ref_name, path_got,
GOT_WORKTREE_HEAD_REF);
+ if (err)
+ goto done;
+
+ if (asprintf(&(*worktree)->gotconfig_path, "%s/%s/%s",
+ (*worktree)->root_path,
+ GOT_WORKTREE_GOT_DIR, GOT_GOTCONFIG_FILENAME) == -1) {
+ err = got_error_from_errno("asprintf");
+ goto done;
+ }
+
+ err = got_gotconfig_read(&(*worktree)->gotconfig,
+ (*worktree)->gotconfig_path);
done:
if (repo)
got_repo_close(repo);
@@ -468,6 +481,8 @@ got_worktree_close(struct got_worktree *worktree)
err = got_error_from_errno2("close",
got_worktree_get_root_path(worktree));
free(worktree->root_path);
+ free(worktree->gotconfig_path);
+ got_gotconfig_free(worktree->gotconfig);
free(worktree);
return err;
}
@@ -483,7 +498,6 @@ got_worktree_get_repo_path(struct got_worktree *worktree)
{
return worktree->repo_path;
}
-
const char *
got_worktree_get_path_prefix(struct got_worktree *worktree)
{
@@ -598,6 +612,12 @@ done:
return err;
}
+const struct got_gotconfig *
+got_worktree_get_gotconfig(struct got_worktree *worktree)
+{
+ return worktree->gotconfig;
+}
+
static const struct got_error *
lock_worktree(struct got_worktree *worktree, int operation)
{
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index 13a4e58..7e2e93f 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -736,6 +736,45 @@ function test_commit_gotconfig_author {
test_done "$testroot" "$ret"
}
+function test_commit_gotconfig_worktree_author {
+ local testroot=`test_init commit_gotconfig_worktree_author`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
+ > $testroot/repo/.git/got.conf
+ echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
+ > $testroot/wt/.got/got.conf
+
+ echo "modified alpha" > $testroot/wt/alpha
+ (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "from: Flan Squee <flan_squee@openbsd.org>" \
+ > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
function test_commit_gitconfig_author {
local testroot=`test_init commit_gitconfig_author`
@@ -1335,6 +1374,7 @@ run_test test_commit_outside_refs_heads
run_test test_commit_no_email
run_test test_commit_tree_entry_sorting
run_test test_commit_gotconfig_author
+run_test test_commit_gotconfig_worktree_author
run_test test_commit_gitconfig_author
run_test test_commit_xbit_change
run_test test_commit_normalizes_filemodes
diff --git a/regress/cmdline/fetch.sh b/regress/cmdline/fetch.sh
index 22fde4a..a131768 100755
--- a/regress/cmdline/fetch.sh
+++ b/regress/cmdline/fetch.sh
@@ -948,6 +948,85 @@ function test_fetch_headref_deleted_locally {
test_done "$testroot" "$ret"
}
+function test_fetch_gotconfig_remote_repo {
+ local testroot=`test_init fetch_gotconfig_remote_repo`
+ local testurl=ssh://127.0.0.1/$testroot
+ local commit_id=`git_show_head $testroot/repo`
+
+ got branch -r $testroot/repo -c $commit_id foo
+ got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
+ got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
+
+ got clone -q $testurl/repo $testroot/repo-clone
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got clone command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+cat > $testroot/repo-clone/got.conf <<EOF
+remote "foobar" {
+ protocol ssh
+ server 127.0.0.1
+ repository "$testroot/repo"
+}
+
+remote "barbaz" {
+ protocol ssh
+ server 127.0.0.1
+ repository "$testroot/does-not-exist"
+}
+EOF
+ (cd $testroot/repo-clone && got fetch -l foobar \
+ > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got fetch command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "Connecting to \"foobar\" 127.0.0.1" > $testroot/stdout.expected
+ got ref -l -r $testroot/repo >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+
+cat > $testroot/wt/.got/got.conf <<EOF
+remote "barbaz" {
+ protocol ssh
+ server 127.0.0.1
+ repository "$testroot/repo"
+}
+EOF
+ (cd $testroot/wt && got fetch -l barbaz > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got fetch command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "Connecting to \"barbaz\" 127.0.0.1" > $testroot/stdout.expected
+ got ref -l -r $testroot/repo >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+
+}
+
test_parseargs "$@"
run_test test_fetch_basic
run_test test_fetch_list
@@ -960,3 +1039,4 @@ run_test test_fetch_reference
run_test test_fetch_replace_symref
run_test test_fetch_update_headref
run_test test_fetch_headref_deleted_locally
+run_test test_fetch_gotconfig_remote_repo
diff --git a/regress/fetch/Makefile b/regress/fetch/Makefile
index 9834aee..f9e0d6b 100644
--- a/regress/fetch/Makefile
+++ b/regress/fetch/Makefile
@@ -4,7 +4,7 @@ PROG = fetch_test
SRCS = error.c privsep.c reference.c sha1.c object.c object_parse.c path.c \
opentemp.c repository.c lockfile.c object_cache.c pack.c inflate.c \
deflate.c delta.c delta_cache.c object_idset.c object_create.c \
- fetch.c fetch_test.c
+ fetch.c gotconfig.c fetch_test.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz
diff --git a/tog/Makefile b/tog/Makefile
index aafde1a..41af3be 100644
--- a/tog/Makefile
+++ b/tog/Makefile
@@ -8,7 +8,8 @@ SRCS= tog.c blame.c commit_graph.c delta.c diff.c \
object_idset.c object_parse.c opentemp.c path.c pack.c \
privsep.c reference.c repository.c sha1.c worktree.c \
utf8.c inflate.c buf.c rcsutil.c diff3.c \
- lockfile.c deflate.c object_create.c delta_cache.c
+ lockfile.c deflate.c object_create.c delta_cache.c \
+ gotconfig.c
MAN = ${PROG}.1
CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib