From 7e1a3911688855910623e432719f29c95f56f023 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 2 Jul 2021 13:55:12 -0700 Subject: [PATCH] projtool.pl: allow existing projects to be specified by path Where an existing project is required, accept a path to that project and make a best effort attempt to translate that path to a project name before giving up with an error. For safety, make the remove command continue to only accept project names. The prune command, by its very nature, only accepts project names as it's looking for missing directories. Add a note about all this to the beginning of the help output including a mention of the convenient "." shortcut. Signed-off-by: Kyle J. McKay --- toolbox/projtool.pl | 56 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/toolbox/projtool.pl b/toolbox/projtool.pl index 000e4c1..09bfb58 100755 --- a/toolbox/projtool.pl +++ b/toolbox/projtool.pl @@ -36,6 +36,13 @@ Usage: %s [...] -p | --pager force output to be paginated --no-pager never paginate output + Note that as a convenience, where an existing is required as + an argument, a path to the project may be given instead of the name in + most places. The "remove" and "prune" commands only accept names. + Since a matching project name takes precedence over a path, to force + interpretation as a path, start the path with "/" or "./" or "../". + Giving "." will find the project matching the current working directory. + help [] show full help or just for if given @@ -115,6 +122,7 @@ Usage: %s [...] listtags [--verbose] list all ctags on project + with --verbose include tag counts deltags [-i] remove any ctags on project present in @@ -285,7 +293,7 @@ sub get_ctag_counts { } sub get_clean_project { - my $project = get_project(@_); + my $project = get_project_harder(@_); delete $project->{loaded}; delete $project->{base_path}; delete $project->{ccrypt}; @@ -1101,7 +1109,7 @@ sub cmd_remove { "keep-forks" => \$keepforks, quiet => \$quiet, q =>\$quiet); @ARGV or die "Please give project name on command line.\n"; @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project($ARGV[0]); # for safety only names accepted here my $projname = $project->{name}; my $isempty = !$project->{mirror} && $project->is_empty; if (!$project->{mirror} && !$isempty && $reallydel) { @@ -1211,7 +1219,7 @@ sub cmd_urls { parse_options("push" => \$pushonly); my @projs = @ARGV; @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $suffix = "/".$project->{name}.".git"; @Gitweb::Config::git_base_url_list = (); @Gitweb::Config::git_base_push_urls = (); @@ -1260,7 +1268,7 @@ sub cmd_urls { sub cmd_listheads { @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my @heads = sort({lc($a) cmp lc($b)} $project->get_heads); my $cur = $project->{HEAD}; defined($cur) or $cur = ''; @@ -1280,7 +1288,7 @@ sub cmd_listtags { my $vcnt = 0; shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose' || $ARGV[0] eq '-v'); @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); if ($vcnt) { print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project)); } else { @@ -1293,7 +1301,7 @@ sub cmd_deltags { my $ic = 0; shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i; @ARGV >= 2 or die_usage; - my $project = get_project(shift @ARGV); + my $project = get_project_harder(shift @ARGV); my %curtags; if ($ic) { push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names; @@ -1324,7 +1332,7 @@ sub cmd_deltags { sub cmd_addtags { @ARGV >= 2 or die_usage; - my $project = get_project(shift @ARGV); + my $project = get_project_harder(shift @ARGV); my $ctags = join(" ", @ARGV); $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n"; @@ -1360,7 +1368,7 @@ sub cmd_chpass { my $random = undef; pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i; @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); die "refusing to change locked password of project \"$ARGV[0]\" without --force\n" if $project->is_password_locked; my ($newpw, $rmsg); @@ -1405,7 +1413,7 @@ sub cmd_chpass { sub cmd_checkpw { @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $pwhash = $project->{crypt}; defined($pwhash) or $pwhash = ""; if ($pwhash eq "") { @@ -1443,7 +1451,7 @@ sub cmd_gc { $force && $auto and die "--force and --auto are mutually exclusive options\n"; @ARGV or die "Please give project name on command line.\n"; @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); delete $ENV{show_progress}; delete $ENV{force_gc}; $quiet or $ENV{"show_progress"} = 1; @@ -1472,7 +1480,7 @@ sub cmd_update { $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n"; @ARGV or die "Please give project name on command line.\n"; @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); $project->{mirror} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n"; delete $ENV{show_progress}; delete $ENV{force_update}; @@ -1491,7 +1499,7 @@ sub cmd_remirror { parse_options(force => \$force, quiet => \$quiet, q => \$quiet); @ARGV or die "Please give project name on command line.\n"; @ARGV == 1 or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); $project->{mirror} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n"; if ($project->{clone_in_progress} && !$project->{clone_failed}) { warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force; @@ -1518,7 +1526,7 @@ sub cmd_setowner { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); if (@ARGV == 2 && !valid_email($ARGV[1])) { die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n" unless $force; @@ -1550,7 +1558,7 @@ sub cmd_setdesc { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; - my $project = get_project(shift @ARGV); + my $project = get_project_harder(shift @ARGV); if (@ARGV && !valid_desc(join(" ", @ARGV))) { die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n" unless $force; @@ -1585,7 +1593,7 @@ sub cmd_setreadme { @ARGV == 2 || (@ARGV == 1 && !$force && !defined($readmetype) && !$setopt) or die_usage; defined($readmetype) and $readmetype = Girocco::Project::_normalize_rmtype($readmetype,1); defined($readmetype) && !$readmetype and die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $old = $project->{READMEDATA}; if (@ARGV == 1) { chomp $old if defined($old); @@ -1669,7 +1677,7 @@ sub valid_head { sub cmd_sethead { @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); if (@ARGV == 2 && !valid_head($project, $ARGV[1])) { die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n"; } @@ -1693,7 +1701,7 @@ sub cmd_sethooks { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $projconfig = read_config_file_hash($project->{path}."/config"); my $ghp = $Girocco::Config::reporoot."/_global/hooks"; my $rghp = realpath($ghp); @@ -1778,7 +1786,7 @@ sub cmd_setbool { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); if (!exists($boolfields{$ARGV[1]})) { die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n"; } @@ -1808,7 +1816,7 @@ sub cmd_setbool { sub cmd_setjsontype { @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $jsontype; if (@ARGV == 2) { my $jt = lc($ARGV[1]); @@ -1835,7 +1843,7 @@ sub cmd_setjsontype { sub cmd_setjsonsecret { @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $jsonsecret; if (@ARGV == 2) { my $js = $ARGV[1]; @@ -1859,7 +1867,7 @@ sub cmd_setjsonsecret { sub cmd_setautogchack { @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); my $aghok = $Girocco::Config::autogchack && ($project->{mirror} || $Girocco::Config::autogchack ne "mirror"); my $old = defined($project->{autogchack}) ? clean_bool($project->{autogchack}) : "unset"; @@ -1918,7 +1926,7 @@ sub cmd_seturl { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage; - my $project = get_project($ARGV[0]); + my $project = get_project_harder($ARGV[0]); if (!exists($urlfields{$ARGV[1]})) { die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n"; } @@ -1964,7 +1972,7 @@ sub cmd_setmsgs { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage; - my $project = get_project(shift @ARGV); + my $project = get_project_harder(shift @ARGV); my $field = shift @ARGV; if (!exists($msgsfields{$field})) { die "invalid msgs field name: \"$field\" -- try \"help\"\n"; @@ -1994,7 +2002,7 @@ sub cmd_setusers { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; - my $project = get_project(shift @ARGV); + my $project = get_project_harder(shift @ARGV); my $projname = $project->{name}; !@ARGV || !$project->{mirror} or die "cannot set users list for mirror project: \"$projname\"\n"; my @newusers = (); -- 2.11.4.GIT