3 # projtool.pl - command line Girocco project maintenance tool
4 # Copyright (C) 2016,2017,2020,2021 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.4'}
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 [<global option>...] <command> <options>
35 -q | --quiet suppress warning messages
36 -p | --pager force output to be paginated
37 --no-pager never paginate output
39 Note that as a convenience, where an existing <project> is required as
40 an argument, a path to the project may be given instead of the name in
41 most places. The "remove" and "prune" commands only accept names.
42 Since a matching project name takes precedence over a path, to force
43 interpretation as a path, start the path with "/" or "./" or "../".
44 Giving "." will find the project matching the current working directory.
47 show full help or just for <command> if given
49 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
50 list all projects (default is --sort=lcname)
51 limit to project names matching <regex> if given
52 match <regex> against owner instead of project name with --owner
54 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
55 create new project <project> (prompted)
57 --no-alternates skip setup of objects/info/alternates
58 --orphan allow creation of subproject w/o a parent
59 -p use mkdir -p during --orphan creation
60 --no-password set password crypt to invalid value "unknown"
61 --no-owner leave the gitweb.owner config unset
62 --mirror=<url> create a mirror from <url>
63 --full-mirror mirror all refs
64 --push[=<list>] create a push project
65 --desc=<string> specify project description w/o prompt
66 --homepage=<url> specify project homepage URL w/o prompt
67 --defaults do no interactive prompting at all
68 Using --no-password skips the prompts for password, using
69 --no-owner skips the prompt for owner and using --mirror=<url>
70 or --push[=<list>] skips the prompts for mirror URL and
71 heads-only and push users. With --defaults if neither
72 --mirror=<url> nor --push[=<list>] is given then --push will
73 be implied. Using --desc=<string> will force a specific
74 description (including an empty string) and skip the prompt for
75 it. Otherwise a non-empty default description will always be
76 supplied in lieu of an empty or omitted description.
78 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
79 adopt project <project>
80 type of project is guessed if --type=<type> omitted
81 <users> is same as <newuserslist> for setusers command
83 --dry-run do all the checks but don't perform adoption
84 --verbose show project info dump (useful with --dry-run)
85 --no-users no push users at all (<users> must be omitted)
86 --no-owner leave the gitweb.owner config totally unchanged
87 --owner=<val> set the gitweb.owner config to <val>
88 Both --no-owner and --owner=<val> may NOT be given, with neither
89 take owner from preexisting gitweb.owner else use admin setting.
90 For mirrors <users> is ignored otherwise if no <users> and no
91 --no-users option the push users list will consist of the single
92 user name matching the owner or empty if none or more than one.
93 With --dry-run <project> can be an absolute path to a git dir.
95 remove [--force] [--really-delete] [--keep-forks] <project>
96 remove project <project>
97 do not move to _recyclebin with --really-delete (just rm -rf)
98 remove projects with forks (by keeping forks) using --keep-forks
100 prune [--quiet] (--force | --dry-run) [<project>...]
101 check to see if any projects (default is all projects) are
102 missing the associated project directory on disk.
103 Requires either --force or --dry-run option to operate.
104 With --dry-run only show what would be done.
105 With --prune actually remove any extraneous project(s).
106 With --dry-run exit code is non-zero if any action needed.
107 With --quiet, suppress output message, if any.
110 show project <project>
112 verify [--quiet] <project>
113 show the canonical project name for <project> (which might
114 be a path) if and only if it exists. Otherwise display an
115 error (unless --quiet is used). Exit status will be 0 if
116 project found, non-zero otherwise.
118 urls [--push] <project>
119 show available fetch/push URLs for <project>
120 Note that this does NOT include non-Git protocol URLs such
121 as any home page or any upstream URL for a mirror project --
122 those are all accessible via the "show" command.
123 The URLs shown are those that would be shown by gitweb.cgi.
124 With --push only show push urls (mirrors have no push urls)
127 list all available heads for <project> and indicate current head
129 listtags [--verbose] <project>
130 list all ctags on project <project>
131 with --verbose include tag counts
133 deltags <project> [-i] <tagstodel>
134 remove any ctags on project <project> present in <tagstodel>
135 <tagstodel> is space or comma separated list of tags to remove
136 with -i match against <tagstodel> without regard to letter case
138 addtags <project> <tagstoadd>
139 add ctags to project <project>
140 <tagstoadd> is space or comma separated list of tags to add
142 chpass [--force] <project> [random | unknown]
143 change project <project> password (prompted)
144 with "random" set to random password
145 with "unknown" set password hash to invalid value "unknown"
148 check project <project> password for a match (prompted)
150 gc [--force | --auto] [--redelta | --recompress] <project>
151 run the gc.sh script on project <project>
152 with --auto let the gc.sh script decide what to do
153 with --force cause a full gc to take place (force_gc=1)
154 with neither --auto nor --force do a mini or if needed a full gc
155 (in other words just touch .needsgc and run gc.sh)
156 with --redelta a full gc will use pack-objects --no-reuse-delta
157 with --recompress a full gc uses pack-objects --no-reuse-object
158 (--no-reuse-delta and --no-reuse-object are accepted as aliases)
159 with --aggressive activate the --force and --redelta options
160 unless the global --quiet option is given show_progress=1 is used
162 update [--force] [--quiet | --summary] <project>
163 run the update.sh script on project <project>
164 with --force cause a fetch to always take place (force_update=1)
165 with --quiet only show errors (show_progress is left unset)
166 with --summary show progress and ref summary (show_progress=1)
167 with neither --quiet nor --summary show it all (show_progress=2)
169 remirror [--force] <project>
170 initiate a remirror of project <project>
172 [set]owner [--force] <project> <newowner>
173 set project <project> owner to <newowner>
174 without "set" and only 1 arg, just show current project owner
176 [set]desc [--force] <project> <newdesc>
177 set project <project> description to <newdesc>
178 without "set" and only 1 arg, just show current project desc
180 [set]readme [--force] [--format=<readmetype>] <project> [<newsetting>]
181 set project <project> readme to <newsetting>
182 <readmetype> is markdown|plain|html (default is no change)
183 <newsetting> is automatic|suppressed|-|[@]filename
184 with "set" <readmetype> and/or <newsetting> is required
185 without "set" and only 2 args, just show current readme setting
187 [set]head <project> <newhead>
188 set project <project> HEAD symbolic ref to <newhead>
189 without "set" and only 1 arg, just show current project HEAD
191 [set]bool [--force] <project> <flagname> <boolvalue>
192 set project <project> boolean <flagname> to <boolvalue>
193 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
194 without "set" and only 2 args, just show current flag value
196 [set]hooks [--force] <project> local | global | <path>
197 set project <project> hookspath to local, global or <path>
198 without "set" and only 1 arg, just show current hookspath
200 [set]autogchack <project> <boolvalue> | unset
201 set project <project> autogchack to <boolvalue> or "unset" it
202 without "set" just show current autogchack setting if enabled
203 with "set" autogchack must be enabled in Config.pm for the
204 type of project and maintain-auto-gc-hack.sh is always run
206 [set]url [--force] <project> <urlname> <newurlvalue>
207 set project <project> url <urlname> to <newurlvalue>
208 <urlname> is baseurl|homepage|notifyjson
209 without "set" and only 2 args, just show current url value
211 [set]msgs [--force] <project> <msgsname> <eaddrlist>
212 set project <project> msgs <msgsname> to <addrlist>
213 <msgsname> is notifymail|notifytag
214 <eaddrlist> is space or comma separated list of email addresses
215 without "set" and only 2 args, just show current msgs value
217 [set]users [--force] <project> <newuserslist>
218 set push project <project> users list to <newuserslist>
219 <newuserslist> is space or comma separated list of user names
220 without "set" and only 1 arg, just show current users list
222 [set]jsontype <project> <newjsontype>
223 set project <project> JSON Content-Type to <newjsontype>
224 <newjsontype> is x-www-form-urlencoded or json
225 without "set" and only 1 arg, just show current jsontype
227 [set]jsonsecret <project> <newjsonsecret>
228 set project <project> JSON secret to <newjsonsecret>
229 <newjsonsecret> is a string (empty string disables signatures)
230 without "set" and only 1 arg, just show current jsonsecret
232 get <project> <fieldname>
233 show project <project> field <fieldname>
234 <fieldname> is owner|desc|readme|head|hooks|users|jsontype
235 or jsonsecret|<flagname>|autogchack|<urlname>|<msgsname>
237 set [--force] <project> <fieldname> <newfieldvalue>
238 set project <project> field <fieldname> to <newfieldvalue>
239 <fieldname> same as for get
240 <newfieldvalue> same as for corresponding set... command
247 my $sub = shift || diename
;
249 die "Invalid arguments to $sub command -- try \"help\"\n";
251 die "Invalid arguments -- try \"help\"\n";
257 defined($rm) or $rm = '';
258 return "length " . length($rm);
261 sub get_readme_desc
{
263 defined($rm) or $rm = '';
266 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
268 return $test eq '' ?
"suppressed" : "length " . length($rm);
274 sub get_ctag_counts
{
278 foreach ($project->get_ctag_names) {
281 if (open $ct, '<', $project->{path
}."/ctags/$_") {
284 defined $count or $count = '';
286 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
292 push(@ctags, $_."(".$val.")");
295 push(@ctags, [$_, $val]) if $val;
301 sub get_clean_project
{
302 my $project = get_project_harder
(@_);
303 delete $project->{loaded
};
304 delete $project->{base_path
};
305 delete $project->{ccrypt
};
306 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
307 $project->{owner
} = $project->{email
}; delete $project->{email
};
308 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
309 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
310 if (defined($project->{path
}) && $project->{path
} ne "") {
311 my $rp = realpath
($project->{path
});
312 defined($rp) && $rp ne "" and $project->{realpath
} = $rp;
313 if (-f
"$rp/objects/info/packs") {
314 my $ipt = (stat _
)[9];
315 defined($ipt) and $project->{infopackstime
} =
316 strftime
("%Y-%m-%d %H:%M:%S %z", localtime($ipt));
319 my $owner = $project->{owner
};
322 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
323 $project->{owner_users
} = \
@owner_users if @owner_users;
325 my $projname = $project->{name
};
326 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
327 $project->{has_forks
} = 1 if @forks;
328 $project->{has_alternates
} = 1 if $project->has_alternates;
329 my @bundles = $project->bundles;
330 for (my $i = 0; $i < @bundles; ++$i) {
331 my $secs = $bundles[$i]->[0];
332 $bundles[$i]->[0] = strftime
("%Y-%m-%d %H:%M:%S %z", localtime($secs));
333 my $sz = $bundles[$i]->[2];
334 1 while $sz =~ s/(?<=\d)(\d{3})(?:,|$)/,$1/g;
335 $bundles[$i]->[2] = $sz;
337 delete $project->{bundles
};
338 $project->{bundles
} = \
@bundles if @bundles;
339 $project->{mirror
} = 0 unless $project->{mirror
};
340 $project->{is_empty
} = 1 if $project->is_empty;
341 delete $project->{showpush
} unless $project->{showpush
};
342 delete $project->{users
} if $project->{mirror
};
343 delete $project->{baseurl
} unless $project->{mirror
};
344 delete $project->{banged
} unless $project->{mirror
};
345 delete $project->{lastrefresh
} unless $project->{mirror
};
346 delete $project->{cleanmirror
} unless $project->{mirror
};
347 delete $project->{statusupdates
} unless $project->{mirror
};
348 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
349 unless ($project->{banged
}) {
350 delete $project->{bangcount
};
351 delete $project->{bangfirstfail
};
352 delete $project->{bangmessagesent
};
354 my $projhook = $project->_has_notifyhook;
355 if (defined($projhook) && $projhook ne "") {
356 $project->{notifyhook
} = $projhook;
358 delete $project->{notifyhook
};
360 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
361 $project->{READMEDATA
} = get_readme_len
($project->{READMEDATA
}) if exists($project->{READMEDATA
});
362 my @tags = get_ctag_counts
($project, 1);
363 $project->{tags
} = \
@tags if @tags;
364 my $projconfig = read_config_file_hash
($project->{path
}."/config");
365 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
366 my $ahp = $projconfig->{"core.hookspath"};
367 my $rahp = realpath
($ahp);
368 my $lhp = $project->{path
}."/hooks";
369 my $rlhp = realpath
($lhp);
370 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
371 my $rghp = realpath
($ghp);
372 $project->{has_local_hooks
} = 1 if
373 defined($rahp) && defined($rlhp) && $rahp eq $rlhp;
374 $project->{has_global_hooks
} = 1 if
375 defined($rahp) && defined($rghp) && $rahp eq $rghp;
376 $project->{hookspath
} = $ahp unless $ahp eq $lhp || $ahp eq $ghp;
384 foreach (split(/[,\s]+/, $_[0])) {
386 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
388 return join(($_[1]||","), @newlist);
392 my $cleaned = clean_addrlist
(join(" ", @_));
393 return 1 if $cleaned eq "";
394 valid_email_multi
($cleaned) && length($cleaned) <= 512;
398 my ($userlist, $force, $nodie) = @_;
402 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
403 my %users = map({($$_[1] => $_)} get_all_users
);
404 foreach (split(/[\s,]+/, $userlist)) {
405 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
406 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
409 if (Girocco
::User
::does_exist
($_, 1)) {
411 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
414 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
419 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
421 die if $badlist && !$nodie;
425 sub is_default_desc
{
426 # "Unnamed repository; edit this file 'description' to name the repository."
427 # "Unnamed repository; edit this file to name it for gitweb."
429 return 0 unless defined($_);
430 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
436 return 0 if $test =~ /[\r\n]/;
437 $test =~ s/\s\s+/ /g;
445 defined($desc) or $desc = '';
447 $desc = to_utf8
($desc, 1);
448 $desc =~ s/\s\s+/ /g;
455 Girocco
::CLIUtil
::_parse_options
(
457 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
465 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
466 name
=> sub {$$a[1] cmp $$b[1]},
467 gid
=> sub {$$a[3] <=> $$b[3]},
468 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
469 no => sub {$$a[0] <=> $$b[0]},
471 my $sortopt = 'lcname';
472 my ($verbose, $owner);
473 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
476 my $val = shift @ARGV;
477 $regex = qr
($val) or die "bad regex \"$val\"\n";
479 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
480 my $sortsub = $sortsub{$sortopt};
481 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
482 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
484 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
486 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
492 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
493 $ismirror, $desc, $fullmirror, $homepage);
495 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
496 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
497 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
498 ":description" => \
$desc, "full-mirror" => \
$fullmirror, ":homepage" => \
$homepage);
499 @ARGV == 1 or die_usage
;
500 !defined($pushusers) || defined($ispush) or $ispush = 1;
501 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
502 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
503 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
504 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
505 !$defaults || defined($nopasswd) or $nopasswd = 1;
506 !$defaults || defined($noowner) or $noowner = 1;
507 !defined($ispush) || defined($pushusers) or $pushusers = "";
508 my $projname = $ARGV[0];
509 $projname =~ s/\.git$//i;
510 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
511 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
512 warn "Refusing to create orphan project without --orphan\n"
513 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
514 warn "Required orphan parent directory does not exist (use -p): ",
515 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
516 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
517 die "Invalid project name: \"$projname\"\n";
519 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
520 my $newtype = $forkee ?
'fork' : 'project';
521 if (length($project) > 64) {
522 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
524 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
526 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
527 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
528 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
530 print "Enter settings for new project \"$projname\"\n" unless $defaults;
532 $settings{noalternates
} = $noalternates;
534 $settings{crypt} = "unknown";
536 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
537 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
538 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
539 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
540 "the admin passwords you have entered do not match each other.\n";
541 $settings{crypt} = scrypt_sha1
($np1);
545 $owner = prompt_or_die
("Owner/email name for project $projname");
546 unless (valid_email
($owner)) {
548 warn "Your email sure looks weird...?\n";
551 warn "Allowing invalid email with --force\n" unless $quiet;
553 if (length($owner) > 96) {
555 warn "Your email is longer than 96 characters. Do you really need that much?\n";
558 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
561 $settings{email
} = $owner;
563 my $checkmirror = sub {
564 my $checkurl = shift;
565 unless (valid_repo_url
($checkurl)) {
567 warn "Invalid mirror URL: \"$checkurl\"\n";
570 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
572 if ($Girocco::Config
::restrict_mirror_hosts
) {
573 my $mh = extract_url_hostname
($checkurl);
574 unless (is_dns_hostname
($mh)) {
576 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
579 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
581 if (is_our_hostname
($mh)) {
583 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
586 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
591 if ($ispush || $ismirror) {
592 !$ispush || $force || $Girocco::Config
::push or
593 die "Push projects are disabled, create a mirror (or use --force)\n";
594 !$ismirror || $force || $Girocco::Config
::mirror
or
595 die "Mirror projects are disabled, create a push project (or use --force)\n";
597 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
598 $baseurl = $ismirror;
599 $settings{url
} = $baseurl;
600 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
603 if ($pushusers !~ /^[\s,]*$/) {
604 eval {@newusers = validate_users
($pushusers, $force); 1;} or
605 die "Invalid --push user list\n";
607 $settings{users
} = \
@newusers;
609 } elsif ($force || $Girocco::Config
::mirror
) {{
610 if ($force || $Girocco::Config
::push) {
611 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
613 $baseurl = prompt_or_die
("URL to mirror from");
614 unless ($baseurl ne "") {
615 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
619 if ($baseurl ne "") {
620 &$checkmirror($baseurl) or redo;
621 $settings{url
} = $baseurl;
622 $settings{cleanmirror
} =
623 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
626 my $mirror = ($baseurl eq "") ?
0 : 1;
627 my $checkdesc = sub {
629 if (length($d) > 1024) {
631 warn "Short description length greater than 1024 characters!\n";
634 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
638 if (defined($desc)) {
639 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
640 $desc eq "" || &$checkdesc($desc) or
641 die "Invalid --desc description\n";
642 } elsif (!$defaults) {
643 $desc = prompt_or_die
("Short description", "");
644 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
645 $desc eq "" || &$checkdesc($desc) or redo;
646 $desc = undef if $desc eq "";
648 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
649 $settings{desc
} = $desc;
652 unless (valid_web_url
($hpurl)) {
654 warn "Invalid home page URL: \"$hpurl\"\n";
657 warn "Allowing invalid home page URL with --force\n" unless $quiet;
661 if (defined($homepage)) {
662 $homepage =~ s/^\s+//; $homepage =~ s/\s+$//;
663 $homepage eq "" || &$checkhp($homepage) or
664 die "Invalid --homepage URL\n";
665 } elsif (!$defaults) {
666 $homepage = prompt_or_die
("Home page URL", "");
667 $homepage =~ s/^\s+//; $homepage =~ s/\s+$//;
668 $homepage eq "" || &$checkhp($homepage) or redo;
669 $homepage = undef if $homepage eq "";
671 $settings{hp
} = $homepage;
674 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
675 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
677 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
680 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
683 $settings{notifyjson
} = $jsonurl;
684 my $commitaddrs = "";
686 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
687 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
689 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
692 warn "using invalid commit notify email address list with --force\n" unless $quiet;
695 $settings{notifymail
} = $commitaddrs;
696 $settings{reverseorder
} = 1;
697 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
698 if !$defaults && $commitaddrs ne "";
699 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
700 if !$defaults && $commitaddrs ne "";
703 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
704 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
706 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
709 warn "using invalid tag notify email address list with --force\n" unless $quiet;
712 $settings{notifytag
} = $tagaddrs;
713 if (!$mirror && !$ispush) {
716 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
717 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
719 $settings{users
} = \
@newusers;
721 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
722 or die "Girocco::Project->ghost call failed\n";
724 $newproj->{$k} = $v while ($k, $v) = each(%settings);
725 my $killowner = sub {
726 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
727 'config', '--unset', "gitweb.owner");
730 $newproj->premirror or die "Girocco::Project->premirror failed\n";
731 !$noowner or &$killowner;
732 $newproj->clone or die "Girocco::Project->clone failed\n";
733 warn "Project $projname created and cloning successfully initiated.\n"
736 $newproj->conjure or die "Girocco::Project->conjure failed\n";
737 !$noowner or &$killowner;
738 warn "New push project fork is empty due to use of --no-alternates\n"
739 if !$quiet && $projname =~ m
,/, && $noalternates;
740 warn "Project $projname successfully created.\n" unless $quiet;
747 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
748 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
752 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
753 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
754 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
755 @ARGV or die "Please give project name on command line.\n";
756 my $projname = shift @ARGV;
757 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
758 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
759 defined($type) or $type = "";
761 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
762 $projdir = realpath
($projname);
763 $projname = $projdir;
764 $projname =~ s/\.git$//i;
765 $projname =~ s
,/+$,,;
766 $projname =~ s
,^.*/,,;
767 $projname ne "" or $projname = $projdir;
769 $projname =~ s/\.git$//i;
770 $projname ne "" or die "Invalid project name \"\".\n";
771 unless (Girocco
::Project
::does_exist
($projname, 1)) {
772 Girocco
::Project
::valid_name
($projname, 1, 1)
773 or die "Invalid project name \"$projname\".\n";
774 die "No such project to adopt: $projname\n";
776 defined(Girocco
::Project
->load($projname))
777 and die "Project already known (no need to adopt): $projname\n";
778 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
779 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
781 my $config = read_config_file
($projdir . "/config");
783 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
784 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
785 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
786 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1)];
788 if (-e
"$projdir/description") {
789 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
795 defined $desc or $desc = "";
797 $desc = to_utf8
($desc, 1);
798 is_default_desc
($desc) and $desc = "";
799 if ($desc ne "" && !valid_desc
($desc)) {
800 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
802 warn "using invalid 'description' file contents with --force\n" unless $quiet;
804 $desc = clean_desc
($desc);
805 if (length($desc) > 1024) {
806 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
808 warn "using longer than 1024 char description with --force\n" unless $quiet;
814 my $origreadmedata = "";
815 my $readmetype = Girocco
::Project
::_normalize_rmtype
($config{"girocco.readmetype"},1);
816 if (-e
"$projdir/README.html") {
817 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
823 defined $readme or $readme = "";
824 $readme = to_utf8
($readme, 1);
825 $readme =~ s/\r\n?/\n/gs;
826 $readme =~ s/^\s+//s;
827 $readme =~ s/\s+$//s;
828 $readme eq "" or $readme .= "\n";
829 $origreadme = $readme;
830 if (-e
"$projdir/README.dat") {
831 open my $fd2, '<', "$projdir/README.dat" or die "Cannot open \"$projdir/README.dat\": $!\n";
834 $readmedata = <$fd2>;
837 defined $readmedata or $readmedata = "";
838 $readmedata = to_utf8
($readmedata, 1);
839 $readmedata =~ s/\r\n?/\n/gs;
840 $readmedata =~ s/^\s+//s;
841 $readmedata =~ s/\s+$//s;
842 $readmedata eq "" or $readmedata .= "\n";
843 $origreadmedata = $readmedata;
845 !$readmetype && length($readme) && !length($readmedata) and do {
846 # the old HTML format
847 $readmetype = 'HTML';
848 $readmedata = $readme;
850 if (length($readmedata) > 8192) {
851 die "readme greater than 8192 chars is too long (use --force to override)\n"
853 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
856 my $dummy = {READMEDATA
=> $readmedata, rmtype
=> $readmetype, name
=> $projname};
857 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
859 my $msg = "README: $cnt error";
860 $msg .= "s" unless $cnt == 1;
861 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
862 unless $force && $quiet;
863 exit(255) unless $force && $readmetype eq 'HTML';
864 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
866 $readme = $dummy->{README
};
870 $readmetype or $readmetype = Girocco
::Project
::_normalize_rmtype
(""); # use default type
871 # Inspect any remotes now
872 # Yes, Virginia, remote urls can be multi-valued
876 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
877 my ($name, $subkey) = ($1, $2);
878 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
879 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
880 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
881 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
882 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
884 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
885 # the remote names in a group are separated by runs of [ \t\n] characters
886 # remote names "", ".", ".." and any name starting with "/" are invalid
887 # a remote with no url or vcs setting is not considered valid
890 if (exists($config{"remotes
.default"})) {
891 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
892 next unless exists($remotes{$_});
893 my $rmt = $remotes{$_};
894 next if !exists($rmt->{url}) && !$rmt->{vcs};
902 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
903 next if $seenrmt{$1};
905 next unless exists($remotes{$1});
906 my $rmt = $remotes{$1};
907 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
911 my @needskip = (); # remotes that need skipDefaultUpdate set to true
914 my $foundfetchwithmirror = 0;
916 my $rmt = $remotes{$_};
917 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
918 next unless exists($rmt->{fetch});
920 ++$foundfetchwithmirror if $rmt->{mirror};
921 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
923 # if we have $foundvcs then we need to explicitly set fetch.prune to false
924 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
925 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
927 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
928 # if remote "origin
" exists we always pick up its first url or use ""
929 if (exists($remotes{origin})) {
930 my $rmt = $remotes{origin};
931 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
932 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
935 # get the first url of the @check remotes
937 my $rmt = $remotes{$_};
938 next unless exists($rmt->{url});
939 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
940 $baseurl = $rmt->{url}->[0];
944 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
946 # If we have $foundfetch we want to make a mirror but complain if
947 # we $foundfetchwithmirror as well unless we have --type=mirror.
948 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
949 # Warn if we need to set fetch.prune=false when making a mirror
950 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
951 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
952 # Warn if $usingall and any @needskip (and set them) if making a mirror
953 # Warn if making a mirror and $baseurl eq ""
954 # Warn if we have --type=mirror and !$foundfetch
957 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
958 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
959 if ($foundfetchwithmirror) {
960 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
961 "(Use
--type
=mirror to override
)\n"
962 unless $type eq "mirror
";
963 exit(255) unless $type eq "mirror
" || $dryrun;
964 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
965 unless $quiet || $type ne "mirror
";
967 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
968 if !$quiet && $neednoprune;
969 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
970 if !$quiet && $needfakeorigin;
971 if (!$usingall && @needskip) {
972 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
974 exit(255) unless $force || $dryrun;
975 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
976 unless $quiet || !$force;
978 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
979 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
981 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
982 if !$quiet && $foundfetch && !$foundfetchwithmirror;
985 if (!$noowner && !defined($owner)) {
987 $owner = $config{"gitweb
.owner
"};
988 if (!defined($owner) || $owner eq "") {
989 $owner = $Girocco::Config::admin;
990 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
993 if (!$nousers && !$makemirror && !defined($users)) {
994 # select user list for push project
995 my $findowner = $owner;
996 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
997 $findowner = lc($findowner) if defined($findowner);
998 my @owner_users = ();
999 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
1000 if defined($findowner) && $findowner ne "";
1001 defined($findowner) or $findowner = "";
1002 if (@owner_users <= 1) {
1003 $users = \@owner_users;
1004 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
1007 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
1008 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
1011 defined($users) or $users = [];
1013 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
1014 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
1015 # and warn about preserving the setting)
1017 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
1018 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
1019 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
1020 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
1021 $config{"receive
.denydeletecurrent
"} ne "warn";
1023 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
1024 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
1025 if ($reflogactive || $reflogfiles) {
1026 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
1027 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
1028 exit(255) unless $force || $dryrun;
1029 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
1030 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
1033 return 0 if $dryrun && !$verbose;
1035 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
1036 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
1037 $newproj->{desc} = $desc;
1038 $newproj->{README} = $readme;
1039 $newproj->{READMEDATA} = $readmedata;
1040 $newproj->{rmtype} = $readmetype;
1041 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
1042 $newproj->{email} = $owner if defined($owner);
1043 $newproj->{users} = $users;
1044 $newproj->{crypt} = "unknown
";
1045 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
1046 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
1047 my $dummy = bless {}, "Girocco
::Project
";
1048 $dummy->{path} = "$projdir";
1049 $dummy->{configfilehash} = \%config;
1050 $dummy->_properties_load;
1051 delete $dummy->{origurl};
1052 foreach my $k (keys(%$dummy)) {
1053 $newproj->{$k} = $dummy->{$k}
1054 if exists($dummy->{$k}) && !exists($newproj->{$k});
1059 my %info = %$newproj;
1060 $info{README} = get_readme_desc($info{README}) if exists($info{README});
1061 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
1062 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1063 print $d->Dump([\%info], ['*'.$newproj->{name}]);
1065 return 0 if $dryrun;
1067 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
1069 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
1070 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
1071 if ($usingall && @needskip) {
1072 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
1076 # Write out any README.dat/README.html changes before the actual Adoption
1077 # Otherwise they will get stepped on. The Girocco::Project::adopt function
1078 # does not know how to validate README.html during adoption like the above code does.
1079 if ($readmedata ne $origreadmedata) {
1080 open my $fd, '>', "$projdir/README.dat" or die "Cannot write \"$projdir/README
.dat
\": $!\n";
1081 print $fd $readmedata or die "Error writing
\"$projdir/README
.dat
\": $!\n";
1082 close $fd or die "Error closing
\"$projdir/README
.dat
\": $!\n";
1084 if ($readme ne $origreadme || ! -e "$projdir/README
.html
") {
1085 open my $fd, '>', "$projdir/README.html" or die "Cannot write \"$projdir/README
.html
\": $!\n";
1086 print $fd $readme or die "Error writing
\"$projdir/README
.html
\": $!\n";
1087 close $fd or die "Error closing
\"$projdir/README
.html
\": $!\n";
1089 git_config($projdir, "girocco
.rmtype
", $readmetype);
1091 # Perform the actual adoption
1092 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
1094 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
1095 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
1096 if git_bool($config{"receive
.denynonfastforwards
"});
1097 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
1098 if exists($config{"receive
.denydeletecurrent
"}) &&
1099 $config{"receive
.denydeletecurrent
"} ne "warn";
1100 git_config($projdir, "core
.logAllRefUpdates
", "true
")
1105 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
1107 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
1113 my ($force, $reallydel, $keepforks);
1114 parse_options(force => \$force, "really
-delete" => \$reallydel,
1115 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
1116 @ARGV or die "Please give project name on command line
.\n";
1117 @ARGV == 1 or die_usage;
1118 my $project = get_project($ARGV[0]); # for safety only names accepted here
1119 my $projname = $project->{name};
1120 my $isempty = !$project->{mirror} && $project->is_empty;
1121 if (!$project->{mirror} && !$isempty && $reallydel) {
1122 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
1123 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
1127 if ($project->has_forks) {
1128 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
1129 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
1130 # Run pseudo GC on that repository so that objects don't get lost within forks
1131 my $basedir = $Girocco::Config::basedir;
1132 my $projdir = $project->{path};
1133 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
1134 my $nogcrunning = sub {
1135 die "Error: GC appears to be currently running on $projname\n"
1136 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
1139 $removenogc = ! -e "$projdir/.nogc";
1140 recreate_file("$projdir/.nogc") if $removenogc;
1141 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
1142 delete $ENV{show_progress};
1143 $ENV{'show_progress
'} = 1 unless $quiet;
1146 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
1147 or die "Running pseudo GC on project $projname failed\n";
1151 if (!$project->{mirror} && !$isempty && !$reallydel) {
1152 $archived = $project->archive_and_delete;
1153 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1157 warn "Project '$projname' removed from $Girocco::Config::name" .
1158 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1159 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1164 my ($force, $dryrun);
1165 parse_options(force => \$force, "dry-run" => \$dryrun, "quiet" => \$quiet);
1166 ($force && !$dryrun) || (!$force && $dryrun) or die_usage;
1168 my %allprojs = map({($$_[0] => $_)} Girocco::Project::get_full_list_extended());
1169 my @allprojs = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%allprojs));
1171 @projs or @projs = @allprojs;
1172 my $bd = $Girocco::Config::reporoot.'/';
1175 !$seen{$_} && $allprojs{$_} && ${$allprojs{$_}}[2] >= 65536 or next;
1177 /^[a-zA-Z0-9]/ or next;
1178 my $pd = $bd . $_ . '.git
';
1180 warn "$_: no such directory: $pd\n" unless $quiet;
1183 warn "$_: exists but not directory: $pd\n" unless $quiet;
1187 warn "\n" if @remove && !$quiet;
1189 return 0 unless @remove;
1190 my $msg = "Would remove ".scalar(@remove). " project entr";
1191 $msg .= (@remove == 1 ? "y" : "ies");
1193 $msg .= join("", map("\t$_\n", @remove));
1194 print $msg unless $quiet;
1197 my $msg = "Removed ".scalar(@remove). " project entr";
1198 $msg .= (@remove == 1 ? "y" : "ies");
1200 $msg .= join("", map("\t$_\n", @remove));
1201 my %remove = map({$_ => 1} @remove);
1202 filedb_atomic_edit(jailed_file('/etc/group
'), sub {
1203 my ($name,undef,$gid) = split /:/;
1204 $gid =~ /^\d+$/ && $gid >= 65536 or return $_;
1205 $name =~ /^[a-zA-Z0-9]/ or return $_;
1206 !exists($remove{$name}) and return $_;
1208 print $msg unless $quiet;
1214 @ARGV == 1 or die_usage;
1215 my $project = get_clean_project($ARGV[0]);
1216 my %info = %$project;
1217 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1218 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1219 print $d->Dump([\%info], ['*'.$project->{name}]);
1224 use Scalar::Util ();
1225 my $rt = sub { return ref($_[0]) ? Scalar::Util::reftype($_[0]) : '' };
1226 parse_options("quiet" => \$quiet);
1227 @ARGV == 1 or die_usage;
1228 my $project = undef;
1231 $project = get_project_harder($ARGV[0]);
1233 $pname = $project->{name} if &$rt($project) eq 'HASH
';
1234 defined($pname) && $pname ne "" or $project = undef;
1235 !$@ && &$rt($project) ne 'HASH
' and $@ = "No such project: \"$ARGV[0]\"\n";
1236 warn $@ if $@ && !$quiet;
1238 printf "%s\n", $pname;
1244 parse_options("push" => \$pushonly);
1246 @ARGV == 1 or die_usage;
1247 my $project = get_project_harder($ARGV[0]);
1248 my $suffix = "/".$project->{name}.".git";
1249 @Gitweb::Config::git_base_url_list = ();
1250 @Gitweb::Config::git_base_push_urls = ();
1251 @Gitweb::Config::git_base_mirror_urls = ();
1253 package Gitweb::Config;
1254 do $Girocco::Config::basedir."/gitweb/gitweb_config.perl";
1255 !$! or die "could not read gitweb_config.perl: $!\n";
1256 !$@ or die "could not parse gitweb_config.perl: $@\n";
1258 my @fetch_urls = ();
1264 ref($_) eq 'ARRAY
' or die "expected ARRAY ref";
1266 defined($u) && $u ne "" and
1267 push(@$array, $u.$suffix);
1268 } elsif (defined($_) && $_ ne "") {
1269 push(@$array, $_.$suffix);
1275 $items{$_} = 1 foreach @_;
1278 &$add_url(\@fetch_urls, @Gitweb::Config::git_base_url_list);
1279 if ($project->{mirror}) {
1280 &$add_url(\@fetch_urls, @Gitweb::Config::git_base_mirror_urls);
1282 &$add_url(\@push_urls, @Gitweb::Config::git_base_push_urls);
1286 push(@urls, &$uniq(@push_urls));
1288 push(@urls, &$uniq(@fetch_urls, @push_urls));
1290 print map "$_\n", @urls;
1295 @ARGV == 1 or die_usage;
1296 my $project = get_project_harder($ARGV[0]);
1297 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1298 my $cur = $project->{HEAD};
1299 defined($cur) or $cur = '';
1301 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1302 defined($headhash) or $headhash = '';
1304 $headhash or $curmark = '!';
1306 my $mark = $_ eq $cur ? $curmark : ' ';
1314 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1315 @ARGV == 1 or die_usage;
1316 my $project = get_project_harder($ARGV[0]);
1318 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1320 print map("$_\n", $project->get_ctag_names);
1327 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1328 @ARGV >= 2 or die_usage;
1329 my $project = get_project_harder(shift @ARGV);
1332 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1334 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1338 my $ctags = join(" ", @ARGV);
1339 $ctags = lc($ctags) if $ic;
1340 foreach (split(/[\s,]+/, $ctags)) {
1341 next unless exists($curtags{$_});
1342 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1345 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1347 # Avoid touching anything other than the ctags
1348 foreach my $tg (@deltags) {
1349 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1351 $project->_set_changed;
1352 $project->_set_forkchange;
1353 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1359 @ARGV >= 2 or die_usage;
1360 my $project = get_project_harder(shift @ARGV);
1361 my $ctags = join(" ", @ARGV);
1362 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1363 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1364 my $oldmask = umask();
1365 umask($oldmask & ~0060);
1367 foreach (split(/[\s,]+/, $ctags)) {
1368 ++$changed if $project->add_ctag($_, 1);
1371 $project->_set_changed;
1372 $project->_set_forkchange;
1375 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1376 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1380 sub _get_random_val {
1385 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1392 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1394 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1395 @ARGV == 1 or die_usage;
1396 my $project = get_project_harder($ARGV[0]);
1397 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1398 if $project->is_password_locked;
1401 if ($random eq "random") {
1402 die "refusing to set random password without --force\n" unless $force;
1403 $rmsg = "set to random value";
1404 $newpw = _get_random_val($project);
1406 die "refusing to set password hash to '$random' without --force\n" unless $force;
1407 $rmsg = "hash set to '$random'";
1413 print "Changing admin password for project $ARGV[0]\n";
1414 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1415 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1416 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1417 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1418 "the admin passwords you have entered do not match each other.\n";
1422 defined($newpw) or die "missing new password on STDIN\n";
1426 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1427 my $old = $project->{crypt};
1428 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1429 if (defined($old) && $old eq $project->{crypt}) {
1430 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1432 # Avoid touching anything other than the password hash
1433 $project->_group_update;
1434 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1440 @ARGV == 1 or die_usage;
1441 my $project = get_project_harder($ARGV[0]);
1442 my $pwhash = $project->{crypt};
1443 defined($pwhash) or $pwhash = "";
1444 if ($pwhash eq "") {
1445 warn $project->{name}, ": no password required\n" unless $quiet;
1448 if ($project->is_password_locked) {
1449 warn $project->{name}, ": password is locked\n" unless $quiet;
1454 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1455 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1458 defined($checkpw) or die "missing admin password on STDIN\n";
1461 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1462 warn "password check failure\n" unless $quiet;
1465 warn "admin password match\n" unless $quiet;
1470 my ($force, $auto, $redelta, $recompress, $aggressive);
1471 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1472 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force,
1473 recompress => \$recompress, "no-reuse-object" => $recompress,
1474 aggressive => \$aggressive);
1475 $aggressive and $force = $redelta = 1;
1476 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1477 @ARGV or die "Please give project name on command line.\n";
1478 @ARGV == 1 or die_usage;
1479 my $project = get_project_harder($ARGV[0]);
1480 delete $ENV{show_progress};
1481 delete $ENV{force_gc};
1482 $quiet or $ENV{"show_progress"} = 1;
1483 $force and $ENV{"force_gc"} = 1;
1484 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1485 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1487 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1488 $redelta && !$recompress and push(@args, "-f");
1489 $recompress and push(@args, "-F");
1490 my $lastgc = $project->{lastgc};
1491 system({$args[0]} @args) != 0 and return 1;
1492 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1494 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1496 system({$args[0]} @args) != 0 and return 1;
1503 my ($force, $summary);
1504 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1505 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1506 @ARGV or die "Please give project name on command line.\n";
1507 @ARGV == 1 or die_usage
;
1508 my $project = get_project_harder
($ARGV[0]);
1509 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1510 delete $ENV{show_progress
};
1511 delete $ENV{force_update
};
1513 $ENV{"show_progress"} = 0;
1515 $ENV{"show_progress"} = ($summary ?
1 : 2);
1517 $force and $ENV{"force_update"} = 1;
1518 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1524 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1525 @ARGV or die "Please give project name on command line.\n";
1526 @ARGV == 1 or die_usage
;
1527 my $project = get_project_harder
($ARGV[0]);
1528 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1529 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1530 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1531 exit(255) unless $force;
1532 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1534 unlink($project->_clonefail_path);
1535 unlink($project->_clonelog_path);
1536 recreate_file
($project->_clonep_path);
1537 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1538 die "cannot connect to taskd.socket: $!\n";
1539 select((select($sock),$|=1)[0]);
1540 $sock->print("clone ".$project->{name
}."\n");
1541 # Just ignore reply, we are going to succeed anyway and the I/O
1542 # would apparently get quite hairy.
1546 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1552 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1553 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1554 my $project = get_project_harder
($ARGV[0]);
1555 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1556 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1558 warn "using invalid owner/email with --force\n" unless $quiet;
1560 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1561 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1563 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1565 my $old = $project->{email
};
1567 print "$old\n" if defined($old);
1570 if (defined($old) && $old eq $ARGV[1]) {
1571 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1573 # Avoid touching anything other than "gitweb.owner"
1574 $project->_property_fput("email", $ARGV[1]);
1575 $project->_update_index;
1576 $project->_set_changed;
1577 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1584 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1585 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1586 my $project = get_project_harder
(shift @ARGV);
1587 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1588 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1590 warn "using invalid description with --force\n" unless $quiet;
1592 my $desc = clean_desc
(join(" ", @ARGV));
1593 if (@ARGV && length($desc) > 1024) {
1594 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1596 warn "using longer than 1024 char description with --force\n" unless $quiet;
1598 my $old = $project->{desc
};
1600 print "$old\n" if defined($old);
1603 if (defined($old) && $old eq $desc) {
1604 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1606 # Avoid touching anything other than description file
1607 $project->_property_fput("desc", $desc);
1608 $project->_set_changed;
1609 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1615 my ($force, $readmetype) = (0, undef);
1616 parse_options
(force
=> \
$force, ":type" => \
$readmetype, ":format" => \
$readmetype);
1617 @ARGV == 1 && defined($readmetype) and push(@ARGV, undef);
1618 @ARGV == 2 || (@ARGV == 1 && !$force && !defined($readmetype) && !$setopt) or die_usage
;
1619 defined($readmetype) and $readmetype = Girocco
::Project
::_normalize_rmtype
($readmetype,1);
1620 defined($readmetype) && !$readmetype and die_usage
;
1621 my $project = get_project_harder
($ARGV[0]);
1622 my $old = $project->{READMEDATA
};
1624 chomp $old if defined($old);
1625 print "$old\n" if defined($old) && $old ne "";
1628 $readmetype or $readmetype = $project->{rmtype
};
1629 my ($new, $raw, $newname);
1631 if (!defined($ARGV[1])) {
1633 $newname = "original README data";
1634 $readmetype ne $project->{rmtype
} && $new ne "" and $raw = 1;
1635 } elsif ($ARGV[1] eq "-") {
1639 $newname = "contents of <STDIN>";
1640 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1642 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1643 $new = "<!-- suppress -->";
1647 die "missing filename for README\n" unless $fn ne "";
1648 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1649 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1654 $newname = "contents of \"$fn\"";
1656 defined($new) or $new = '';
1657 my $origrmtype = $project->{rmtype
};
1658 $project->{rmtype
} = $readmetype;
1659 $project->{READMEDATA
} = to_utf8
($new, 1);
1660 $project->_cleanup_readme;
1661 if (length($project->{READMEDATA
}) > 8192) {
1662 die "readme greater than 8192 chars is too long (use --force to override)\n"
1664 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1667 my ($cnt, $err) = $project->_lint_readme(0);
1669 my $msg = "README: $cnt error";
1670 $msg .= "s" unless $cnt == 1;
1671 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1672 unless $force && $quiet;
1673 exit(255) unless $force && $project->{rmtype
} eq 'HTML';
1674 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1675 $project->{README
} = $project->{READMEDATA
};
1678 if (defined($old) && $old eq $project->{READMEDATA
} && $readmetype eq $origrmtype && !$force) {
1679 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1681 # Avoid touching anything other than README.html file
1682 $project->_property_fput("READMEDATA", $project->{READMEDATA
}, 1);
1683 $project->_property_fput("README", $project->{README
});
1684 $project->_property_fput("rmtype", $readmetype) if $readmetype ne $origrmtype;
1685 $project->_set_changed;
1686 my $desc = get_readme_desc
($project->{README
});
1688 $newname .= " ($desc)";
1692 warn $project->{name
}, ": README $readmetype format updated to $newname\n" unless $quiet;
1698 my ($proj, $newhead) = @_;
1699 my %okheads = map({($_ => 1)} $proj->get_heads);
1700 exists($okheads{$newhead});
1704 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1705 my $project = get_project_harder
($ARGV[0]);
1706 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1707 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1709 my $old = $project->{HEAD
};
1711 print "$old\n" if defined($old);
1714 if (defined($old) && $old eq $ARGV[1]) {
1715 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1717 # Avoid touching anything other than the HEAD symref
1718 $project->set_HEAD($ARGV[1]);
1719 $project->_set_changed;
1720 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1727 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1728 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1729 my $project = get_project_harder
($ARGV[0]);
1730 my $projconfig = read_config_file_hash
($project->{path
}."/config");
1731 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
1732 my $rghp = realpath
($ghp);
1733 my $lhp = $project->{path
}."/hooks";
1734 my $rlhp = realpath
($lhp);
1737 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
1738 $ahp = $projconfig->{"core.hookspath"};
1739 $rahp = realpath
($ahp);
1742 if (defined($rahp) && $rahp ne "") {
1743 if ($rahp eq $rghp) {
1744 my $nc = ($ahp eq $ghp ?
"" : " non-canonical");
1745 printf "%s \t(global%s)\n", $ahp, $nc;
1746 } elsif ($rahp eq $rlhp) {
1747 my $nc = ($ahp eq $lhp ?
"" : " non-canonical");
1748 printf "%s \t(local%s)\n", $ahp, $nc;
1749 } elsif ($rahp ne $ahp) {
1750 print "$ahp \t($rahp)\n";
1754 } elsif ($ahp ne "") {
1755 print "$ahp \t(non-existent)\n";
1760 if (lc($shp) eq "global") {
1762 } elsif (lc($shp) eq "local") {
1764 } elsif (substr($shp, 0, 2) eq "~/") {
1765 $shp = $ENV{"HOME"}.substr($shp,1);
1766 } elsif ($shp =~ m
,^~([a
-zA
-Z_
][a
-zA
-Z_0
-9]*)((?
:/.*)?
)$,) {
1768 my $hd = (getpwnam($1))[7];
1769 $shp = $hd . $sfx if defined($hd) && $hd ne "" && $hd ne "/" && -d
$hd;
1771 $shp ne "" && -d
$shp or die "no such directory: $ARGV[1]\n";
1772 my $rshp = realpath
($shp);
1773 defined($rshp) && $rshp ne "" or die "could not realpath: $ARGV[1]\n";
1774 $rshp =~ m
,^/[^/], or die "invalid hookspath: $rshp\n";
1775 die "refusing to switch from current non-global hookspath without --force\n"
1776 if !$force && defined($rahp) && $rahp ne "" && $rahp ne $rghp && $rshp ne $rahp;
1777 if (!$force && defined($rahp) && $rahp ne "") {
1778 if ($rshp eq $rahp && ($ahp eq $ghp || $ahp eq $lhp)) {
1779 warn $project->{name
}, ": skipping update of hookspath to same effective value\n" unless $quiet;
1783 $rshp = $ghp if $rshp eq $rghp;
1784 $rshp = $lhp if $rshp eq $rlhp;
1785 if ($rshp eq $ahp) {
1786 warn $project->{name
}, ": skipping update of hookspath to same value\n" unless $quiet;
1789 die "refusing to set neither local nor global hookspath without --force\n"
1790 if !$force && $rshp ne $ghp && $rshp ne $lhp;
1791 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1792 'config', "core.hookspath", $rshp);
1793 my $newval = '"'.$rshp.'"';
1794 $newval = "global" if $rshp eq $ghp;
1795 $newval = "local" if $rshp eq $lhp;
1796 warn $project->{name
}, ": hookspath set to $newval\n" unless $quiet;
1812 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1813 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1814 my $project = get_project_harder
($ARGV[0]);
1815 if (!exists($boolfields{$ARGV[1]})) {
1816 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1818 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1819 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1821 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1823 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1824 die "invalid boolean value: \"$ARGV[2]\"\n";
1826 my $bool = clean_bool
($ARGV[2]);
1827 my $old = $project->{$ARGV[1]};
1829 print "$old\n" if defined($old);
1832 if (defined($old) && $old eq $bool) {
1833 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1835 # Avoid touching anything other than $ARGV[1] field
1836 $project->_property_fput($ARGV[1], $bool);
1837 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1842 sub cmd_setjsontype
{
1843 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1844 my $project = get_project_harder
($ARGV[0]);
1847 my $jt = lc($ARGV[1]);
1848 index($jt, "/") >= 0 or $jt = "application/".$jt;
1849 $jt eq 'application/x-www-form-urlencoded' ||
1850 $jt eq 'application/json' or
1851 die "invalid jsontype value: \"$ARGV[1]\"\n";
1854 my $old = $project->{jsontype
};
1856 print "$old\n" if defined($old);
1859 if (defined($old) && $old eq $jsontype) {
1860 warn $project->{name
}, ": skipping update of jsontype to same value\n" unless $quiet;
1862 # Avoid touching anything other than jsontype field
1863 $project->_property_fput('jsontype', $jsontype);
1864 warn $project->{name
}, ": jsontype updated to $jsontype\n" unless $quiet;
1869 sub cmd_setjsonsecret
{
1870 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1871 my $project = get_project_harder
($ARGV[0]);
1875 $js =~ s/^\s+//; $js =~ s/\s+$//;
1878 my $old = $project->{jsonsecret
};
1880 print "$old\n" if defined($old);
1883 if (defined($old) && $old eq $jsonsecret) {
1884 warn $project->{name
}, ": skipping update of jsonsecret to same value\n" unless $quiet;
1886 # Avoid touching anything other than jsonsecret field
1887 $project->_property_fput('jsonsecret', $jsonsecret);
1888 warn $project->{name
}, ": jsonsecret updated to \"$jsonsecret\"\n" unless $quiet;
1893 sub cmd_setautogchack
{
1894 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1895 my $project = get_project_harder
($ARGV[0]);
1896 my $aghok = $Girocco::Config
::autogchack
&&
1897 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1898 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1900 print "$old\n" if $aghok;
1904 if (lc($ARGV[1]) eq "unset") {
1907 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1908 $bool = clean_bool
($ARGV[1]);
1911 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1912 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1914 if ($old eq $bool) {
1915 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1917 if ($bool eq "unset") {
1918 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1919 'config', '--unset', "girocco.autogchack");
1921 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1922 'config', '--bool', "girocco.autogchack", $bool);
1925 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1930 my ($url, $type) = @_;
1931 $type ne 'baseurl' and return valid_web_url
($url);
1932 valid_repo_url
($url) or return 0;
1933 if ($Girocco::Config
::restrict_mirror_hosts
) {
1934 my $mh = extract_url_hostname
($url);
1935 is_dns_hostname
($mh) or return 0;
1936 !is_our_hostname
($mh) or return 0;
1944 baseurl
=> ["url" , 1],
1945 homepage
=> ["hp" , 0],
1946 notifyjson
=> ["notifyjson", 0],
1952 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1953 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1954 my $project = get_project_harder
($ARGV[0]);
1955 if (!exists($urlfields{$ARGV[1]})) {
1956 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1958 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1959 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1961 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1963 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1964 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1966 warn "using invalid URL with --force\n" unless $quiet;
1968 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1970 print "$old\n" if defined($old);
1973 if (defined($old) && $old eq $ARGV[2]) {
1974 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1976 # Avoid touching anything other than $ARGV[1]'s field
1977 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1978 if ($ARGV[1] eq "baseurl") {
1979 $project->{url
} = $ARGV[2];
1980 $project->_set_bangagain;
1982 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1983 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1998 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1999 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
2000 my $project = get_project_harder
(shift @ARGV);
2001 my $field = shift @ARGV;
2002 if (!exists($msgsfields{$field})) {
2003 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
2005 if (@ARGV && !valid_addrlist
(@ARGV)) {
2006 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
2008 warn "using invalid email address list with --force\n" unless $quiet;
2010 my $old = $project->{$field};
2012 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
2015 my $newlist = clean_addrlist
(join(" ",@ARGV));
2016 if (defined($old) && $old eq $newlist) {
2017 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
2019 # Avoid touching anything other than $field's field
2020 $project->_property_fput($field, $newlist);
2021 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
2028 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
2029 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
2030 my $project = get_project_harder
(shift @ARGV);
2031 my $projname = $project->{name
};
2032 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
2035 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
2036 die "refusing to set empty users list without --force\n" unless @newusers || $force;
2038 return 0 if !@ARGV && $project->{mirror
};
2039 my $oldusers = $project->{users
};
2040 if ($oldusers && ref($oldusers) eq "ARRAY") {
2041 $oldusers = join("\n", @
$oldusers);
2046 print "$oldusers\n" if $oldusers ne "";
2049 if ($oldusers eq join("\n", @newusers)) {
2050 warn "$projname: skipping update of users list to same value\n" unless $quiet;
2052 # Avoid touching anything other than the users list
2053 $project->{users
} = \
@newusers;
2054 $project->_update_users;
2055 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
2063 owner
=> [\
&cmd_setowner
, 0],
2064 desc
=> [\
&cmd_setdesc
, 0],
2065 description
=> [\
&cmd_setdesc
, 0],
2066 readme
=> [\
&cmd_setreadme
, 0],
2067 head
=> [\
&cmd_sethead
, 0],
2068 HEAD
=> [\
&cmd_sethead
, 0],
2069 hooks
=> [\
&cmd_sethooks
, 0],
2070 hookspath
=> [\
&cmd_sethooks
, 0],
2071 cleanmirror
=> [\
&cmd_setbool
, 1],
2072 reverseorder
=> [\
&cmd_setbool
, 1],
2073 summaryonly
=> [\
&cmd_setbool
, 1],
2074 statusupdates
=> [\
&cmd_setbool
, 1],
2075 autogchack
=> [\
&cmd_setautogchack
, 0],
2076 baseurl
=> [\
&cmd_seturl
, 1],
2077 homepage
=> [\
&cmd_seturl
, 1],
2078 notifyjson
=> [\
&cmd_seturl
, 1],
2079 jsontype
=> [\
&cmd_setjsontype
, 0],
2080 jsonsecret
=> [\
&cmd_setjsonsecret
, 0],
2081 notifymail
=> [\
&cmd_setmsgs
, 1],
2082 notifytag
=> [\
&cmd_setmsgs
, 1],
2083 users
=> [\
&cmd_setusers
, 0],
2090 push(@newargs, shift) if @_ && $_[0] eq '--force';
2092 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
2093 push(@newargs, shift);
2094 shift unless ${$fieldnames{$field}}[1];
2096 diename
(($setopt ?
"set " : "get ") . $field);
2098 &{${$fieldnames{$field}}[0]}(@ARGV);
2113 create
=> \
&cmd_create
,
2114 adopt
=> \
&cmd_adopt
,
2115 remove
=> \
&cmd_remove
,
2116 trash
=> \
&cmd_remove
,
2117 delete => \
&cmd_remove
,
2118 prune
=> \
&cmd_prune
,
2120 verify
=> \
&cmd_verify
,
2122 listheads
=> \
&cmd_listheads
,
2123 listtags
=> \
&cmd_listtags
,
2124 listctags
=> \
&cmd_listtags
,
2125 deltags
=> \
&cmd_deltags
,
2126 delctags
=> \
&cmd_deltags
,
2127 addtags
=> \
&cmd_addtags
,
2128 addctags
=> \
&cmd_addtags
,
2129 chpass
=> \
&cmd_chpass
,
2130 checkpw
=> \
&cmd_checkpw
,
2132 update
=> \
&cmd_update
,
2133 remirror
=> \
&cmd_remirror
,
2134 setowner
=> \
&cmd_setowner
,
2135 setdesc
=> \
&cmd_setdesc
,
2136 setdescription
=> \
&cmd_setdesc
,
2137 setreadme
=> \
&cmd_setreadme
,
2138 sethead
=> \
&cmd_sethead
,
2139 sethooks
=> \
&cmd_sethooks
,
2140 sethookspath
=> \
&cmd_sethooks
,
2141 setbool
=> \
&cmd_setbool
,
2142 setboolean
=> \
&cmd_setbool
,
2143 setflag
=> \
&cmd_setbool
,
2144 setautogchack
=> \
&cmd_setautogchack
,
2145 seturl
=> \
&cmd_seturl
,
2146 setjsontype
=> \
&cmd_setjsontype
,
2147 setjsonsecret
=> \
&cmd_setjsonsecret
,
2148 setmsgs
=> \
&cmd_setmsgs
,
2149 setusers
=> \
&cmd_setusers
,
2155 BEGIN { %nopager = (
2156 # 1 => pager never allowed
2157 # -1 => pager defaults to off instead of on
2175 setdescription
=> -1,
2183 setautogchack
=> -1,
2186 setjsonsecret
=> -1,
2196 my $bn = basename
($0);
2197 setup_pager_stdout
($usepager);
2198 printf "%s version %s\n\n", $bn, $VERSION;
2199 if (defined($cmd) && $cmd ne '') {
2200 $cmd =~ s/^set(?=[a-zA-Z])//i;
2202 my ($lastmt, $incmd);
2203 foreach (split('\n', sprintf($help, $bn))) {
2204 $lastmt || $incmd or $lastmt = /^\s*$/, next;
2205 $incmd = 1 if $lastmt && /^\s*(?:\[?set\]?)?$cmd\s/;
2206 last if $incmd && /^\s*$/;
2207 $incmd and $cmdhelp .= $_ . "\n";
2210 print $cmdhelp and exit 0 if $cmdhelp;
2219 shift, $quiet=1, redo if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
2220 shift, $usepager=1, redo if @ARGV && $ARGV[0] =~ /^(?:-p|--pager|--paginate)$/i;
2221 shift, $usepager=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-pager|--no-paginate)$/i;
2223 dohelp
($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
2224 my $command = shift;
2227 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
2229 $command = "set" . $command;
2231 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
2232 dohelp
($command) if @ARGV && ($ARGV[0] =~ /^(?:-h|-?-help)$/i ||
2233 $ARGV[0] =~ /^help$/i && !Girocco
::Project
::does_exist
("help",1));
2234 $nopager{$command} && $nopager{$command} > 0 and $usepager = 0;
2235 my $pgdfltoff = $nopager{$command} && $nopager{$command} < 0 ?
1 : 0;
2236 setup_pager_stdout
($usepager, $pgdfltoff);
2237 &{$commands{$command}}(@ARGV);