From 4ab2d17b2b1cb936f99fdb9fd640b00f99cca4a9 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 27 Jun 2021 14:40:15 -0700 Subject: [PATCH] toolbox/projtool.pl: add urls subcommand Add a convenient "urls" subcommand to display the various Git fetch/push URLs that are available for a project and would be shown by gitweb.cgi thereby making this information easily obtainable directly from the command line. As a convenience allow the URLs to be limited to only "push" URLs with the --push option. Signed-off-by: Kyle J. McKay --- toolbox/projtool.pl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/toolbox/projtool.pl b/toolbox/projtool.pl index 30d912c..a61d473 100755 --- a/toolbox/projtool.pl +++ b/toolbox/projtool.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # projtool.pl - command line Girocco project maintenance tool -# Copyright (C) 2016,2017,2020 Kyle J. McKay. All rights reserved. +# Copyright (C) 2016,2017,2020,2021 Kyle J. McKay. All rights reserved. # License GPLv2+: GNU GPL version 2 or later. # www.gnu.org/licenses/gpl-2.0.html # This is free software: you are free to change and redistribute it. @@ -102,6 +102,14 @@ Usage: %s [...] show show project + urls [--push] + show available fetch/push URLs for + Note that this does NOT include non-Git protocol URLs such + as any home page or any upstream URL for a mirror project -- + those are all accessible via the "show" command. + The URLs shown are those that would be shown by gitweb.cgi. + With --push only show push urls (mirrors have no push urls) + listheads list all available heads for and indicate current head @@ -1197,6 +1205,58 @@ sub cmd_show { return 0; } +sub cmd_urls { + my $pushonly; + parse_options("push" => \$pushonly); + my @projs = @ARGV; + @ARGV == 1 or die_usage; + my $project = get_project($ARGV[0]); + my $suffix = "/".$project->{name}.".git"; + @Gitweb::Config::git_base_url_list = (); + @Gitweb::Config::git_base_push_urls = (); + @Gitweb::Config::git_base_mirror_urls = (); + { + package Gitweb::Config; + do $Girocco::Config::basedir."/gitweb/gitweb_config.perl"; + !$! or die "could not read gitweb_config.perl: $!\n"; + !$@ or die "could not parse gitweb_config.perl: $@\n"; + } + my @fetch_urls = (); + my @push_urls = (); + my $add_url = sub { + my $array = shift; + foreach (@_) { + if (ref($_)) { + ref($_) eq 'ARRAY' or die "expected ARRAY ref"; + my $u = $$_[0]; + defined($u) && $u ne "" and + push(@$array, $u.$suffix); + } elsif (defined($_) && $_ ne "") { + push(@$array, $_.$suffix); + } + } + }; + my $uniq = sub { + my %items = (); + $items{$_} = 1 foreach @_; + sort(keys(%items)); + }; + &$add_url(\@fetch_urls, @Gitweb::Config::git_base_url_list); + if ($project->{mirror}) { + &$add_url(\@fetch_urls, @Gitweb::Config::git_base_mirror_urls); + } else { + &$add_url(\@push_urls, @Gitweb::Config::git_base_push_urls); + } + my @urls = (); + if ($pushonly) { + push(@urls, &$uniq(@push_urls)); + } else { + push(@urls, &$uniq(@fetch_urls, @push_urls)); + } + print map "$_\n", @urls; + return 0; +} + sub cmd_listheads { @ARGV == 1 or die_usage; my $project = get_project($ARGV[0]); @@ -2021,6 +2081,7 @@ BEGIN { delete => \&cmd_remove, prune => \&cmd_prune, show => \&cmd_show, + urls => \&cmd_urls, listheads => \&cmd_listheads, listtags => \&cmd_listtags, listctags => \&cmd_listtags, @@ -2089,6 +2150,7 @@ BEGIN { %nopager = ( setmsgs => -1, setusers => -1, set => -1, + urls => -1, )} sub dohelp { -- 2.11.4.GIT