3 # projtool.pl - command line Girocco project maintenance tool
4 # Copyright (C) 2016,2017,2020 Kyle J. McKay. All rights reserved.
5 # License GPLv2+: GNU GPL version 2 or later.
6 # www.gnu.org/licenses/gpl-2.0.html
7 # This is free software: you are free to change and redistribute it.
8 # There is NO WARRANTY, to the extent permitted by law.
12 use vars
qw($VERSION);
13 BEGIN {*VERSION = \'1.0.1'}
15 use Digest::MD5 qw(md5_hex);
18 use POSIX
qw(strftime);
19 use lib
"__BASEDIR__";
22 use Girocco
::HashUtil
;
27 exit(&main
(@ARGV)||0);
30 BEGIN {$help = <<'HELP'}
31 Usage: %s [--quiet] <command> <options>
34 show full help or just for <command> if given
36 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
37 list all projects (default is --sort=lcname)
38 limit to project names matching <regex> if given
39 match <regex> against owner instead of project name with --owner
41 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
42 create new project <project> (prompted)
44 --no-alternates skip setup of objects/info/alternates
45 --orphan allow creation of subproject w/o a parent
46 -p use mkdir -p during --orphan creation
47 --no-password set password crypt to invalid value "unknown"
48 --no-owner leave the gitweb.owner config unset
49 --mirror=<url> create a mirror from <url>
50 --full-mirror mirror all refs
51 --push[=<list>] create a push project
52 --desc=<string> specify project description w/o prompt
53 --defaults do no interactive prompting at all
54 Using --no-password skips the prompts for password, using
55 --no-owner skips the prompt for owner and using --mirror=<url>
56 or --push[=<list>] skips the prompts for mirror URL and
57 heads-only and push users. With --defaults if neither
58 --mirror=<url> nor --push[=<list>] is given then --push will
59 be implied. Using --desc=<string> will force a specific
60 description (including an empty string) and skip the prompt for
61 it. Otherwise a non-empty default description will always be
62 supplied in lieu of an empty or omitted description.
64 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
65 adopt project <project>
66 type of project is guessed if --type=<type> omitted
67 <users> is same as <newuserslist> for setusers command
69 --dry-run do all the checks but don't perform adoption
70 --verbose show project info dump (useful with --dry-run)
71 --no-users no push users at all (<users> must be omitted)
72 --no-owner leave the gitweb.owner config totally unchanged
73 --owner=<val> set the gitweb.owner config to <val>
74 Both --no-owner and --owner=<val> may NOT be given, with neither
75 take owner from preexisting gitweb.owner else use admin setting.
76 For mirrors <users> is ignored otherwise if no <users> and no
77 --no-users option the push users list will consist of the single
78 user name matching the owner or empty if none or more than one.
79 With --dry-run <project> can be an absolute path to a git dir.
81 remove [--force] [--really-delete] [--keep-forks] <project>
82 remove project <project>
83 do not move to _recyclebin with --really-delete (just rm -rf)
84 remove projects with forks (by keeping forks) using --keep-forks
87 show project <project>
90 list all available heads for <project> and indicate current head
92 listtags [--verbose] <project>
93 list all ctags on project <project>
95 deltags <project> [-i] <tagstodel>
96 remove any ctags on project <project> present in <tagstodel>
97 <tagstodel> is space or comma separated list of tags to remove
98 with -i match against <tagstodel> without regard to letter case
100 addtags <project> <tagstoadd>
101 add ctags to project <project>
102 <tagstoadd> is space or comma separated list of tags to add
104 chpass [--force] <project> [random | unknown]
105 change project <project> password (prompted)
106 with "random" set to random password
107 with "unknown" set password hash to invalid value "unknown"
110 check project <project> password for a match (prompted)
112 gc [--force | --auto] [--redelta | --recompress] <project>
113 run the gc.sh script on project <project>
114 with --auto let the gc.sh script decide what to do
115 with --force cause a full gc to take place (force_gc=1)
116 with neither --auto nor --force do a mini or if needed a full gc
117 (in other words just touch .needsgc and run gc.sh)
118 with --redelta a full gc will use pack-objects --no-reuse-delta
119 with --recompress a full gc uses pack-objects --no-reuse-object
120 (--no-reuse-delta and --no-reuse-object are accepted as aliases)
121 unless the global --quiet option is given show_progress=1 is used
123 update [--force] [--quiet | --summary] <project>
124 run the update.sh script on project <project>
125 with --force cause a fetch to always take place (force_update=1)
126 with --quiet only show errors (show_progress is left unset)
127 with --summary show progress and ref summary (show_progress=1)
128 with neither --quiet nor --summary show it all (show_progress=2)
130 remirror [--force] <project>
131 initiate a remirror of project <project>
133 [set]owner [--force] <project> <newowner>
134 set project <project> owner to <newowner>
135 without "set" and only 1 arg, just show current project owner
137 [set]desc [--force] <project> <newdesc>
138 set project <project> description to <newdesc>
139 without "set" and only 1 arg, just show current project desc
141 [set]readme [--force] <project> <newsetting>
142 set project <project> readme to <newsetting>
143 <newsetting> is automatic|suppressed|-|[@]filename
144 without "set" and only 2 args, just show current readme setting
146 [set]head <project> <newhead>
147 set project <project> HEAD symbolic ref to <newhead>
148 without "set" and only 1 arg, just show current project HEAD
150 [set]bool [--force] <project> <flagname> <boolvalue>
151 set project <project> boolean <flagname> to <boolvalue>
152 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
153 without "set" and only 2 args, just show current flag value
155 [set]hooks [--force] <project> local | global | <path>
156 set project <project> hookspath to local, global or <path>
157 without "set" and only 1 arg, just show current hookspath
159 [set]autogchack <project> <boolvalue> | unset
160 set project <project> autogchack to <boolvalue> or "unset" it
161 without "set" just show current autogchack setting if enabled
162 with "set" autogchack must be enabled in Config.pm for the
163 type of project and maintain-auto-gc-hack.sh is always run
165 [set]url [--force] <project> <urlname> <newurlvalue>
166 set project <project> url <urlname> to <newurlvalue>
167 <urlname> is baseurl|homepage|notifyjson
168 without "set" and only 2 args, just show current url value
170 [set]msgs [--force] <project> <msgsname> <eaddrlist>
171 set project <project> msgs <msgsname> to <addrlist>
172 <msgsname> is notifymail|notifytag
173 <eaddrlist> is space or comma separated list of email addresses
174 without "set" and only 2 args, just show current msgs value
176 [set]users [--force] <project> <newuserslist>
177 set push project <project> users list to <newuserslist>
178 <newuserslist> is space or comma separated list of user names
179 without "set" and only 1 arg, just show current users list
181 get <project> <fieldname>
182 show project <project> field <fieldname>
183 <fieldname> is owner|desc|readme|head|hooks|users
184 or <flagname>|autogchack|<urlname>|<msgsname>
186 set [--force] <project> <fieldname> <newfieldvalue>
187 set project <project> field <fieldname> to <newfieldvalue>
188 <fieldname> same as for get
189 <newfieldvalue> same as for corresponding set... command
195 my $sub = shift || diename
;
197 die "Invalid arguments to $sub command -- try \"help\"\n";
199 die "Invalid arguments -- try \"help\"\n";
203 sub get_readme_desc
{
205 defined($rm) or $rm = '';
208 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
210 return $test eq '' ?
"suppressed" : "length " . length($rm);
216 sub get_ctag_counts
{
220 foreach ($project->get_ctag_names) {
223 if (open $ct, '<', $project->{path
}."/ctags/$_") {
226 defined $count or $count = '';
228 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
234 push(@ctags, $_."(".$val.")");
237 push(@ctags, [$_, $val]) if $val;
243 sub get_clean_project
{
244 my $project = get_project
(@_);
245 delete $project->{loaded
};
246 delete $project->{base_path
};
247 delete $project->{ccrypt
};
248 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
249 $project->{owner
} = $project->{email
}; delete $project->{email
};
250 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
251 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
252 my $owner = $project->{owner
};
255 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
256 $project->{owner_users
} = \
@owner_users if @owner_users;
258 my $projname = $project->{name
};
259 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
260 $project->{has_forks
} = 1 if @forks;
261 $project->{has_alternates
} = 1 if $project->has_alternates;
262 my @bundles = $project->bundles;
263 for (my $i = 0; $i < @bundles; ++$i) {
264 my $secs = $bundles[$i]->[0];
265 $bundles[$i]->[0] = strftime
("%Y-%m-%dT%H:%M:%S%z", localtime($secs));
266 my $sz = $bundles[$i]->[2];
267 1 while $sz =~ s/(?<=\d)(\d{3})(?:,|$)/,$1/g;
268 $bundles[$i]->[2] = $sz;
270 delete $project->{bundles
};
271 $project->{bundles
} = \
@bundles if @bundles;
272 $project->{mirror
} = 0 unless $project->{mirror
};
273 $project->{is_empty
} = 1 if $project->is_empty;
274 delete $project->{showpush
} unless $project->{showpush
};
275 delete $project->{users
} if $project->{mirror
};
276 delete $project->{baseurl
} unless $project->{mirror
};
277 delete $project->{banged
} unless $project->{mirror
};
278 delete $project->{lastrefresh
} unless $project->{mirror
};
279 delete $project->{cleanmirror
} unless $project->{mirror
};
280 delete $project->{statusupdates
} unless $project->{mirror
};
281 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
282 unless ($project->{banged
}) {
283 delete $project->{bangcount
};
284 delete $project->{bangfirstfail
};
285 delete $project->{bangmessagesent
};
287 my $projhook = $project->_has_notifyhook;
288 if (defined($projhook) && $projhook ne "") {
289 $project->{notifyhook
} = $projhook;
291 delete $project->{notifyhook
};
293 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
294 my @tags = get_ctag_counts
($project, 1);
295 $project->{tags
} = \
@tags if @tags;
296 my $projconfig = read_config_file_hash
($project->{path
}."/config");
297 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
298 my $ahp = $projconfig->{"core.hookspath"};
299 my $rahp = realpath
($ahp);
300 my $lhp = $project->{path
}."/hooks";
301 my $rlhp = realpath
($lhp);
302 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
303 my $rghp = realpath
($ghp);
304 $project->{has_local_hooks
} = 1 if
305 defined($rahp) && defined($rlhp) && $rahp eq $rlhp;
306 $project->{has_global_hooks
} = 1 if
307 defined($rahp) && defined($rghp) && $rahp eq $rghp;
308 $project->{hookspath
} = $ahp unless $ahp eq $lhp || $ahp eq $ghp;
316 foreach (split(/[,\s]+/, $_[0])) {
318 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
320 return join(($_[1]||","), @newlist);
324 my $cleaned = clean_addrlist
(join(" ", @_));
325 return 1 if $cleaned eq "";
326 valid_email_multi
($cleaned) && length($cleaned) <= 512;
330 my ($userlist, $force, $nodie, $quiet) = @_;
334 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
335 my %users = map({($$_[1] => $_)} get_all_users
);
336 foreach (split(/[\s,]+/, $userlist)) {
337 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
338 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
341 if (Girocco
::User
::does_exist
($_, 1)) {
343 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
346 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
351 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
353 die if $badlist && !$nodie;
357 sub is_default_desc
{
358 # "Unnamed repository; edit this file 'description' to name the repository."
359 # "Unnamed repository; edit this file to name it for gitweb."
361 return 0 unless defined($_);
362 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
368 return 0 if $test =~ /[\r\n]/;
369 $test =~ s/\s\s+/ /g;
377 defined($desc) or $desc = '';
379 $desc = to_utf8
($desc, 1);
380 $desc =~ s/\s\s+/ /g;
387 Girocco
::CLIUtil
::_parse_options
(
389 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
397 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
398 name
=> sub {$$a[1] cmp $$b[1]},
399 gid
=> sub {$$a[3] <=> $$b[3]},
400 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
401 no => sub {$$a[0] <=> $$b[0]},
403 my $sortopt = 'lcname';
404 my ($verbose, $owner);
405 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
408 my $val = shift @ARGV;
409 $regex = qr
($val) or die "bad regex \"$val\"\n";
411 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
412 my $sortsub = $sortsub{$sortopt};
413 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
414 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
416 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
418 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
424 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
425 $ismirror, $desc, $fullmirror);
427 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
428 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
429 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
430 ":description" => \
$desc, "full-mirror" => \
$fullmirror);
431 @ARGV == 1 or die_usage
;
432 !defined($pushusers) || defined($ispush) or $ispush = 1;
433 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
434 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
435 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
436 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
437 !$defaults || defined($nopasswd) or $nopasswd = 1;
438 !$defaults || defined($noowner) or $noowner = 1;
439 !defined($ispush) || defined($pushusers) or $pushusers = "";
440 my $projname = $ARGV[0];
441 $projname =~ s/\.git$//i;
442 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
443 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
444 warn "Refusing to create orphan project without --orphan\n"
445 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
446 warn "Required orphan parent directory does not exist (use -p): ",
447 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
448 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
449 die "Invalid project name: \"$projname\"\n";
451 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
452 my $newtype = $forkee ?
'fork' : 'project';
453 if (length($project) > 64) {
454 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
456 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
458 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
459 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
460 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
462 print "Enter settings for new project \"$projname\"\n" unless $defaults;
464 $settings{noalternates
} = $noalternates;
466 $settings{crypt} = "unknown";
468 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
469 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
470 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
471 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
472 "the admin passwords you have entered do not match each other.\n";
473 $settings{crypt} = scrypt_sha1
($np1);
477 $owner = prompt_or_die
("Owner/email name for project $projname");
478 unless (valid_email
($owner)) {
480 warn "Your email sure looks weird...?\n";
483 warn "Allowing invalid email with --force\n" unless $quiet;
485 if (length($owner) > 96) {
487 warn "Your email is longer than 96 characters. Do you really need that much?\n";
490 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
493 $settings{email
} = $owner;
495 my $checkmirror = sub {
496 my $checkurl = shift;
497 unless (valid_repo_url
($checkurl)) {
499 warn "Invalid mirror URL: \"$checkurl\"\n";
502 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
504 if ($Girocco::Config
::restrict_mirror_hosts
) {
505 my $mh = extract_url_hostname
($checkurl);
506 unless (is_dns_hostname
($mh)) {
508 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
511 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
513 if (is_our_hostname
($mh)) {
515 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
518 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
523 if ($ispush || $ismirror) {
524 !$ispush || $force || $Girocco::Config
::push or
525 die "Push projects are disabled, create a mirror (or use --force)\n";
526 !$ismirror || $force || $Girocco::Config
::mirror
or
527 die "Mirror projects are disabled, create a push project (or use --force)\n";
529 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
530 $baseurl = $ismirror;
531 $settings{url
} = $baseurl;
532 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
535 if ($pushusers !~ /^[\s,]*$/) {
536 eval {@newusers = validate_users
($pushusers, $force); 1;} or
537 die "Invalid --push user list\n";
539 $settings{users
} = \
@newusers;
541 } elsif ($force || $Girocco::Config
::mirror
) {{
542 if ($force || $Girocco::Config
::push) {
543 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
545 $baseurl = prompt_or_die
("URL to mirror from");
546 unless ($baseurl ne "") {
547 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
551 if ($baseurl ne "") {
552 &$checkmirror($baseurl) or redo;
553 $settings{url
} = $baseurl;
554 $settings{cleanmirror
} =
555 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
558 my $mirror = ($baseurl eq "") ?
0 : 1;
559 my $checkdesc = sub {
561 if (length($d) > 1024) {
563 warn "Short description length greater than 1024 characters!\n";
566 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
570 if (defined($desc)) {
571 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
572 $desc eq "" || &$checkdesc($desc) or
573 die "Invalid --desc description\n";
574 } elsif (!$defaults) {
575 $desc = prompt_or_die
("Short description", "");
576 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
577 $desc eq "" || &$checkdesc($desc) or redo;
578 $desc = undef if $desc eq "";
580 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
581 $settings{desc
} = $desc;
584 $homepage = prompt_or_die
("Home page URL", "");
585 if ($homepage ne "" && !valid_web_url
($homepage)) {
587 warn "Invalid home page URL: \$homepage\"\n";
590 warn "Allowing invalid home page URL with --force\n" unless $quiet;
593 $settings{hp
} = $homepage;
596 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
597 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
599 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
602 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
605 $settings{notifyjson
} = $jsonurl;
606 my $commitaddrs = "";
608 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
609 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
611 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
614 warn "using invalid commit notify email address list with --force\n" unless $quiet;
617 $settings{notifymail
} = $commitaddrs;
618 $settings{reverseorder
} = 1;
619 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
620 if !$defaults && $commitaddrs ne "";
621 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
622 if !$defaults && $commitaddrs ne "";
625 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
626 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
628 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
631 warn "using invalid tag notify email address list with --force\n" unless $quiet;
634 $settings{notifytag
} = $tagaddrs;
635 if (!$mirror && !$ispush) {
638 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
639 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
641 $settings{users
} = \
@newusers;
643 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
644 or die "Girocco::Project->ghost call failed\n";
646 $newproj->{$k} = $v while ($k, $v) = each(%settings);
647 my $killowner = sub {
648 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
649 'config', '--unset', "gitweb.owner");
652 $newproj->premirror or die "Girocco::Project->premirror failed\n";
653 !$noowner or &$killowner;
654 $newproj->clone or die "Girocco::Project->clone failed\n";
655 warn "Project $projname created and cloning successfully initiated.\n"
658 $newproj->conjure or die "Girocco::Project->conjure failed\n";
659 !$noowner or &$killowner;
660 warn "New push project fork is empty due to use of --no-alternates\n"
661 if !$quiet && $projname =~ m
,/, && $noalternates;
662 warn "Project $projname successfully created.\n" unless $quiet;
669 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
670 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
674 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
675 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
676 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
677 @ARGV or die "Please give project name on command line.\n";
678 my $projname = shift @ARGV;
679 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
680 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
681 defined($type) or $type = "";
683 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
684 $projdir = realpath
($projname);
685 $projname = $projdir;
686 $projname =~ s/\.git$//i;
687 $projname =~ s
,/+$,,;
688 $projname =~ s
,^.*/,,;
689 $projname ne "" or $projname = $projdir;
691 $projname =~ s/\.git$//i;
692 $projname ne "" or die "Invalid project name \"\".\n";
693 unless (Girocco
::Project
::does_exist
($projname, 1)) {
694 Girocco
::Project
::valid_name
($projname, 1, 1)
695 or die "Invalid project name \"$projname\".\n";
696 die "No such project to adopt: $projname\n";
698 defined(Girocco
::Project
->load($projname))
699 and die "Project already known (no need to adopt): $projname\n";
700 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
701 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
703 my $config = read_config_file
($projdir . "/config");
705 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
706 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
707 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
708 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1, $quiet)];
710 if (-e
"$projdir/description") {
711 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
717 defined $desc or $desc = "";
719 $desc = to_utf8
($desc, 1);
720 is_default_desc
($desc) and $desc = "";
721 if ($desc ne "" && !valid_desc
($desc)) {
722 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
724 warn "using invalid 'description' file contents with --force\n" unless $quiet;
726 $desc = clean_desc
($desc);
727 if (length($desc) > 1024) {
728 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
730 warn "using longer than 1024 char description with --force\n" unless $quiet;
734 if (-e
"$projdir/README.html") {
735 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
741 defined $readme or $readme = "";
742 $readme = to_utf8
($readme, 1);
743 $readme =~ s/\r\n?/\n/gs;
744 $readme =~ s/^\s+//s;
745 $readme =~ s/\s+$//s;
746 $readme eq "" or $readme .= "\n";
747 if (length($readme) > 8192) {
748 die "readme greater than 8192 chars is too long (use --force to override)\n"
750 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
752 my $rd = get_readme_desc
($readme);
753 if ($rd ne "automatic" && $rd ne "suppressed") {
754 my $xmllint = qx(sh
-c
'command -v xmllint'); chomp $xmllint;
755 if (-f
$xmllint && -x
$xmllint) {
756 my $dummy = {README
=> $readme};
757 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
759 my $msg = "xmllint: $cnt error";
760 $msg .= "s" unless $cnt == 1;
761 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
762 unless $force && $quiet;
763 exit(255) unless $force;
764 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
767 die "xmllint not available, refusing to use raw HTML without --force\n"
769 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
773 # Inspect any remotes now
774 # Yes, Virginia, remote urls can be multi-valued
778 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
779 my ($name, $subkey) = ($1, $2);
780 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
781 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
782 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
783 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
784 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
786 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
787 # the remote names in a group are separated by runs of [ \t\n] characters
788 # remote names "", ".", ".." and any name starting with "/" are invalid
789 # a remote with no url or vcs setting is not considered valid
792 if (exists($config{"remotes
.default"})) {
793 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
794 next unless exists($remotes{$_});
795 my $rmt = $remotes{$_};
796 next if !exists($rmt->{url}) && !$rmt->{vcs};
804 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
805 next if $seenrmt{$1};
807 next unless exists($remotes{$1});
808 my $rmt = $remotes{$1};
809 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
813 my @needskip = (); # remotes that need skipDefaultUpdate set to true
816 my $foundfetchwithmirror = 0;
818 my $rmt = $remotes{$_};
819 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
820 next unless exists($rmt->{fetch});
822 ++$foundfetchwithmirror if $rmt->{mirror};
823 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
825 # if we have $foundvcs then we need to explicitly set fetch.prune to false
826 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
827 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
829 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
830 # if remote "origin
" exists we always pick up its first url or use ""
831 if (exists($remotes{origin})) {
832 my $rmt = $remotes{origin};
833 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
834 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
837 # get the first url of the @check remotes
839 my $rmt = $remotes{$_};
840 next unless exists($rmt->{url});
841 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
842 $baseurl = $rmt->{url}->[0];
846 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
848 # If we have $foundfetch we want to make a mirror but complain if
849 # we $foundfetchwithmirror as well unless we have --type=mirror.
850 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
851 # Warn if we need to set fetch.prune=false when making a mirror
852 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
853 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
854 # Warn if $usingall and any @needskip (and set them) if making a mirror
855 # Warn if making a mirror and $baseurl eq ""
856 # Warn if we have --type=mirror and !$foundfetch
859 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
860 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
861 if ($foundfetchwithmirror) {
862 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
863 "(Use
--type
=mirror to override
)\n"
864 unless $type eq "mirror
";
865 exit(255) unless $type eq "mirror
" || $dryrun;
866 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
867 unless $quiet || $type ne "mirror
";
869 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
870 if !$quiet && $neednoprune;
871 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
872 if !$quiet && $needfakeorigin;
873 if (!$usingall && @needskip) {
874 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
876 exit(255) unless $force || $dryrun;
877 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
878 unless $quiet || !$force;
880 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
881 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
883 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
884 if !$quiet && $foundfetch && !$foundfetchwithmirror;
887 if (!$noowner && !defined($owner)) {
889 $owner = $config{"gitweb
.owner
"};
890 if (!defined($owner) || $owner eq "") {
891 $owner = $Girocco::Config::admin;
892 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
895 if (!$nousers && !$makemirror && !defined($users)) {
896 # select user list for push project
897 my $findowner = $owner;
898 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
899 $findowner = lc($findowner) if defined($findowner);
900 my @owner_users = ();
901 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
902 if defined($findowner) && $findowner ne "";
903 if (@owner_users <= 1) {
904 $users = \@owner_users;
905 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
908 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
909 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
912 defined($users) or $users = [];
914 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
915 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
916 # and warn about preserving the setting)
918 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
919 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
920 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
921 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
922 $config{"receive
.denydeletecurrent
"} ne "warn";
924 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
925 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
926 if ($reflogactive || $reflogfiles) {
927 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
928 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
929 exit(255) unless $force || $dryrun;
930 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
931 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
934 return 0 if $dryrun && !$verbose;
936 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
937 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
938 $newproj->{desc} = $desc;
939 $newproj->{README} = $readme;
940 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
941 $newproj->{email} = $owner if defined($owner);
942 $newproj->{users} = $users;
943 $newproj->{crypt} = "unknown
";
944 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
945 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
946 my $dummy = bless {}, "Girocco
::Project
";
947 $dummy->{path} = "$projdir";
948 $dummy->{configfilehash} = \%config;
949 $dummy->_properties_load;
950 delete $dummy->{origurl};
951 foreach my $k (keys(%$dummy)) {
952 $newproj->{$k} = $dummy->{$k}
953 if exists($dummy->{$k}) && !exists($newproj->{$k});
958 my %info = %$newproj;
959 $info{README} = get_readme_desc($info{README}) if exists($info{README});
960 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
961 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
962 print $d->Dump([\%info], ['*'.$newproj->{name}]);
966 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
968 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
969 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
970 if ($usingall && @needskip) {
971 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
975 # Perform the actual adoption
976 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
978 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
979 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
980 if git_bool($config{"receive
.denynonfastforwards
"});
981 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
982 if exists($config{"receive
.denydeletecurrent
"}) &&
983 $config{"receive
.denydeletecurrent
"} ne "warn";
984 git_config($projdir, "core
.logAllRefUpdates
", "true
")
989 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
991 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
997 my ($force, $reallydel, $keepforks);
998 parse_options(force => \$force, "really
-delete" => \$reallydel,
999 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
1000 @ARGV or die "Please give project name on command line
.\n";
1001 @ARGV == 1 or die_usage;
1002 my $project = get_project($ARGV[0]);
1003 my $projname = $project->{name};
1004 my $isempty = !$project->{mirror} && $project->is_empty;
1005 if (!$project->{mirror} && !$isempty && $reallydel) {
1006 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
1007 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
1011 if ($project->has_forks) {
1012 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
1013 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
1014 # Run pseudo GC on that repository so that objects don't get lost within forks
1015 my $basedir = $Girocco::Config::basedir;
1016 my $projdir = $project->{path};
1017 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
1018 my $nogcrunning = sub {
1019 die "Error: GC appears to be currently running on $projname\n"
1020 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
1023 $removenogc = ! -e "$projdir/.nogc";
1024 recreate_file("$projdir/.nogc") if $removenogc;
1025 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
1026 delete $ENV{show_progress};
1027 $ENV{'show_progress
'} = 1 unless $quiet;
1030 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
1031 or die "Running pseudo GC on project $projname failed\n";
1035 if (!$project->{mirror} && !$isempty && !$reallydel) {
1036 $archived = $project->archive_and_delete;
1037 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1041 warn "Project '$projname' removed from $Girocco::Config::name" .
1042 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1043 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1049 @ARGV == 1 or die_usage;
1050 my $project = get_clean_project($ARGV[0]);
1051 my %info = %$project;
1052 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1053 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1054 print $d->Dump([\%info], ['*'.$project->{name}]);
1059 @ARGV == 1 or die_usage;
1060 my $project = get_project($ARGV[0]);
1061 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1062 my $cur = $project->{HEAD};
1063 defined($cur) or $cur = '';
1065 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1066 defined($headhash) or $headhash = '';
1068 $headhash or $curmark = '!';
1070 my $mark = $_ eq $cur ? $curmark : ' ';
1078 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1079 @ARGV == 1 or die_usage;
1080 my $project = get_project($ARGV[0]);
1082 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1084 print map("$_\n", $project->get_ctag_names);
1091 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1092 @ARGV >= 2 or die_usage;
1093 my $project = get_project(shift @ARGV);
1096 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1098 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1102 my $ctags = join(" ", @ARGV);
1103 $ctags = lc($ctags) if $ic;
1104 foreach (split(/[\s,]+/, $ctags)) {
1105 next unless exists($curtags{$_});
1106 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1109 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1111 # Avoid touching anything other than the ctags
1112 foreach my $tg (@deltags) {
1113 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1115 $project->_set_changed;
1116 $project->_set_forkchange;
1117 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1123 @ARGV >= 2 or die_usage;
1124 my $project = get_project(shift @ARGV);
1125 my $ctags = join(" ", @ARGV);
1126 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1127 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1128 my $oldmask = umask();
1129 umask($oldmask & ~0060);
1131 foreach (split(/[\s,]+/, $ctags)) {
1132 ++$changed if $project->add_ctag($_, 1);
1135 $project->_set_changed;
1136 $project->_set_forkchange;
1139 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1140 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1144 sub _get_random_val {
1149 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1156 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1158 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1159 @ARGV == 1 or die_usage;
1160 my $project = get_project($ARGV[0]);
1161 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1162 if $project->is_password_locked;
1165 if ($random eq "random") {
1166 die "refusing to set random password without --force\n" unless $force;
1167 $rmsg = "set to random value";
1168 $newpw = _get_random_val($project);
1170 die "refusing to set password hash to '$random' without --force\n" unless $force;
1171 $rmsg = "hash set to '$random'";
1177 print "Changing admin password for project $ARGV[0]\n";
1178 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1179 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1180 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1181 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1182 "the admin passwords you have entered do not match each other.\n";
1186 defined($newpw) or die "missing new password on STDIN\n";
1190 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1191 my $old = $project->{crypt};
1192 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1193 if (defined($old) && $old eq $project->{crypt}) {
1194 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1196 # Avoid touching anything other than the password hash
1197 $project->_group_update;
1198 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1204 @ARGV == 1 or die_usage;
1205 my $project = get_project($ARGV[0]);
1206 my $pwhash = $project->{crypt};
1207 defined($pwhash) or $pwhash = "";
1208 if ($pwhash eq "") {
1209 warn $project->{name}, ": no password required\n" unless $quiet;
1212 if ($project->is_password_locked) {
1213 warn $project->{name}, ": password is locked\n" unless $quiet;
1218 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1219 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1222 defined($checkpw) or die "missing admin password on STDIN\n";
1225 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1226 warn "password check failure\n" unless $quiet;
1229 warn "admin password match\n" unless $quiet;
1234 my ($force, $auto, $redelta, $recompress);
1235 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1236 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force,
1237 recompress => \$recompress, "no-reuse-object" => $recompress);
1238 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1239 @ARGV or die "Please give project name on command line.\n";
1240 @ARGV == 1 or die_usage;
1241 my $project = get_project($ARGV[0]);
1242 delete $ENV{show_progress};
1243 delete $ENV{force_gc};
1244 $quiet or $ENV{"show_progress"} = 1;
1245 $force and $ENV{"force_gc"} = 1;
1246 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1247 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1249 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1250 $redelta && !$recompress and push(@args, "-f");
1251 $recompress and push(@args, "-F");
1252 my $lastgc = $project->{lastgc};
1253 system({$args[0]} @args) != 0 and return 1;
1254 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1256 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1258 system({$args[0]} @args) != 0 and return 1;
1265 my ($force, $summary);
1266 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1267 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1268 @ARGV or die "Please give project name on command line.\n";
1269 @ARGV == 1 or die_usage
;
1270 my $project = get_project
($ARGV[0]);
1271 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1272 delete $ENV{show_progress
};
1273 delete $ENV{force_update
};
1275 $ENV{"show_progress"} = 0;
1277 $ENV{"show_progress"} = ($summary ?
1 : 2);
1279 $force and $ENV{"force_update"} = 1;
1280 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1286 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1287 @ARGV or die "Please give project name on command line.\n";
1288 @ARGV == 1 or die_usage
;
1289 my $project = get_project
($ARGV[0]);
1290 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1291 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1292 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1293 exit(255) unless $force;
1294 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1296 unlink($project->_clonefail_path);
1297 unlink($project->_clonelog_path);
1298 recreate_file
($project->_clonep_path);
1299 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1300 die "cannot connect to taskd.socket: $!\n";
1301 select((select($sock),$|=1)[0]);
1302 $sock->print("clone ".$project->{name
}."\n");
1303 # Just ignore reply, we are going to succeed anyway and the I/O
1304 # would apparently get quite hairy.
1308 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1314 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1315 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1316 my $project = get_project
($ARGV[0]);
1317 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1318 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1320 warn "using invalid owner/email with --force\n" unless $quiet;
1322 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1323 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1325 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1327 my $old = $project->{email
};
1329 print "$old\n" if defined($old);
1332 if (defined($old) && $old eq $ARGV[1]) {
1333 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1335 # Avoid touching anything other than "gitweb.owner"
1336 $project->_property_fput("email", $ARGV[1]);
1337 $project->_update_index;
1338 $project->_set_changed;
1339 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1346 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1347 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1348 my $project = get_project
(shift @ARGV);
1349 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1350 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1352 warn "using invalid description with --force\n" unless $quiet;
1354 my $desc = clean_desc
(join(" ", @ARGV));
1355 if (@ARGV && length($desc) > 1024) {
1356 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1358 warn "using longer than 1024 char description with --force\n" unless $quiet;
1360 my $old = $project->{desc
};
1362 print "$old\n" if defined($old);
1365 if (defined($old) && $old eq $desc) {
1366 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1368 # Avoid touching anything other than description file
1369 $project->_property_fput("desc", $desc);
1370 $project->_set_changed;
1371 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1378 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1379 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1380 my $project = get_project
($ARGV[0]);
1381 my $old = $project->{README
};
1383 chomp $old if defined($old);
1384 print "$old\n" if defined($old) && $old ne "";
1387 my ($new, $raw, $newname);
1389 if ($ARGV[1] eq "-") {
1393 $newname = "contents of <STDIN>";
1394 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1396 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1397 $new = "<!-- suppress -->";
1401 die "missing filename for README\n" unless $fn ne "";
1402 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1403 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1408 $newname = "contents of \"$fn\"";
1410 defined($new) or $new = '';
1411 $project->{README
} = to_utf8
($new, 1);
1412 $project->_cleanup_readme;
1413 if (length($project->{README
}) > 8192) {
1414 die "readme greater than 8192 chars is too long (use --force to override)\n"
1416 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1419 my $rd = get_readme_desc
($project->{README
});
1420 if ($rd ne "automatic" && $rd ne "suppressed") {
1421 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
1422 if (-f
$xmllint && -x
$xmllint) {
1423 my ($cnt, $err) = $project->_lint_readme(0);
1425 my $msg = "xmllint: $cnt error";
1426 $msg .= "s" unless $cnt == 1;
1427 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1428 unless $force && $quiet;
1429 exit(255) unless $force;
1430 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1433 die "xmllint not available, refusing to use raw HTML without --force\n"
1435 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1439 if (defined($old) && $old eq $project->{README
}) {
1440 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1442 # Avoid touching anything other than README.html file
1443 $project->_property_fput("README", $project->{README
});
1444 $project->_set_changed;
1445 my $desc = get_readme_desc
($project->{README
});
1447 $newname .= " ($desc)";
1451 warn $project->{name
}, ": README updated to $newname\n" unless $quiet;
1457 my ($proj, $newhead) = @_;
1458 my %okheads = map({($_ => 1)} $proj->get_heads);
1459 exists($okheads{$newhead});
1463 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1464 my $project = get_project
($ARGV[0]);
1465 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1466 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1468 my $old = $project->{HEAD
};
1470 print "$old\n" if defined($old);
1473 if (defined($old) && $old eq $ARGV[1]) {
1474 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1476 # Avoid touching anything other than the HEAD symref
1477 $project->set_HEAD($ARGV[1]);
1478 $project->_set_changed;
1479 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1486 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1487 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1488 my $project = get_project
($ARGV[0]);
1489 my $projconfig = read_config_file_hash
($project->{path
}."/config");
1490 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
1491 my $rghp = realpath
($ghp);
1492 my $lhp = $project->{path
}."/hooks";
1493 my $rlhp = realpath
($lhp);
1496 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
1497 $ahp = $projconfig->{"core.hookspath"};
1498 $rahp = realpath
($ahp);
1501 if (defined($rahp) && $rahp ne "") {
1502 if ($rahp eq $rghp) {
1503 my $nc = ($ahp eq $ghp ?
"" : " non-canonical");
1504 printf "%s \t(global%s)\n", $ahp, $nc;
1505 } elsif ($rahp eq $rlhp) {
1506 my $nc = ($ahp eq $lhp ?
"" : " non-canonical");
1507 printf "%s \t(local%s)\n", $ahp, $nc;
1508 } elsif ($rahp ne $ahp) {
1509 print "$ahp \t($rahp)\n";
1513 } elsif ($ahp ne "") {
1514 print "$ahp \t(non-existent)\n";
1519 if (lc($shp) eq "global") {
1521 } elsif (lc($shp) eq "local") {
1523 } elsif (substr($shp, 0, 2) eq "~/") {
1524 $shp = $ENV{"HOME"}.substr($shp,1);
1525 } elsif ($shp =~ m
,^~([a
-zA
-Z_
][a
-zA
-Z_0
-9]*)((?
:/.*)?
)$,) {
1527 my $hd = (getpwnam($1))[7];
1528 $shp = $hd . $sfx if defined($hd) && $hd ne "" && $hd ne "/" && -d
$hd;
1530 $shp ne "" && -d
$shp or die "no such directory: $ARGV[1]\n";
1531 my $rshp = realpath
($shp);
1532 defined($rshp) && $rshp ne "" or die "could not realpath: $ARGV[1]\n";
1533 $rshp =~ m
,^/[^/], or die "invalid hookspath: $rshp\n";
1534 die "refusing to switch from current non-global hookspath without --force\n"
1535 if !$force && defined($rahp) && $rahp ne "" && $rahp ne $rghp && $rshp ne $rahp;
1536 if (!$force && defined($rahp) && $rahp ne "") {
1537 if ($rshp eq $rahp && ($ahp eq $ghp || $ahp eq $lhp)) {
1538 warn $project->{name
}, ": skipping update of hookspath to same effective value\n" unless $quiet;
1542 $rshp = $ghp if $rshp eq $rghp;
1543 $rshp = $lhp if $rshp eq $rlhp;
1544 if ($rshp eq $ahp) {
1545 warn $project->{name
}, ": skipping update of hookspath to same value\n" unless $quiet;
1548 die "refusing to set neither local nor global hookspath without --force\n"
1549 if !$force && $rshp ne $ghp && $rshp ne $lhp;
1550 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1551 'config', "core.hookspath", $rshp);
1552 my $newval = '"'.$rshp.'"';
1553 $newval = "global" if $rshp eq $ghp;
1554 $newval = "local" if $rshp eq $lhp;
1555 warn $project->{name
}, ": hookspath set to $newval\n" unless $quiet;
1571 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1572 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1573 my $project = get_project
($ARGV[0]);
1574 if (!exists($boolfields{$ARGV[1]})) {
1575 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1577 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1578 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1580 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1582 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1583 die "invalid boolean value: \"$ARGV[2]\"\n";
1585 my $bool = clean_bool
($ARGV[2]);
1586 my $old = $project->{$ARGV[1]};
1588 print "$old\n" if defined($old);
1591 if (defined($old) && $old eq $bool) {
1592 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1594 # Avoid touching anything other than $ARGV[1] field
1595 $project->_property_fput($ARGV[1], $bool);
1596 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1601 sub cmd_setautogchack
{
1602 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1603 my $project = get_project
($ARGV[0]);
1604 my $aghok = $Girocco::Config
::autogchack
&&
1605 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1606 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1608 print "$old\n" if $aghok;
1612 if (lc($ARGV[1]) eq "unset") {
1615 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1616 $bool = clean_bool
($ARGV[1]);
1619 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1620 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1622 if ($old eq $bool) {
1623 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1625 if ($bool eq "unset") {
1626 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1627 'config', '--unset', "girocco.autogchack");
1629 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1630 'config', '--bool', "girocco.autogchack", $bool);
1633 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1638 my ($url, $type) = @_;
1639 $type ne 'baseurl' and return valid_web_url
($url);
1640 valid_repo_url
($url) or return 0;
1641 if ($Girocco::Config
::restrict_mirror_hosts
) {
1642 my $mh = extract_url_hostname
($url);
1643 is_dns_hostname
($mh) or return 0;
1644 !is_our_hostname
($mh) or return 0;
1652 baseurl
=> ["url" , 1],
1653 homepage
=> ["hp" , 0],
1654 notifyjson
=> ["notifyjson", 0],
1660 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1661 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1662 my $project = get_project
($ARGV[0]);
1663 if (!exists($urlfields{$ARGV[1]})) {
1664 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1666 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1667 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1669 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1671 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1672 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1674 warn "using invalid URL with --force\n" unless $quiet;
1676 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1678 print "$old\n" if defined($old);
1681 if (defined($old) && $old eq $ARGV[2]) {
1682 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1684 # Avoid touching anything other than $ARGV[1]'s field
1685 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1686 if ($ARGV[1] eq "baseurl") {
1687 $project->{url
} = $ARGV[2];
1688 $project->_set_bangagain;
1690 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1691 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1706 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1707 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1708 my $project = get_project
(shift @ARGV);
1709 my $field = shift @ARGV;
1710 if (!exists($msgsfields{$field})) {
1711 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1713 if (@ARGV && !valid_addrlist
(@ARGV)) {
1714 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1716 warn "using invalid email address list with --force\n" unless $quiet;
1718 my $old = $project->{$field};
1720 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1723 my $newlist = clean_addrlist
(join(" ",@ARGV));
1724 if (defined($old) && $old eq $newlist) {
1725 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1727 # Avoid touching anything other than $field's field
1728 $project->_property_fput($field, $newlist);
1729 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1736 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1737 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1738 my $project = get_project
(shift @ARGV);
1739 my $projname = $project->{name
};
1740 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
1743 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
1744 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1746 return 0 if !@ARGV && $project->{mirror
};
1747 my $oldusers = $project->{users
};
1748 if ($oldusers && ref($oldusers) eq "ARRAY") {
1749 $oldusers = join("\n", @
$oldusers);
1754 print "$oldusers\n" if $oldusers ne "";
1757 if ($oldusers eq join("\n", @newusers)) {
1758 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1760 # Avoid touching anything other than the users list
1761 $project->{users
} = \
@newusers;
1762 $project->_update_users;
1763 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1771 owner
=> [\
&cmd_setowner
, 0],
1772 desc
=> [\
&cmd_setdesc
, 0],
1773 description
=> [\
&cmd_setdesc
, 0],
1774 readme
=> [\
&cmd_setreadme
, 0],
1775 head
=> [\
&cmd_sethead
, 0],
1776 HEAD
=> [\
&cmd_sethead
, 0],
1777 hooks
=> [\
&cmd_sethooks
, 0],
1778 hookspath
=> [\
&cmd_sethooks
, 0],
1779 cleanmirror
=> [\
&cmd_setbool
, 1],
1780 reverseorder
=> [\
&cmd_setbool
, 1],
1781 summaryonly
=> [\
&cmd_setbool
, 1],
1782 statusupdates
=> [\
&cmd_setbool
, 1],
1783 autogchack
=> [\
&cmd_setautogchack
, 0],
1784 baseurl
=> [\
&cmd_seturl
, 1],
1785 homepage
=> [\
&cmd_seturl
, 1],
1786 notifyjson
=> [\
&cmd_seturl
, 1],
1787 notifymail
=> [\
&cmd_setmsgs
, 1],
1788 notifytag
=> [\
&cmd_setmsgs
, 1],
1789 users
=> [\
&cmd_setusers
, 0],
1796 push(@newargs, shift) if @_ && $_[0] eq '--force';
1798 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
1799 push(@newargs, shift);
1800 shift unless ${$fieldnames{$field}}[1];
1802 diename
(($setopt ?
"set " : "get ") . $field);
1804 &{${$fieldnames{$field}}[0]}(@ARGV);
1819 create
=> \
&cmd_create
,
1820 adopt
=> \
&cmd_adopt
,
1821 remove
=> \
&cmd_remove
,
1822 trash
=> \
&cmd_remove
,
1823 delete => \
&cmd_remove
,
1825 listheads
=> \
&cmd_listheads
,
1826 listtags
=> \
&cmd_listtags
,
1827 listctags
=> \
&cmd_listtags
,
1828 deltags
=> \
&cmd_deltags
,
1829 delctags
=> \
&cmd_deltags
,
1830 addtags
=> \
&cmd_addtags
,
1831 addctags
=> \
&cmd_addtags
,
1832 chpass
=> \
&cmd_chpass
,
1833 checkpw
=> \
&cmd_checkpw
,
1835 update
=> \
&cmd_update
,
1836 remirror
=> \
&cmd_remirror
,
1837 setowner
=> \
&cmd_setowner
,
1838 setdesc
=> \
&cmd_setdesc
,
1839 setdescription
=> \
&cmd_setdesc
,
1840 setreadme
=> \
&cmd_setreadme
,
1841 sethead
=> \
&cmd_sethead
,
1842 sethooks
=> \
&cmd_sethooks
,
1843 sethookspath
=> \
&cmd_sethooks
,
1844 setbool
=> \
&cmd_setbool
,
1845 setboolean
=> \
&cmd_setbool
,
1846 setflag
=> \
&cmd_setbool
,
1847 setautogchack
=> \
&cmd_setautogchack
,
1848 seturl
=> \
&cmd_seturl
,
1849 setmsgs
=> \
&cmd_setmsgs
,
1850 setusers
=> \
&cmd_setusers
,
1858 my $bn = basename
($0);
1859 printf "%s version %s\n\n", $bn, $VERSION;
1860 if (defined($cmd) && $cmd ne '') {
1861 $cmd =~ s/^set(?=[a-zA-Z])//i;
1863 my ($lastmt, $incmd);
1864 foreach (split('\n', sprintf($help, $bn))) {
1865 $lastmt || $incmd or $lastmt = /^\s*$/, next;
1866 $incmd = 1 if $lastmt && /^\s*(?:\[?set\]?)?$cmd\s/;
1867 last if $incmd && /^\s*$/;
1868 $incmd and $cmdhelp .= $_ . "\n";
1871 print $cmdhelp and exit 0 if $cmdhelp;
1879 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1880 dohelp
($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1881 my $command = shift;
1884 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1886 $command = "set" . $command;
1888 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1889 dohelp
($command) if @ARGV && $ARGV[0] =~ /^(?:-h|-?-help)$/i ||
1890 $ARGV[0] =~ /^help$/i && !Girocco
::Project
::does_exist
("help",1);
1891 &{$commands{$command}}(@ARGV);