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.3'}
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 {my @a; /^(.*)$/s && push(@a, $1) foreach @ARGV; @ARGV=@a;}
31 BEGIN {$help = <<'HELP'}
32 Usage: %s [--quiet] <command> <options>
35 show full help or just for <command> if given
37 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
38 list all projects (default is --sort=lcname)
39 limit to project names matching <regex> if given
40 match <regex> against owner instead of project name with --owner
42 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
43 create new project <project> (prompted)
45 --no-alternates skip setup of objects/info/alternates
46 --orphan allow creation of subproject w/o a parent
47 -p use mkdir -p during --orphan creation
48 --no-password set password crypt to invalid value "unknown"
49 --no-owner leave the gitweb.owner config unset
50 --mirror=<url> create a mirror from <url>
51 --full-mirror mirror all refs
52 --push[=<list>] create a push project
53 --desc=<string> specify project description w/o prompt
54 --homepage=<url> specify project homepage URL w/o prompt
55 --defaults do no interactive prompting at all
56 Using --no-password skips the prompts for password, using
57 --no-owner skips the prompt for owner and using --mirror=<url>
58 or --push[=<list>] skips the prompts for mirror URL and
59 heads-only and push users. With --defaults if neither
60 --mirror=<url> nor --push[=<list>] is given then --push will
61 be implied. Using --desc=<string> will force a specific
62 description (including an empty string) and skip the prompt for
63 it. Otherwise a non-empty default description will always be
64 supplied in lieu of an empty or omitted description.
66 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
67 adopt project <project>
68 type of project is guessed if --type=<type> omitted
69 <users> is same as <newuserslist> for setusers command
71 --dry-run do all the checks but don't perform adoption
72 --verbose show project info dump (useful with --dry-run)
73 --no-users no push users at all (<users> must be omitted)
74 --no-owner leave the gitweb.owner config totally unchanged
75 --owner=<val> set the gitweb.owner config to <val>
76 Both --no-owner and --owner=<val> may NOT be given, with neither
77 take owner from preexisting gitweb.owner else use admin setting.
78 For mirrors <users> is ignored otherwise if no <users> and no
79 --no-users option the push users list will consist of the single
80 user name matching the owner or empty if none or more than one.
81 With --dry-run <project> can be an absolute path to a git dir.
83 remove [--force] [--really-delete] [--keep-forks] <project>
84 remove project <project>
85 do not move to _recyclebin with --really-delete (just rm -rf)
86 remove projects with forks (by keeping forks) using --keep-forks
89 show project <project>
92 list all available heads for <project> and indicate current head
94 listtags [--verbose] <project>
95 list all ctags on project <project>
97 deltags <project> [-i] <tagstodel>
98 remove any ctags on project <project> present in <tagstodel>
99 <tagstodel> is space or comma separated list of tags to remove
100 with -i match against <tagstodel> without regard to letter case
102 addtags <project> <tagstoadd>
103 add ctags to project <project>
104 <tagstoadd> is space or comma separated list of tags to add
106 chpass [--force] <project> [random | unknown]
107 change project <project> password (prompted)
108 with "random" set to random password
109 with "unknown" set password hash to invalid value "unknown"
112 check project <project> password for a match (prompted)
114 gc [--force | --auto] [--redelta | --recompress] <project>
115 run the gc.sh script on project <project>
116 with --auto let the gc.sh script decide what to do
117 with --force cause a full gc to take place (force_gc=1)
118 with neither --auto nor --force do a mini or if needed a full gc
119 (in other words just touch .needsgc and run gc.sh)
120 with --redelta a full gc will use pack-objects --no-reuse-delta
121 with --recompress a full gc uses pack-objects --no-reuse-object
122 (--no-reuse-delta and --no-reuse-object are accepted as aliases)
123 unless the global --quiet option is given show_progress=1 is used
125 update [--force] [--quiet | --summary] <project>
126 run the update.sh script on project <project>
127 with --force cause a fetch to always take place (force_update=1)
128 with --quiet only show errors (show_progress is left unset)
129 with --summary show progress and ref summary (show_progress=1)
130 with neither --quiet nor --summary show it all (show_progress=2)
132 remirror [--force] <project>
133 initiate a remirror of project <project>
135 [set]owner [--force] <project> <newowner>
136 set project <project> owner to <newowner>
137 without "set" and only 1 arg, just show current project owner
139 [set]desc [--force] <project> <newdesc>
140 set project <project> description to <newdesc>
141 without "set" and only 1 arg, just show current project desc
143 [set]readme [--force] <project> <newsetting>
144 set project <project> readme to <newsetting>
145 <newsetting> is automatic|suppressed|-|[@]filename
146 without "set" and only 2 args, just show current readme setting
148 [set]head <project> <newhead>
149 set project <project> HEAD symbolic ref to <newhead>
150 without "set" and only 1 arg, just show current project HEAD
152 [set]bool [--force] <project> <flagname> <boolvalue>
153 set project <project> boolean <flagname> to <boolvalue>
154 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
155 without "set" and only 2 args, just show current flag value
157 [set]hooks [--force] <project> local | global | <path>
158 set project <project> hookspath to local, global or <path>
159 without "set" and only 1 arg, just show current hookspath
161 [set]autogchack <project> <boolvalue> | unset
162 set project <project> autogchack to <boolvalue> or "unset" it
163 without "set" just show current autogchack setting if enabled
164 with "set" autogchack must be enabled in Config.pm for the
165 type of project and maintain-auto-gc-hack.sh is always run
167 [set]url [--force] <project> <urlname> <newurlvalue>
168 set project <project> url <urlname> to <newurlvalue>
169 <urlname> is baseurl|homepage|notifyjson
170 without "set" and only 2 args, just show current url value
172 [set]msgs [--force] <project> <msgsname> <eaddrlist>
173 set project <project> msgs <msgsname> to <addrlist>
174 <msgsname> is notifymail|notifytag
175 <eaddrlist> is space or comma separated list of email addresses
176 without "set" and only 2 args, just show current msgs value
178 [set]users [--force] <project> <newuserslist>
179 set push project <project> users list to <newuserslist>
180 <newuserslist> is space or comma separated list of user names
181 without "set" and only 1 arg, just show current users list
183 [set]jsontype <project> <newjsontype>
184 set project <project> JSON Content-Type to <newjsontype>
185 <newjsontype> is x-www-form-urlencoded or json
186 without "set" and only 1 arg, just show current jsontype
188 [set]jsonsecret <project> <newjsonsecret>
189 set project <project> JSON secret to <newjsonsecret>
190 <newjsonsecret> is a string (empty string disables signatures)
191 without "set" and only 1 arg, just show current jsonsecret
193 get <project> <fieldname>
194 show project <project> field <fieldname>
195 <fieldname> is owner|desc|readme|head|hooks|users|jsontype
196 or jsonsecret|<flagname>|autogchack|<urlname>|<msgsname>
198 set [--force] <project> <fieldname> <newfieldvalue>
199 set project <project> field <fieldname> to <newfieldvalue>
200 <fieldname> same as for get
201 <newfieldvalue> same as for corresponding set... command
207 my $sub = shift || diename
;
209 die "Invalid arguments to $sub command -- try \"help\"\n";
211 die "Invalid arguments -- try \"help\"\n";
215 sub get_readme_desc
{
217 defined($rm) or $rm = '';
220 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
222 return $test eq '' ?
"suppressed" : "length " . length($rm);
228 sub get_ctag_counts
{
232 foreach ($project->get_ctag_names) {
235 if (open $ct, '<', $project->{path
}."/ctags/$_") {
238 defined $count or $count = '';
240 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
246 push(@ctags, $_."(".$val.")");
249 push(@ctags, [$_, $val]) if $val;
255 sub get_clean_project
{
256 my $project = get_project
(@_);
257 delete $project->{loaded
};
258 delete $project->{base_path
};
259 delete $project->{ccrypt
};
260 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
261 $project->{owner
} = $project->{email
}; delete $project->{email
};
262 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
263 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
264 if (defined($project->{path
}) && $project->{path
} ne "") {
265 my $rp = realpath
($project->{path
});
266 defined($rp) && $rp ne "" and $project->{realpath
} = $rp;
267 if (-f
"$rp/objects/info/packs") {
268 my $ipt = (stat _
)[9];
269 defined($ipt) and $project->{infopackstime
} =
270 strftime
("%Y-%m-%d %H:%M:%S %z", localtime($ipt));
273 my $owner = $project->{owner
};
276 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
277 $project->{owner_users
} = \
@owner_users if @owner_users;
279 my $projname = $project->{name
};
280 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
281 $project->{has_forks
} = 1 if @forks;
282 $project->{has_alternates
} = 1 if $project->has_alternates;
283 my @bundles = $project->bundles;
284 for (my $i = 0; $i < @bundles; ++$i) {
285 my $secs = $bundles[$i]->[0];
286 $bundles[$i]->[0] = strftime
("%Y-%m-%d %H:%M:%S %z", localtime($secs));
287 my $sz = $bundles[$i]->[2];
288 1 while $sz =~ s/(?<=\d)(\d{3})(?:,|$)/,$1/g;
289 $bundles[$i]->[2] = $sz;
291 delete $project->{bundles
};
292 $project->{bundles
} = \
@bundles if @bundles;
293 $project->{mirror
} = 0 unless $project->{mirror
};
294 $project->{is_empty
} = 1 if $project->is_empty;
295 delete $project->{showpush
} unless $project->{showpush
};
296 delete $project->{users
} if $project->{mirror
};
297 delete $project->{baseurl
} unless $project->{mirror
};
298 delete $project->{banged
} unless $project->{mirror
};
299 delete $project->{lastrefresh
} unless $project->{mirror
};
300 delete $project->{cleanmirror
} unless $project->{mirror
};
301 delete $project->{statusupdates
} unless $project->{mirror
};
302 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
303 unless ($project->{banged
}) {
304 delete $project->{bangcount
};
305 delete $project->{bangfirstfail
};
306 delete $project->{bangmessagesent
};
308 my $projhook = $project->_has_notifyhook;
309 if (defined($projhook) && $projhook ne "") {
310 $project->{notifyhook
} = $projhook;
312 delete $project->{notifyhook
};
314 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
315 my @tags = get_ctag_counts
($project, 1);
316 $project->{tags
} = \
@tags if @tags;
317 my $projconfig = read_config_file_hash
($project->{path
}."/config");
318 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
319 my $ahp = $projconfig->{"core.hookspath"};
320 my $rahp = realpath
($ahp);
321 my $lhp = $project->{path
}."/hooks";
322 my $rlhp = realpath
($lhp);
323 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
324 my $rghp = realpath
($ghp);
325 $project->{has_local_hooks
} = 1 if
326 defined($rahp) && defined($rlhp) && $rahp eq $rlhp;
327 $project->{has_global_hooks
} = 1 if
328 defined($rahp) && defined($rghp) && $rahp eq $rghp;
329 $project->{hookspath
} = $ahp unless $ahp eq $lhp || $ahp eq $ghp;
337 foreach (split(/[,\s]+/, $_[0])) {
339 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
341 return join(($_[1]||","), @newlist);
345 my $cleaned = clean_addrlist
(join(" ", @_));
346 return 1 if $cleaned eq "";
347 valid_email_multi
($cleaned) && length($cleaned) <= 512;
351 my ($userlist, $force, $nodie, $quiet) = @_;
355 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
356 my %users = map({($$_[1] => $_)} get_all_users
);
357 foreach (split(/[\s,]+/, $userlist)) {
358 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
359 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
362 if (Girocco
::User
::does_exist
($_, 1)) {
364 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
367 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
372 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
374 die if $badlist && !$nodie;
378 sub is_default_desc
{
379 # "Unnamed repository; edit this file 'description' to name the repository."
380 # "Unnamed repository; edit this file to name it for gitweb."
382 return 0 unless defined($_);
383 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
389 return 0 if $test =~ /[\r\n]/;
390 $test =~ s/\s\s+/ /g;
398 defined($desc) or $desc = '';
400 $desc = to_utf8
($desc, 1);
401 $desc =~ s/\s\s+/ /g;
408 Girocco
::CLIUtil
::_parse_options
(
410 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
418 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
419 name
=> sub {$$a[1] cmp $$b[1]},
420 gid
=> sub {$$a[3] <=> $$b[3]},
421 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
422 no => sub {$$a[0] <=> $$b[0]},
424 my $sortopt = 'lcname';
425 my ($verbose, $owner);
426 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
429 my $val = shift @ARGV;
430 $regex = qr
($val) or die "bad regex \"$val\"\n";
432 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
433 my $sortsub = $sortsub{$sortopt};
434 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
435 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
437 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
439 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
445 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
446 $ismirror, $desc, $fullmirror, $homepage);
448 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
449 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
450 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
451 ":description" => \
$desc, "full-mirror" => \
$fullmirror, ":homepage" => \
$homepage);
452 @ARGV == 1 or die_usage
;
453 !defined($pushusers) || defined($ispush) or $ispush = 1;
454 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
455 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
456 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
457 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
458 !$defaults || defined($nopasswd) or $nopasswd = 1;
459 !$defaults || defined($noowner) or $noowner = 1;
460 !defined($ispush) || defined($pushusers) or $pushusers = "";
461 my $projname = $ARGV[0];
462 $projname =~ s/\.git$//i;
463 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
464 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
465 warn "Refusing to create orphan project without --orphan\n"
466 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
467 warn "Required orphan parent directory does not exist (use -p): ",
468 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
469 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
470 die "Invalid project name: \"$projname\"\n";
472 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
473 my $newtype = $forkee ?
'fork' : 'project';
474 if (length($project) > 64) {
475 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
477 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
479 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
480 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
481 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
483 print "Enter settings for new project \"$projname\"\n" unless $defaults;
485 $settings{noalternates
} = $noalternates;
487 $settings{crypt} = "unknown";
489 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
490 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
491 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
492 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
493 "the admin passwords you have entered do not match each other.\n";
494 $settings{crypt} = scrypt_sha1
($np1);
498 $owner = prompt_or_die
("Owner/email name for project $projname");
499 unless (valid_email
($owner)) {
501 warn "Your email sure looks weird...?\n";
504 warn "Allowing invalid email with --force\n" unless $quiet;
506 if (length($owner) > 96) {
508 warn "Your email is longer than 96 characters. Do you really need that much?\n";
511 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
514 $settings{email
} = $owner;
516 my $checkmirror = sub {
517 my $checkurl = shift;
518 unless (valid_repo_url
($checkurl)) {
520 warn "Invalid mirror URL: \"$checkurl\"\n";
523 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
525 if ($Girocco::Config
::restrict_mirror_hosts
) {
526 my $mh = extract_url_hostname
($checkurl);
527 unless (is_dns_hostname
($mh)) {
529 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
532 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
534 if (is_our_hostname
($mh)) {
536 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
539 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
544 if ($ispush || $ismirror) {
545 !$ispush || $force || $Girocco::Config
::push or
546 die "Push projects are disabled, create a mirror (or use --force)\n";
547 !$ismirror || $force || $Girocco::Config
::mirror
or
548 die "Mirror projects are disabled, create a push project (or use --force)\n";
550 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
551 $baseurl = $ismirror;
552 $settings{url
} = $baseurl;
553 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
556 if ($pushusers !~ /^[\s,]*$/) {
557 eval {@newusers = validate_users
($pushusers, $force); 1;} or
558 die "Invalid --push user list\n";
560 $settings{users
} = \
@newusers;
562 } elsif ($force || $Girocco::Config
::mirror
) {{
563 if ($force || $Girocco::Config
::push) {
564 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
566 $baseurl = prompt_or_die
("URL to mirror from");
567 unless ($baseurl ne "") {
568 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
572 if ($baseurl ne "") {
573 &$checkmirror($baseurl) or redo;
574 $settings{url
} = $baseurl;
575 $settings{cleanmirror
} =
576 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
579 my $mirror = ($baseurl eq "") ?
0 : 1;
580 my $checkdesc = sub {
582 if (length($d) > 1024) {
584 warn "Short description length greater than 1024 characters!\n";
587 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
591 if (defined($desc)) {
592 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
593 $desc eq "" || &$checkdesc($desc) or
594 die "Invalid --desc description\n";
595 } elsif (!$defaults) {
596 $desc = prompt_or_die
("Short description", "");
597 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
598 $desc eq "" || &$checkdesc($desc) or redo;
599 $desc = undef if $desc eq "";
601 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
602 $settings{desc
} = $desc;
605 unless (valid_web_url
($hpurl)) {
607 warn "Invalid home page URL: \"$hpurl\"\n";
610 warn "Allowing invalid home page URL with --force\n" unless $quiet;
614 if (defined($homepage)) {
615 $homepage =~ s/^\s+//; $homepage =~ s/\s+$//;
616 $homepage eq "" || &$checkhp($homepage) or
617 die "Invalid --homepage URL\n";
618 } elsif (!$defaults) {
619 $homepage = prompt_or_die
("Home page URL", "");
620 $homepage =~ s/^\s+//; $homepage =~ s/\s+$//;
621 $homepage eq "" || &$checkhp($homepage) or redo;
622 $homepage = undef if $homepage eq "";
624 $settings{hp
} = $homepage;
627 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
628 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
630 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
633 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
636 $settings{notifyjson
} = $jsonurl;
637 my $commitaddrs = "";
639 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
640 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
642 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
645 warn "using invalid commit notify email address list with --force\n" unless $quiet;
648 $settings{notifymail
} = $commitaddrs;
649 $settings{reverseorder
} = 1;
650 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
651 if !$defaults && $commitaddrs ne "";
652 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
653 if !$defaults && $commitaddrs ne "";
656 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
657 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
659 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
662 warn "using invalid tag notify email address list with --force\n" unless $quiet;
665 $settings{notifytag
} = $tagaddrs;
666 if (!$mirror && !$ispush) {
669 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
670 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
672 $settings{users
} = \
@newusers;
674 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
675 or die "Girocco::Project->ghost call failed\n";
677 $newproj->{$k} = $v while ($k, $v) = each(%settings);
678 my $killowner = sub {
679 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
680 'config', '--unset', "gitweb.owner");
683 $newproj->premirror or die "Girocco::Project->premirror failed\n";
684 !$noowner or &$killowner;
685 $newproj->clone or die "Girocco::Project->clone failed\n";
686 warn "Project $projname created and cloning successfully initiated.\n"
689 $newproj->conjure or die "Girocco::Project->conjure failed\n";
690 !$noowner or &$killowner;
691 warn "New push project fork is empty due to use of --no-alternates\n"
692 if !$quiet && $projname =~ m
,/, && $noalternates;
693 warn "Project $projname successfully created.\n" unless $quiet;
700 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
701 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
705 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
706 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
707 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
708 @ARGV or die "Please give project name on command line.\n";
709 my $projname = shift @ARGV;
710 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
711 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
712 defined($type) or $type = "";
714 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
715 $projdir = realpath
($projname);
716 $projname = $projdir;
717 $projname =~ s/\.git$//i;
718 $projname =~ s
,/+$,,;
719 $projname =~ s
,^.*/,,;
720 $projname ne "" or $projname = $projdir;
722 $projname =~ s/\.git$//i;
723 $projname ne "" or die "Invalid project name \"\".\n";
724 unless (Girocco
::Project
::does_exist
($projname, 1)) {
725 Girocco
::Project
::valid_name
($projname, 1, 1)
726 or die "Invalid project name \"$projname\".\n";
727 die "No such project to adopt: $projname\n";
729 defined(Girocco
::Project
->load($projname))
730 and die "Project already known (no need to adopt): $projname\n";
731 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
732 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
734 my $config = read_config_file
($projdir . "/config");
736 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
737 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
738 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
739 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1, $quiet)];
741 if (-e
"$projdir/description") {
742 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
748 defined $desc or $desc = "";
750 $desc = to_utf8
($desc, 1);
751 is_default_desc
($desc) and $desc = "";
752 if ($desc ne "" && !valid_desc
($desc)) {
753 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
755 warn "using invalid 'description' file contents with --force\n" unless $quiet;
757 $desc = clean_desc
($desc);
758 if (length($desc) > 1024) {
759 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
761 warn "using longer than 1024 char description with --force\n" unless $quiet;
765 if (-e
"$projdir/README.html") {
766 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
772 defined $readme or $readme = "";
773 $readme = to_utf8
($readme, 1);
774 $readme =~ s/\r\n?/\n/gs;
775 $readme =~ s/^\s+//s;
776 $readme =~ s/\s+$//s;
777 $readme eq "" or $readme .= "\n";
778 if (length($readme) > 8192) {
779 die "readme greater than 8192 chars is too long (use --force to override)\n"
781 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
783 my $rd = get_readme_desc
($readme);
784 if ($rd ne "automatic" && $rd ne "suppressed") {
785 my $xmllint = qx(sh
-c
'command -v xmllint'); chomp $xmllint;
786 if (-f
$xmllint && -x
$xmllint) {
787 my $dummy = {README
=> $readme};
788 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
790 my $msg = "xmllint: $cnt error";
791 $msg .= "s" unless $cnt == 1;
792 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
793 unless $force && $quiet;
794 exit(255) unless $force;
795 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
798 die "xmllint not available, refusing to use raw HTML without --force\n"
800 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
804 # Inspect any remotes now
805 # Yes, Virginia, remote urls can be multi-valued
809 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
810 my ($name, $subkey) = ($1, $2);
811 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
812 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
813 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
814 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
815 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
817 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
818 # the remote names in a group are separated by runs of [ \t\n] characters
819 # remote names "", ".", ".." and any name starting with "/" are invalid
820 # a remote with no url or vcs setting is not considered valid
823 if (exists($config{"remotes
.default"})) {
824 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
825 next unless exists($remotes{$_});
826 my $rmt = $remotes{$_};
827 next if !exists($rmt->{url}) && !$rmt->{vcs};
835 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
836 next if $seenrmt{$1};
838 next unless exists($remotes{$1});
839 my $rmt = $remotes{$1};
840 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
844 my @needskip = (); # remotes that need skipDefaultUpdate set to true
847 my $foundfetchwithmirror = 0;
849 my $rmt = $remotes{$_};
850 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
851 next unless exists($rmt->{fetch});
853 ++$foundfetchwithmirror if $rmt->{mirror};
854 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
856 # if we have $foundvcs then we need to explicitly set fetch.prune to false
857 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
858 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
860 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
861 # if remote "origin
" exists we always pick up its first url or use ""
862 if (exists($remotes{origin})) {
863 my $rmt = $remotes{origin};
864 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
865 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
868 # get the first url of the @check remotes
870 my $rmt = $remotes{$_};
871 next unless exists($rmt->{url});
872 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
873 $baseurl = $rmt->{url}->[0];
877 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
879 # If we have $foundfetch we want to make a mirror but complain if
880 # we $foundfetchwithmirror as well unless we have --type=mirror.
881 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
882 # Warn if we need to set fetch.prune=false when making a mirror
883 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
884 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
885 # Warn if $usingall and any @needskip (and set them) if making a mirror
886 # Warn if making a mirror and $baseurl eq ""
887 # Warn if we have --type=mirror and !$foundfetch
890 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
891 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
892 if ($foundfetchwithmirror) {
893 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
894 "(Use
--type
=mirror to override
)\n"
895 unless $type eq "mirror
";
896 exit(255) unless $type eq "mirror
" || $dryrun;
897 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
898 unless $quiet || $type ne "mirror
";
900 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
901 if !$quiet && $neednoprune;
902 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
903 if !$quiet && $needfakeorigin;
904 if (!$usingall && @needskip) {
905 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
907 exit(255) unless $force || $dryrun;
908 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
909 unless $quiet || !$force;
911 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
912 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
914 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
915 if !$quiet && $foundfetch && !$foundfetchwithmirror;
918 if (!$noowner && !defined($owner)) {
920 $owner = $config{"gitweb
.owner
"};
921 if (!defined($owner) || $owner eq "") {
922 $owner = $Girocco::Config::admin;
923 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
926 if (!$nousers && !$makemirror && !defined($users)) {
927 # select user list for push project
928 my $findowner = $owner;
929 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
930 $findowner = lc($findowner) if defined($findowner);
931 my @owner_users = ();
932 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
933 if defined($findowner) && $findowner ne "";
934 defined($findowner) or $findowner = "";
935 if (@owner_users <= 1) {
936 $users = \@owner_users;
937 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
940 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
941 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
944 defined($users) or $users = [];
946 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
947 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
948 # and warn about preserving the setting)
950 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
951 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
952 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
953 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
954 $config{"receive
.denydeletecurrent
"} ne "warn";
956 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
957 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
958 if ($reflogactive || $reflogfiles) {
959 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
960 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
961 exit(255) unless $force || $dryrun;
962 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
963 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
966 return 0 if $dryrun && !$verbose;
968 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
969 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
970 $newproj->{desc} = $desc;
971 $newproj->{README} = $readme;
972 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
973 $newproj->{email} = $owner if defined($owner);
974 $newproj->{users} = $users;
975 $newproj->{crypt} = "unknown
";
976 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
977 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
978 my $dummy = bless {}, "Girocco
::Project
";
979 $dummy->{path} = "$projdir";
980 $dummy->{configfilehash} = \%config;
981 $dummy->_properties_load;
982 delete $dummy->{origurl};
983 foreach my $k (keys(%$dummy)) {
984 $newproj->{$k} = $dummy->{$k}
985 if exists($dummy->{$k}) && !exists($newproj->{$k});
990 my %info = %$newproj;
991 $info{README} = get_readme_desc($info{README}) if exists($info{README});
992 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
993 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
994 print $d->Dump([\%info], ['*'.$newproj->{name}]);
998 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
1000 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
1001 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
1002 if ($usingall && @needskip) {
1003 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
1007 # Perform the actual adoption
1008 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
1010 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
1011 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
1012 if git_bool($config{"receive
.denynonfastforwards
"});
1013 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
1014 if exists($config{"receive
.denydeletecurrent
"}) &&
1015 $config{"receive
.denydeletecurrent
"} ne "warn";
1016 git_config($projdir, "core
.logAllRefUpdates
", "true
")
1021 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
1023 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
1029 my ($force, $reallydel, $keepforks);
1030 parse_options(force => \$force, "really
-delete" => \$reallydel,
1031 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
1032 @ARGV or die "Please give project name on command line
.\n";
1033 @ARGV == 1 or die_usage;
1034 my $project = get_project($ARGV[0]);
1035 my $projname = $project->{name};
1036 my $isempty = !$project->{mirror} && $project->is_empty;
1037 if (!$project->{mirror} && !$isempty && $reallydel) {
1038 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
1039 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
1043 if ($project->has_forks) {
1044 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
1045 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
1046 # Run pseudo GC on that repository so that objects don't get lost within forks
1047 my $basedir = $Girocco::Config::basedir;
1048 my $projdir = $project->{path};
1049 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
1050 my $nogcrunning = sub {
1051 die "Error: GC appears to be currently running on $projname\n"
1052 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
1055 $removenogc = ! -e "$projdir/.nogc";
1056 recreate_file("$projdir/.nogc") if $removenogc;
1057 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
1058 delete $ENV{show_progress};
1059 $ENV{'show_progress
'} = 1 unless $quiet;
1062 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
1063 or die "Running pseudo GC on project $projname failed\n";
1067 if (!$project->{mirror} && !$isempty && !$reallydel) {
1068 $archived = $project->archive_and_delete;
1069 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1073 warn "Project '$projname' removed from $Girocco::Config::name" .
1074 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1075 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1081 @ARGV == 1 or die_usage;
1082 my $project = get_clean_project($ARGV[0]);
1083 my %info = %$project;
1084 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1085 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1086 print $d->Dump([\%info], ['*'.$project->{name}]);
1091 @ARGV == 1 or die_usage;
1092 my $project = get_project($ARGV[0]);
1093 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1094 my $cur = $project->{HEAD};
1095 defined($cur) or $cur = '';
1097 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1098 defined($headhash) or $headhash = '';
1100 $headhash or $curmark = '!';
1102 my $mark = $_ eq $cur ? $curmark : ' ';
1110 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1111 @ARGV == 1 or die_usage;
1112 my $project = get_project($ARGV[0]);
1114 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1116 print map("$_\n", $project->get_ctag_names);
1123 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1124 @ARGV >= 2 or die_usage;
1125 my $project = get_project(shift @ARGV);
1128 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1130 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1134 my $ctags = join(" ", @ARGV);
1135 $ctags = lc($ctags) if $ic;
1136 foreach (split(/[\s,]+/, $ctags)) {
1137 next unless exists($curtags{$_});
1138 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1141 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1143 # Avoid touching anything other than the ctags
1144 foreach my $tg (@deltags) {
1145 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1147 $project->_set_changed;
1148 $project->_set_forkchange;
1149 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1155 @ARGV >= 2 or die_usage;
1156 my $project = get_project(shift @ARGV);
1157 my $ctags = join(" ", @ARGV);
1158 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1159 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1160 my $oldmask = umask();
1161 umask($oldmask & ~0060);
1163 foreach (split(/[\s,]+/, $ctags)) {
1164 ++$changed if $project->add_ctag($_, 1);
1167 $project->_set_changed;
1168 $project->_set_forkchange;
1171 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1172 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1176 sub _get_random_val {
1181 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1188 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1190 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1191 @ARGV == 1 or die_usage;
1192 my $project = get_project($ARGV[0]);
1193 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1194 if $project->is_password_locked;
1197 if ($random eq "random") {
1198 die "refusing to set random password without --force\n" unless $force;
1199 $rmsg = "set to random value";
1200 $newpw = _get_random_val($project);
1202 die "refusing to set password hash to '$random' without --force\n" unless $force;
1203 $rmsg = "hash set to '$random'";
1209 print "Changing admin password for project $ARGV[0]\n";
1210 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1211 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1212 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1213 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1214 "the admin passwords you have entered do not match each other.\n";
1218 defined($newpw) or die "missing new password on STDIN\n";
1222 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1223 my $old = $project->{crypt};
1224 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1225 if (defined($old) && $old eq $project->{crypt}) {
1226 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1228 # Avoid touching anything other than the password hash
1229 $project->_group_update;
1230 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1236 @ARGV == 1 or die_usage;
1237 my $project = get_project($ARGV[0]);
1238 my $pwhash = $project->{crypt};
1239 defined($pwhash) or $pwhash = "";
1240 if ($pwhash eq "") {
1241 warn $project->{name}, ": no password required\n" unless $quiet;
1244 if ($project->is_password_locked) {
1245 warn $project->{name}, ": password is locked\n" unless $quiet;
1250 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1251 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1254 defined($checkpw) or die "missing admin password on STDIN\n";
1257 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1258 warn "password check failure\n" unless $quiet;
1261 warn "admin password match\n" unless $quiet;
1266 my ($force, $auto, $redelta, $recompress);
1267 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1268 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force,
1269 recompress => \$recompress, "no-reuse-object" => $recompress);
1270 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1271 @ARGV or die "Please give project name on command line.\n";
1272 @ARGV == 1 or die_usage;
1273 my $project = get_project($ARGV[0]);
1274 delete $ENV{show_progress};
1275 delete $ENV{force_gc};
1276 $quiet or $ENV{"show_progress"} = 1;
1277 $force and $ENV{"force_gc"} = 1;
1278 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1279 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1281 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1282 $redelta && !$recompress and push(@args, "-f");
1283 $recompress and push(@args, "-F");
1284 my $lastgc = $project->{lastgc};
1285 system({$args[0]} @args) != 0 and return 1;
1286 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1288 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1290 system({$args[0]} @args) != 0 and return 1;
1297 my ($force, $summary);
1298 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1299 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1300 @ARGV or die "Please give project name on command line.\n";
1301 @ARGV == 1 or die_usage
;
1302 my $project = get_project
($ARGV[0]);
1303 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1304 delete $ENV{show_progress
};
1305 delete $ENV{force_update
};
1307 $ENV{"show_progress"} = 0;
1309 $ENV{"show_progress"} = ($summary ?
1 : 2);
1311 $force and $ENV{"force_update"} = 1;
1312 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1318 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1319 @ARGV or die "Please give project name on command line.\n";
1320 @ARGV == 1 or die_usage
;
1321 my $project = get_project
($ARGV[0]);
1322 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1323 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1324 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1325 exit(255) unless $force;
1326 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1328 unlink($project->_clonefail_path);
1329 unlink($project->_clonelog_path);
1330 recreate_file
($project->_clonep_path);
1331 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1332 die "cannot connect to taskd.socket: $!\n";
1333 select((select($sock),$|=1)[0]);
1334 $sock->print("clone ".$project->{name
}."\n");
1335 # Just ignore reply, we are going to succeed anyway and the I/O
1336 # would apparently get quite hairy.
1340 warn "Project \"$ARGV[0]\" remirror initiated.\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
($ARGV[0]);
1349 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1350 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1352 warn "using invalid owner/email with --force\n" unless $quiet;
1354 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1355 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1357 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1359 my $old = $project->{email
};
1361 print "$old\n" if defined($old);
1364 if (defined($old) && $old eq $ARGV[1]) {
1365 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1367 # Avoid touching anything other than "gitweb.owner"
1368 $project->_property_fput("email", $ARGV[1]);
1369 $project->_update_index;
1370 $project->_set_changed;
1371 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\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
(shift @ARGV);
1381 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1382 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1384 warn "using invalid description with --force\n" unless $quiet;
1386 my $desc = clean_desc
(join(" ", @ARGV));
1387 if (@ARGV && length($desc) > 1024) {
1388 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1390 warn "using longer than 1024 char description with --force\n" unless $quiet;
1392 my $old = $project->{desc
};
1394 print "$old\n" if defined($old);
1397 if (defined($old) && $old eq $desc) {
1398 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1400 # Avoid touching anything other than description file
1401 $project->_property_fput("desc", $desc);
1402 $project->_set_changed;
1403 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1410 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1411 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1412 my $project = get_project
($ARGV[0]);
1413 my $old = $project->{README
};
1415 chomp $old if defined($old);
1416 print "$old\n" if defined($old) && $old ne "";
1419 my ($new, $raw, $newname);
1421 if ($ARGV[1] eq "-") {
1425 $newname = "contents of <STDIN>";
1426 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1428 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1429 $new = "<!-- suppress -->";
1433 die "missing filename for README\n" unless $fn ne "";
1434 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1435 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1440 $newname = "contents of \"$fn\"";
1442 defined($new) or $new = '';
1443 $project->{README
} = to_utf8
($new, 1);
1444 $project->_cleanup_readme;
1445 if (length($project->{README
}) > 8192) {
1446 die "readme greater than 8192 chars is too long (use --force to override)\n"
1448 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1451 my $rd = get_readme_desc
($project->{README
});
1452 if ($rd ne "automatic" && $rd ne "suppressed") {
1453 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
1454 if (-f
$xmllint && -x
$xmllint) {
1455 my ($cnt, $err) = $project->_lint_readme(0);
1457 my $msg = "xmllint: $cnt error";
1458 $msg .= "s" unless $cnt == 1;
1459 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1460 unless $force && $quiet;
1461 exit(255) unless $force;
1462 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1465 die "xmllint not available, refusing to use raw HTML without --force\n"
1467 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1471 if (defined($old) && $old eq $project->{README
}) {
1472 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1474 # Avoid touching anything other than README.html file
1475 $project->_property_fput("README", $project->{README
});
1476 $project->_set_changed;
1477 my $desc = get_readme_desc
($project->{README
});
1479 $newname .= " ($desc)";
1483 warn $project->{name
}, ": README updated to $newname\n" unless $quiet;
1489 my ($proj, $newhead) = @_;
1490 my %okheads = map({($_ => 1)} $proj->get_heads);
1491 exists($okheads{$newhead});
1495 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1496 my $project = get_project
($ARGV[0]);
1497 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1498 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1500 my $old = $project->{HEAD
};
1502 print "$old\n" if defined($old);
1505 if (defined($old) && $old eq $ARGV[1]) {
1506 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1508 # Avoid touching anything other than the HEAD symref
1509 $project->set_HEAD($ARGV[1]);
1510 $project->_set_changed;
1511 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1518 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1519 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1520 my $project = get_project
($ARGV[0]);
1521 my $projconfig = read_config_file_hash
($project->{path
}."/config");
1522 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
1523 my $rghp = realpath
($ghp);
1524 my $lhp = $project->{path
}."/hooks";
1525 my $rlhp = realpath
($lhp);
1528 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
1529 $ahp = $projconfig->{"core.hookspath"};
1530 $rahp = realpath
($ahp);
1533 if (defined($rahp) && $rahp ne "") {
1534 if ($rahp eq $rghp) {
1535 my $nc = ($ahp eq $ghp ?
"" : " non-canonical");
1536 printf "%s \t(global%s)\n", $ahp, $nc;
1537 } elsif ($rahp eq $rlhp) {
1538 my $nc = ($ahp eq $lhp ?
"" : " non-canonical");
1539 printf "%s \t(local%s)\n", $ahp, $nc;
1540 } elsif ($rahp ne $ahp) {
1541 print "$ahp \t($rahp)\n";
1545 } elsif ($ahp ne "") {
1546 print "$ahp \t(non-existent)\n";
1551 if (lc($shp) eq "global") {
1553 } elsif (lc($shp) eq "local") {
1555 } elsif (substr($shp, 0, 2) eq "~/") {
1556 $shp = $ENV{"HOME"}.substr($shp,1);
1557 } elsif ($shp =~ m
,^~([a
-zA
-Z_
][a
-zA
-Z_0
-9]*)((?
:/.*)?
)$,) {
1559 my $hd = (getpwnam($1))[7];
1560 $shp = $hd . $sfx if defined($hd) && $hd ne "" && $hd ne "/" && -d
$hd;
1562 $shp ne "" && -d
$shp or die "no such directory: $ARGV[1]\n";
1563 my $rshp = realpath
($shp);
1564 defined($rshp) && $rshp ne "" or die "could not realpath: $ARGV[1]\n";
1565 $rshp =~ m
,^/[^/], or die "invalid hookspath: $rshp\n";
1566 die "refusing to switch from current non-global hookspath without --force\n"
1567 if !$force && defined($rahp) && $rahp ne "" && $rahp ne $rghp && $rshp ne $rahp;
1568 if (!$force && defined($rahp) && $rahp ne "") {
1569 if ($rshp eq $rahp && ($ahp eq $ghp || $ahp eq $lhp)) {
1570 warn $project->{name
}, ": skipping update of hookspath to same effective value\n" unless $quiet;
1574 $rshp = $ghp if $rshp eq $rghp;
1575 $rshp = $lhp if $rshp eq $rlhp;
1576 if ($rshp eq $ahp) {
1577 warn $project->{name
}, ": skipping update of hookspath to same value\n" unless $quiet;
1580 die "refusing to set neither local nor global hookspath without --force\n"
1581 if !$force && $rshp ne $ghp && $rshp ne $lhp;
1582 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1583 'config', "core.hookspath", $rshp);
1584 my $newval = '"'.$rshp.'"';
1585 $newval = "global" if $rshp eq $ghp;
1586 $newval = "local" if $rshp eq $lhp;
1587 warn $project->{name
}, ": hookspath set to $newval\n" unless $quiet;
1603 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1604 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1605 my $project = get_project
($ARGV[0]);
1606 if (!exists($boolfields{$ARGV[1]})) {
1607 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1609 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1610 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1612 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1614 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1615 die "invalid boolean value: \"$ARGV[2]\"\n";
1617 my $bool = clean_bool
($ARGV[2]);
1618 my $old = $project->{$ARGV[1]};
1620 print "$old\n" if defined($old);
1623 if (defined($old) && $old eq $bool) {
1624 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1626 # Avoid touching anything other than $ARGV[1] field
1627 $project->_property_fput($ARGV[1], $bool);
1628 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1633 sub cmd_setjsontype
{
1634 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1635 my $project = get_project
($ARGV[0]);
1638 my $jt = lc($ARGV[1]);
1639 index($jt, "/") >= 0 or $jt = "application/".$jt;
1640 $jt eq 'application/x-www-form-urlencoded' ||
1641 $jt eq 'application/json' or
1642 die "invalid jsontype value: \"$ARGV[1]\"\n";
1645 my $old = $project->{jsontype
};
1647 print "$old\n" if defined($old);
1650 if (defined($old) && $old eq $jsontype) {
1651 warn $project->{name
}, ": skipping update of jsontype to same value\n" unless $quiet;
1653 # Avoid touching anything other than jsontype field
1654 $project->_property_fput('jsontype', $jsontype);
1655 warn $project->{name
}, ": jsontype updated to $jsontype\n" unless $quiet;
1660 sub cmd_setjsonsecret
{
1661 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1662 my $project = get_project
($ARGV[0]);
1666 $js =~ s/^\s+//; $js =~ s/\s+$//;
1669 my $old = $project->{jsonsecret
};
1671 print "$old\n" if defined($old);
1674 if (defined($old) && $old eq $jsonsecret) {
1675 warn $project->{name
}, ": skipping update of jsonsecret to same value\n" unless $quiet;
1677 # Avoid touching anything other than jsonsecret field
1678 $project->_property_fput('jsonsecret', $jsonsecret);
1679 warn $project->{name
}, ": jsonsecret updated to \"$jsonsecret\"\n" unless $quiet;
1684 sub cmd_setautogchack
{
1685 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1686 my $project = get_project
($ARGV[0]);
1687 my $aghok = $Girocco::Config
::autogchack
&&
1688 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1689 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1691 print "$old\n" if $aghok;
1695 if (lc($ARGV[1]) eq "unset") {
1698 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1699 $bool = clean_bool
($ARGV[1]);
1702 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1703 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1705 if ($old eq $bool) {
1706 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1708 if ($bool eq "unset") {
1709 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1710 'config', '--unset', "girocco.autogchack");
1712 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1713 'config', '--bool', "girocco.autogchack", $bool);
1716 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1721 my ($url, $type) = @_;
1722 $type ne 'baseurl' and return valid_web_url
($url);
1723 valid_repo_url
($url) or return 0;
1724 if ($Girocco::Config
::restrict_mirror_hosts
) {
1725 my $mh = extract_url_hostname
($url);
1726 is_dns_hostname
($mh) or return 0;
1727 !is_our_hostname
($mh) or return 0;
1735 baseurl
=> ["url" , 1],
1736 homepage
=> ["hp" , 0],
1737 notifyjson
=> ["notifyjson", 0],
1743 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1744 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1745 my $project = get_project
($ARGV[0]);
1746 if (!exists($urlfields{$ARGV[1]})) {
1747 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1749 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1750 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1752 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1754 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1755 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1757 warn "using invalid URL with --force\n" unless $quiet;
1759 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1761 print "$old\n" if defined($old);
1764 if (defined($old) && $old eq $ARGV[2]) {
1765 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1767 # Avoid touching anything other than $ARGV[1]'s field
1768 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1769 if ($ARGV[1] eq "baseurl") {
1770 $project->{url
} = $ARGV[2];
1771 $project->_set_bangagain;
1773 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1774 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1789 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1790 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1791 my $project = get_project
(shift @ARGV);
1792 my $field = shift @ARGV;
1793 if (!exists($msgsfields{$field})) {
1794 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1796 if (@ARGV && !valid_addrlist
(@ARGV)) {
1797 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1799 warn "using invalid email address list with --force\n" unless $quiet;
1801 my $old = $project->{$field};
1803 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1806 my $newlist = clean_addrlist
(join(" ",@ARGV));
1807 if (defined($old) && $old eq $newlist) {
1808 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1810 # Avoid touching anything other than $field's field
1811 $project->_property_fput($field, $newlist);
1812 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1819 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1820 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1821 my $project = get_project
(shift @ARGV);
1822 my $projname = $project->{name
};
1823 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
1826 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
1827 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1829 return 0 if !@ARGV && $project->{mirror
};
1830 my $oldusers = $project->{users
};
1831 if ($oldusers && ref($oldusers) eq "ARRAY") {
1832 $oldusers = join("\n", @
$oldusers);
1837 print "$oldusers\n" if $oldusers ne "";
1840 if ($oldusers eq join("\n", @newusers)) {
1841 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1843 # Avoid touching anything other than the users list
1844 $project->{users
} = \
@newusers;
1845 $project->_update_users;
1846 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1854 owner
=> [\
&cmd_setowner
, 0],
1855 desc
=> [\
&cmd_setdesc
, 0],
1856 description
=> [\
&cmd_setdesc
, 0],
1857 readme
=> [\
&cmd_setreadme
, 0],
1858 head
=> [\
&cmd_sethead
, 0],
1859 HEAD
=> [\
&cmd_sethead
, 0],
1860 hooks
=> [\
&cmd_sethooks
, 0],
1861 hookspath
=> [\
&cmd_sethooks
, 0],
1862 cleanmirror
=> [\
&cmd_setbool
, 1],
1863 reverseorder
=> [\
&cmd_setbool
, 1],
1864 summaryonly
=> [\
&cmd_setbool
, 1],
1865 statusupdates
=> [\
&cmd_setbool
, 1],
1866 autogchack
=> [\
&cmd_setautogchack
, 0],
1867 baseurl
=> [\
&cmd_seturl
, 1],
1868 homepage
=> [\
&cmd_seturl
, 1],
1869 notifyjson
=> [\
&cmd_seturl
, 1],
1870 jsontype
=> [\
&cmd_setjsontype
, 0],
1871 jsonsecret
=> [\
&cmd_setjsonsecret
, 0],
1872 notifymail
=> [\
&cmd_setmsgs
, 1],
1873 notifytag
=> [\
&cmd_setmsgs
, 1],
1874 users
=> [\
&cmd_setusers
, 0],
1881 push(@newargs, shift) if @_ && $_[0] eq '--force';
1883 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
1884 push(@newargs, shift);
1885 shift unless ${$fieldnames{$field}}[1];
1887 diename
(($setopt ?
"set " : "get ") . $field);
1889 &{${$fieldnames{$field}}[0]}(@ARGV);
1904 create
=> \
&cmd_create
,
1905 adopt
=> \
&cmd_adopt
,
1906 remove
=> \
&cmd_remove
,
1907 trash
=> \
&cmd_remove
,
1908 delete => \
&cmd_remove
,
1910 listheads
=> \
&cmd_listheads
,
1911 listtags
=> \
&cmd_listtags
,
1912 listctags
=> \
&cmd_listtags
,
1913 deltags
=> \
&cmd_deltags
,
1914 delctags
=> \
&cmd_deltags
,
1915 addtags
=> \
&cmd_addtags
,
1916 addctags
=> \
&cmd_addtags
,
1917 chpass
=> \
&cmd_chpass
,
1918 checkpw
=> \
&cmd_checkpw
,
1920 update
=> \
&cmd_update
,
1921 remirror
=> \
&cmd_remirror
,
1922 setowner
=> \
&cmd_setowner
,
1923 setdesc
=> \
&cmd_setdesc
,
1924 setdescription
=> \
&cmd_setdesc
,
1925 setreadme
=> \
&cmd_setreadme
,
1926 sethead
=> \
&cmd_sethead
,
1927 sethooks
=> \
&cmd_sethooks
,
1928 sethookspath
=> \
&cmd_sethooks
,
1929 setbool
=> \
&cmd_setbool
,
1930 setboolean
=> \
&cmd_setbool
,
1931 setflag
=> \
&cmd_setbool
,
1932 setautogchack
=> \
&cmd_setautogchack
,
1933 seturl
=> \
&cmd_seturl
,
1934 setjsontype
=> \
&cmd_setjsontype
,
1935 setjsonsecret
=> \
&cmd_setjsonsecret
,
1936 setmsgs
=> \
&cmd_setmsgs
,
1937 setusers
=> \
&cmd_setusers
,
1945 my $bn = basename
($0);
1946 printf "%s version %s\n\n", $bn, $VERSION;
1947 if (defined($cmd) && $cmd ne '') {
1948 $cmd =~ s/^set(?=[a-zA-Z])//i;
1950 my ($lastmt, $incmd);
1951 foreach (split('\n', sprintf($help, $bn))) {
1952 $lastmt || $incmd or $lastmt = /^\s*$/, next;
1953 $incmd = 1 if $lastmt && /^\s*(?:\[?set\]?)?$cmd\s/;
1954 last if $incmd && /^\s*$/;
1955 $incmd and $cmdhelp .= $_ . "\n";
1958 print $cmdhelp and exit 0 if $cmdhelp;
1966 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1967 dohelp
($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1968 my $command = shift;
1971 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1973 $command = "set" . $command;
1975 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1976 dohelp
($command) if @ARGV && ($ARGV[0] =~ /^(?:-h|-?-help)$/i ||
1977 $ARGV[0] =~ /^help$/i && !Girocco
::Project
::does_exist
("help",1));
1978 &{$commands{$command}}(@ARGV);