+# abs_path resolves symlinks, so we want to avoid it if rel2abs
+# is sufficient and doesn't leave "/.." or "/../"
+sub rel2abs_collapsed {
+ require File::Spec;
+ my $p = File::Spec->rel2abs($_[-1]);
+ return $p if substr($p, -3, 3) ne '/..' && index($p, '/../') < 0;
+ require Cwd;
+ Cwd::abs_path($p);
+}
+
+sub get_1 {
+ my ($self, $key) = @_;
+ my $v = $self->{$key};
+ return $v if !ref($v);
+ warn "W: $key has multiple values, only using `$v->[-1]'\n";
+ $v->[-1];
+}
+
+sub repo_objs {
+ my ($self, $ibxish) = @_;
+ my $ibx_code_repos = $ibxish->{coderepo} // return;
+ $ibxish->{-repo_objs} // do {
+ parse_cgitrc($self, undef, 0);
+ my $code_repos = $self->{-code_repos};
+ my @repo_objs;
+ for my $nick (@$ibx_code_repos) {
+ my @parts = split(m!/!, $nick);
+ for (@parts) {
+ @parts = () unless valid_foo_name($_);
+ }
+ unless (@parts) {
+ warn "invalid coderepo name: `$nick'\n";
+ next;
+ }
+ my $repo = $code_repos->{$nick} //=
+ fill_code_repo($self, $nick);
+ push @repo_objs, $repo if $repo;
+ }
+ if (scalar @repo_objs) {
+ require Scalar::Util;
+ for (@repo_objs) {
+ push @{$_->{-ibxs}}, $ibxish;
+ Scalar::Util::weaken($_->{-ibxs}->[-1]);
+ }
+ $ibxish->{-repo_objs} = \@repo_objs;
+ } else {
+ delete $ibxish->{coderepo};
+ }
+ }
+}