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.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 [<global option>...] <command> <options>
35 -q | --quiet suppress warning messages
36 -p | --pager force output to be paginated
37 --no-pager never paginate output
40 show full help or just for <command> if given
42 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
43 list all projects (default is --sort=lcname)
44 limit to project names matching <regex> if given
45 match <regex> against owner instead of project name with --owner
47 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
48 create new project <project> (prompted)
50 --no-alternates skip setup of objects/info/alternates
51 --orphan allow creation of subproject w/o a parent
52 -p use mkdir -p during --orphan creation
53 --no-password set password crypt to invalid value "unknown"
54 --no-owner leave the gitweb.owner config unset
55 --mirror=<url> create a mirror from <url>
56 --full-mirror mirror all refs
57 --push[=<list>] create a push project
58 --desc=<string> specify project description w/o prompt
59 --homepage=<url> specify project homepage URL w/o prompt
60 --defaults do no interactive prompting at all
61 Using --no-password skips the prompts for password, using
62 --no-owner skips the prompt for owner and using --mirror=<url>
63 or --push[=<list>] skips the prompts for mirror URL and
64 heads-only and push users. With --defaults if neither
65 --mirror=<url> nor --push[=<list>] is given then --push will
66 be implied. Using --desc=<string> will force a specific
67 description (including an empty string) and skip the prompt for
68 it. Otherwise a non-empty default description will always be
69 supplied in lieu of an empty or omitted description.
71 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
72 adopt project <project>
73 type of project is guessed if --type=<type> omitted
74 <users> is same as <newuserslist> for setusers command
76 --dry-run do all the checks but don't perform adoption
77 --verbose show project info dump (useful with --dry-run)
78 --no-users no push users at all (<users> must be omitted)
79 --no-owner leave the gitweb.owner config totally unchanged
80 --owner=<val> set the gitweb.owner config to <val>
81 Both --no-owner and --owner=<val> may NOT be given, with neither
82 take owner from preexisting gitweb.owner else use admin setting.
83 For mirrors <users> is ignored otherwise if no <users> and no
84 --no-users option the push users list will consist of the single
85 user name matching the owner or empty if none or more than one.
86 With --dry-run <project> can be an absolute path to a git dir.
88 remove [--force] [--really-delete] [--keep-forks] <project>
89 remove project <project>
90 do not move to _recyclebin with --really-delete (just rm -rf)
91 remove projects with forks (by keeping forks) using --keep-forks
93 prune [--quiet] (--force | --dry-run) [<project>...]
94 check to see if any projects (default is all projects) are
95 missing the associated project directory on disk.
96 Requires either --force or --dry-run option to operate.
97 With --dry-run only show what would be done.
98 With --prune actually remove any extraneous project(s).
99 With --dry-run exit code is non-zero if any action needed.
100 With --quiet, suppress output message, if any.
103 show project <project>
105 urls [--push] <project>
106 show available fetch/push URLs for <project>
107 Note that this does NOT include non-Git protocol URLs such
108 as any home page or any upstream URL for a mirror project --
109 those are all accessible via the "show" command.
110 The URLs shown are those that would be shown by gitweb.cgi.
111 With --push only show push urls (mirrors have no push urls)
114 list all available heads for <project> and indicate current head
116 listtags [--verbose] <project>
117 list all ctags on project <project>
119 deltags <project> [-i] <tagstodel>
120 remove any ctags on project <project> present in <tagstodel>
121 <tagstodel> is space or comma separated list of tags to remove
122 with -i match against <tagstodel> without regard to letter case
124 addtags <project> <tagstoadd>
125 add ctags to project <project>
126 <tagstoadd> is space or comma separated list of tags to add
128 chpass [--force] <project> [random | unknown]
129 change project <project> password (prompted)
130 with "random" set to random password
131 with "unknown" set password hash to invalid value "unknown"
134 check project <project> password for a match (prompted)
136 gc [--force | --auto] [--redelta | --recompress] <project>
137 run the gc.sh script on project <project>
138 with --auto let the gc.sh script decide what to do
139 with --force cause a full gc to take place (force_gc=1)
140 with neither --auto nor --force do a mini or if needed a full gc
141 (in other words just touch .needsgc and run gc.sh)
142 with --redelta a full gc will use pack-objects --no-reuse-delta
143 with --recompress a full gc uses pack-objects --no-reuse-object
144 (--no-reuse-delta and --no-reuse-object are accepted as aliases)
145 with --aggressive activate the --force and --redelta options
146 unless the global --quiet option is given show_progress=1 is used
148 update [--force] [--quiet | --summary] <project>
149 run the update.sh script on project <project>
150 with --force cause a fetch to always take place (force_update=1)
151 with --quiet only show errors (show_progress is left unset)
152 with --summary show progress and ref summary (show_progress=1)
153 with neither --quiet nor --summary show it all (show_progress=2)
155 remirror [--force] <project>
156 initiate a remirror of project <project>
158 [set]owner [--force] <project> <newowner>
159 set project <project> owner to <newowner>
160 without "set" and only 1 arg, just show current project owner
162 [set]desc [--force] <project> <newdesc>
163 set project <project> description to <newdesc>
164 without "set" and only 1 arg, just show current project desc
166 [set]readme [--force] [--format=<readmetype>] <project> [<newsetting>]
167 set project <project> readme to <newsetting>
168 <readmetype> is markdown|plain|html (default is no change)
169 <newsetting> is automatic|suppressed|-|[@]filename
170 with "set" <readmetype> and/or <newsetting> is required
171 without "set" and only 2 args, just show current readme setting
173 [set]head <project> <newhead>
174 set project <project> HEAD symbolic ref to <newhead>
175 without "set" and only 1 arg, just show current project HEAD
177 [set]bool [--force] <project> <flagname> <boolvalue>
178 set project <project> boolean <flagname> to <boolvalue>
179 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
180 without "set" and only 2 args, just show current flag value
182 [set]hooks [--force] <project> local | global | <path>
183 set project <project> hookspath to local, global or <path>
184 without "set" and only 1 arg, just show current hookspath
186 [set]autogchack <project> <boolvalue> | unset
187 set project <project> autogchack to <boolvalue> or "unset" it
188 without "set" just show current autogchack setting if enabled
189 with "set" autogchack must be enabled in Config.pm for the
190 type of project and maintain-auto-gc-hack.sh is always run
192 [set]url [--force] <project> <urlname> <newurlvalue>
193 set project <project> url <urlname> to <newurlvalue>
194 <urlname> is baseurl|homepage|notifyjson
195 without "set" and only 2 args, just show current url value
197 [set]msgs [--force] <project> <msgsname> <eaddrlist>
198 set project <project> msgs <msgsname> to <addrlist>
199 <msgsname> is notifymail|notifytag
200 <eaddrlist> is space or comma separated list of email addresses
201 without "set" and only 2 args, just show current msgs value
203 [set]users [--force] <project> <newuserslist>
204 set push project <project> users list to <newuserslist>
205 <newuserslist> is space or comma separated list of user names
206 without "set" and only 1 arg, just show current users list
208 [set]jsontype <project> <newjsontype>
209 set project <project> JSON Content-Type to <newjsontype>
210 <newjsontype> is x-www-form-urlencoded or json
211 without "set" and only 1 arg, just show current jsontype
213 [set]jsonsecret <project> <newjsonsecret>
214 set project <project> JSON secret to <newjsonsecret>
215 <newjsonsecret> is a string (empty string disables signatures)
216 without "set" and only 1 arg, just show current jsonsecret
218 get <project> <fieldname>
219 show project <project> field <fieldname>
220 <fieldname> is owner|desc|readme|head|hooks|users|jsontype
221 or jsonsecret|<flagname>|autogchack|<urlname>|<msgsname>
223 set [--force] <project> <fieldname> <newfieldvalue>
224 set project <project> field <fieldname> to <newfieldvalue>
225 <fieldname> same as for get
226 <newfieldvalue> same as for corresponding set... command
233 my $sub = shift || diename
;
235 die "Invalid arguments to $sub command -- try \"help\"\n";
237 die "Invalid arguments -- try \"help\"\n";
243 defined($rm) or $rm = '';
244 return "length " . length($rm);
247 sub get_readme_desc
{
249 defined($rm) or $rm = '';
252 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
254 return $test eq '' ?
"suppressed" : "length " . length($rm);
260 sub get_ctag_counts
{
264 foreach ($project->get_ctag_names) {
267 if (open $ct, '<', $project->{path
}."/ctags/$_") {
270 defined $count or $count = '';
272 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
278 push(@ctags, $_."(".$val.")");
281 push(@ctags, [$_, $val]) if $val;
287 sub get_clean_project
{
288 my $project = get_project
(@_);
289 delete $project->{loaded
};
290 delete $project->{base_path
};
291 delete $project->{ccrypt
};
292 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
293 $project->{owner
} = $project->{email
}; delete $project->{email
};
294 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
295 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
296 if (defined($project->{path
}) && $project->{path
} ne "") {
297 my $rp = realpath
($project->{path
});
298 defined($rp) && $rp ne "" and $project->{realpath
} = $rp;
299 if (-f
"$rp/objects/info/packs") {
300 my $ipt = (stat _
)[9];
301 defined($ipt) and $project->{infopackstime
} =
302 strftime
("%Y-%m-%d %H:%M:%S %z", localtime($ipt));
305 my $owner = $project->{owner
};
308 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
309 $project->{owner_users
} = \
@owner_users if @owner_users;
311 my $projname = $project->{name
};
312 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
313 $project->{has_forks
} = 1 if @forks;
314 $project->{has_alternates
} = 1 if $project->has_alternates;
315 my @bundles = $project->bundles;
316 for (my $i = 0; $i < @bundles; ++$i) {
317 my $secs = $bundles[$i]->[0];
318 $bundles[$i]->[0] = strftime
("%Y-%m-%d %H:%M:%S %z", localtime($secs));
319 my $sz = $bundles[$i]->[2];
320 1 while $sz =~ s/(?<=\d)(\d{3})(?:,|$)/,$1/g;
321 $bundles[$i]->[2] = $sz;
323 delete $project->{bundles
};
324 $project->{bundles
} = \
@bundles if @bundles;
325 $project->{mirror
} = 0 unless $project->{mirror
};
326 $project->{is_empty
} = 1 if $project->is_empty;
327 delete $project->{showpush
} unless $project->{showpush
};
328 delete $project->{users
} if $project->{mirror
};
329 delete $project->{baseurl
} unless $project->{mirror
};
330 delete $project->{banged
} unless $project->{mirror
};
331 delete $project->{lastrefresh
} unless $project->{mirror
};
332 delete $project->{cleanmirror
} unless $project->{mirror
};
333 delete $project->{statusupdates
} unless $project->{mirror
};
334 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
335 unless ($project->{banged
}) {
336 delete $project->{bangcount
};
337 delete $project->{bangfirstfail
};
338 delete $project->{bangmessagesent
};
340 my $projhook = $project->_has_notifyhook;
341 if (defined($projhook) && $projhook ne "") {
342 $project->{notifyhook
} = $projhook;
344 delete $project->{notifyhook
};
346 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
347 $project->{READMEDATA
} = get_readme_len
($project->{READMEDATA
}) if exists($project->{READMEDATA
});
348 my @tags = get_ctag_counts
($project, 1);
349 $project->{tags
} = \
@tags if @tags;
350 my $projconfig = read_config_file_hash
($project->{path
}."/config");
351 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
352 my $ahp = $projconfig->{"core.hookspath"};
353 my $rahp = realpath
($ahp);
354 my $lhp = $project->{path
}."/hooks";
355 my $rlhp = realpath
($lhp);
356 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
357 my $rghp = realpath
($ghp);
358 $project->{has_local_hooks
} = 1 if
359 defined($rahp) && defined($rlhp) && $rahp eq $rlhp;
360 $project->{has_global_hooks
} = 1 if
361 defined($rahp) && defined($rghp) && $rahp eq $rghp;
362 $project->{hookspath
} = $ahp unless $ahp eq $lhp || $ahp eq $ghp;
370 foreach (split(/[,\s]+/, $_[0])) {
372 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
374 return join(($_[1]||","), @newlist);
378 my $cleaned = clean_addrlist
(join(" ", @_));
379 return 1 if $cleaned eq "";
380 valid_email_multi
($cleaned) && length($cleaned) <= 512;
384 my ($userlist, $force, $nodie) = @_;
388 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
389 my %users = map({($$_[1] => $_)} get_all_users
);
390 foreach (split(/[\s,]+/, $userlist)) {
391 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
392 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
395 if (Girocco
::User
::does_exist
($_, 1)) {
397 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
400 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
405 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
407 die if $badlist && !$nodie;
411 sub is_default_desc
{
412 # "Unnamed repository; edit this file 'description' to name the repository."
413 # "Unnamed repository; edit this file to name it for gitweb."
415 return 0 unless defined($_);
416 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
422 return 0 if $test =~ /[\r\n]/;
423 $test =~ s/\s\s+/ /g;
431 defined($desc) or $desc = '';
433 $desc = to_utf8
($desc, 1);
434 $desc =~ s/\s\s+/ /g;
441 Girocco
::CLIUtil
::_parse_options
(
443 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
451 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
452 name
=> sub {$$a[1] cmp $$b[1]},
453 gid
=> sub {$$a[3] <=> $$b[3]},
454 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
455 no => sub {$$a[0] <=> $$b[0]},
457 my $sortopt = 'lcname';
458 my ($verbose, $owner);
459 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
462 my $val = shift @ARGV;
463 $regex = qr
($val) or die "bad regex \"$val\"\n";
465 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
466 my $sortsub = $sortsub{$sortopt};
467 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
468 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
470 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
472 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
478 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
479 $ismirror, $desc, $fullmirror, $homepage);
481 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
482 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
483 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
484 ":description" => \
$desc, "full-mirror" => \
$fullmirror, ":homepage" => \
$homepage);
485 @ARGV == 1 or die_usage
;
486 !defined($pushusers) || defined($ispush) or $ispush = 1;
487 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
488 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
489 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
490 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
491 !$defaults || defined($nopasswd) or $nopasswd = 1;
492 !$defaults || defined($noowner) or $noowner = 1;
493 !defined($ispush) || defined($pushusers) or $pushusers = "";
494 my $projname = $ARGV[0];
495 $projname =~ s/\.git$//i;
496 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
497 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
498 warn "Refusing to create orphan project without --orphan\n"
499 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
500 warn "Required orphan parent directory does not exist (use -p): ",
501 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
502 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
503 die "Invalid project name: \"$projname\"\n";
505 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
506 my $newtype = $forkee ?
'fork' : 'project';
507 if (length($project) > 64) {
508 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
510 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
512 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
513 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
514 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
516 print "Enter settings for new project \"$projname\"\n" unless $defaults;
518 $settings{noalternates
} = $noalternates;
520 $settings{crypt} = "unknown";
522 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
523 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
524 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
525 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
526 "the admin passwords you have entered do not match each other.\n";
527 $settings{crypt} = scrypt_sha1
($np1);
531 $owner = prompt_or_die
("Owner/email name for project $projname");
532 unless (valid_email
($owner)) {
534 warn "Your email sure looks weird...?\n";
537 warn "Allowing invalid email with --force\n" unless $quiet;
539 if (length($owner) > 96) {
541 warn "Your email is longer than 96 characters. Do you really need that much?\n";
544 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
547 $settings{email
} = $owner;
549 my $checkmirror = sub {
550 my $checkurl = shift;
551 unless (valid_repo_url
($checkurl)) {
553 warn "Invalid mirror URL: \"$checkurl\"\n";
556 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
558 if ($Girocco::Config
::restrict_mirror_hosts
) {
559 my $mh = extract_url_hostname
($checkurl);
560 unless (is_dns_hostname
($mh)) {
562 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
565 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
567 if (is_our_hostname
($mh)) {
569 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
572 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
577 if ($ispush || $ismirror) {
578 !$ispush || $force || $Girocco::Config
::push or
579 die "Push projects are disabled, create a mirror (or use --force)\n";
580 !$ismirror || $force || $Girocco::Config
::mirror
or
581 die "Mirror projects are disabled, create a push project (or use --force)\n";
583 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
584 $baseurl = $ismirror;
585 $settings{url
} = $baseurl;
586 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
589 if ($pushusers !~ /^[\s,]*$/) {
590 eval {@newusers = validate_users
($pushusers, $force); 1;} or
591 die "Invalid --push user list\n";
593 $settings{users
} = \
@newusers;
595 } elsif ($force || $Girocco::Config
::mirror
) {{
596 if ($force || $Girocco::Config
::push) {
597 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
599 $baseurl = prompt_or_die
("URL to mirror from");
600 unless ($baseurl ne "") {
601 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
605 if ($baseurl ne "") {
606 &$checkmirror($baseurl) or redo;
607 $settings{url
} = $baseurl;
608 $settings{cleanmirror
} =
609 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
612 my $mirror = ($baseurl eq "") ?
0 : 1;
613 my $checkdesc = sub {
615 if (length($d) > 1024) {
617 warn "Short description length greater than 1024 characters!\n";
620 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
624 if (defined($desc)) {
625 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
626 $desc eq "" || &$checkdesc($desc) or
627 die "Invalid --desc description\n";
628 } elsif (!$defaults) {
629 $desc = prompt_or_die
("Short description", "");
630 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
631 $desc eq "" || &$checkdesc($desc) or redo;
632 $desc = undef if $desc eq "";
634 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
635 $settings{desc
} = $desc;
638 unless (valid_web_url
($hpurl)) {
640 warn "Invalid home page URL: \"$hpurl\"\n";
643 warn "Allowing invalid home page URL with --force\n" unless $quiet;
647 if (defined($homepage)) {
648 $homepage =~ s/^\s+//; $homepage =~ s/\s+$//;
649 $homepage eq "" || &$checkhp($homepage) or
650 die "Invalid --homepage URL\n";
651 } elsif (!$defaults) {
652 $homepage = prompt_or_die
("Home page URL", "");
653 $homepage =~ s/^\s+//; $homepage =~ s/\s+$//;
654 $homepage eq "" || &$checkhp($homepage) or redo;
655 $homepage = undef if $homepage eq "";
657 $settings{hp
} = $homepage;
660 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
661 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
663 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
666 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
669 $settings{notifyjson
} = $jsonurl;
670 my $commitaddrs = "";
672 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
673 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
675 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
678 warn "using invalid commit notify email address list with --force\n" unless $quiet;
681 $settings{notifymail
} = $commitaddrs;
682 $settings{reverseorder
} = 1;
683 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
684 if !$defaults && $commitaddrs ne "";
685 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
686 if !$defaults && $commitaddrs ne "";
689 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
690 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
692 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
695 warn "using invalid tag notify email address list with --force\n" unless $quiet;
698 $settings{notifytag
} = $tagaddrs;
699 if (!$mirror && !$ispush) {
702 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
703 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
705 $settings{users
} = \
@newusers;
707 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
708 or die "Girocco::Project->ghost call failed\n";
710 $newproj->{$k} = $v while ($k, $v) = each(%settings);
711 my $killowner = sub {
712 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
713 'config', '--unset', "gitweb.owner");
716 $newproj->premirror or die "Girocco::Project->premirror failed\n";
717 !$noowner or &$killowner;
718 $newproj->clone or die "Girocco::Project->clone failed\n";
719 warn "Project $projname created and cloning successfully initiated.\n"
722 $newproj->conjure or die "Girocco::Project->conjure failed\n";
723 !$noowner or &$killowner;
724 warn "New push project fork is empty due to use of --no-alternates\n"
725 if !$quiet && $projname =~ m
,/, && $noalternates;
726 warn "Project $projname successfully created.\n" unless $quiet;
733 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
734 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
738 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
739 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
740 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
741 @ARGV or die "Please give project name on command line.\n";
742 my $projname = shift @ARGV;
743 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
744 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
745 defined($type) or $type = "";
747 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
748 $projdir = realpath
($projname);
749 $projname = $projdir;
750 $projname =~ s/\.git$//i;
751 $projname =~ s
,/+$,,;
752 $projname =~ s
,^.*/,,;
753 $projname ne "" or $projname = $projdir;
755 $projname =~ s/\.git$//i;
756 $projname ne "" or die "Invalid project name \"\".\n";
757 unless (Girocco
::Project
::does_exist
($projname, 1)) {
758 Girocco
::Project
::valid_name
($projname, 1, 1)
759 or die "Invalid project name \"$projname\".\n";
760 die "No such project to adopt: $projname\n";
762 defined(Girocco
::Project
->load($projname))
763 and die "Project already known (no need to adopt): $projname\n";
764 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
765 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
767 my $config = read_config_file
($projdir . "/config");
769 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
770 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
771 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
772 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1)];
774 if (-e
"$projdir/description") {
775 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
781 defined $desc or $desc = "";
783 $desc = to_utf8
($desc, 1);
784 is_default_desc
($desc) and $desc = "";
785 if ($desc ne "" && !valid_desc
($desc)) {
786 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
788 warn "using invalid 'description' file contents with --force\n" unless $quiet;
790 $desc = clean_desc
($desc);
791 if (length($desc) > 1024) {
792 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
794 warn "using longer than 1024 char description with --force\n" unless $quiet;
800 my $origreadmedata = "";
801 my $readmetype = Girocco
::Project
::_normalize_rmtype
($config{"girocco.readmetype"},1);
802 if (-e
"$projdir/README.html") {
803 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
809 defined $readme or $readme = "";
810 $readme = to_utf8
($readme, 1);
811 $readme =~ s/\r\n?/\n/gs;
812 $readme =~ s/^\s+//s;
813 $readme =~ s/\s+$//s;
814 $readme eq "" or $readme .= "\n";
815 $origreadme = $readme;
816 if (-e
"$projdir/README.dat") {
817 open my $fd2, '<', "$projdir/README.dat" or die "Cannot open \"$projdir/README.dat\": $!\n";
820 $readmedata = <$fd2>;
823 defined $readmedata or $readmedata = "";
824 $readmedata = to_utf8
($readmedata, 1);
825 $readmedata =~ s/\r\n?/\n/gs;
826 $readmedata =~ s/^\s+//s;
827 $readmedata =~ s/\s+$//s;
828 $readmedata eq "" or $readmedata .= "\n";
829 $origreadmedata = $readmedata;
831 !$readmetype && length($readme) && !length($readmedata) and do {
832 # the old HTML format
833 $readmetype = 'HTML';
834 $readmedata = $readme;
836 if (length($readmedata) > 8192) {
837 die "readme greater than 8192 chars is too long (use --force to override)\n"
839 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
842 my $dummy = {READMEDATA
=> $readmedata, rmtype
=> $readmetype, name
=> $projname};
843 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
845 my $msg = "README: $cnt error";
846 $msg .= "s" unless $cnt == 1;
847 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
848 unless $force && $quiet;
849 exit(255) unless $force && $readmetype eq 'HTML';
850 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
852 $readme = $dummy->{README
};
856 $readmetype or $readmetype = Girocco
::Project
::_normalize_rmtype
(""); # use default type
857 # Inspect any remotes now
858 # Yes, Virginia, remote urls can be multi-valued
862 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
863 my ($name, $subkey) = ($1, $2);
864 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
865 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
866 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
867 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
868 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
870 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
871 # the remote names in a group are separated by runs of [ \t\n] characters
872 # remote names "", ".", ".." and any name starting with "/" are invalid
873 # a remote with no url or vcs setting is not considered valid
876 if (exists($config{"remotes
.default"})) {
877 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
878 next unless exists($remotes{$_});
879 my $rmt = $remotes{$_};
880 next if !exists($rmt->{url}) && !$rmt->{vcs};
888 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
889 next if $seenrmt{$1};
891 next unless exists($remotes{$1});
892 my $rmt = $remotes{$1};
893 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
897 my @needskip = (); # remotes that need skipDefaultUpdate set to true
900 my $foundfetchwithmirror = 0;
902 my $rmt = $remotes{$_};
903 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
904 next unless exists($rmt->{fetch});
906 ++$foundfetchwithmirror if $rmt->{mirror};
907 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
909 # if we have $foundvcs then we need to explicitly set fetch.prune to false
910 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
911 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
913 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
914 # if remote "origin
" exists we always pick up its first url or use ""
915 if (exists($remotes{origin})) {
916 my $rmt = $remotes{origin};
917 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
918 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
921 # get the first url of the @check remotes
923 my $rmt = $remotes{$_};
924 next unless exists($rmt->{url});
925 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
926 $baseurl = $rmt->{url}->[0];
930 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
932 # If we have $foundfetch we want to make a mirror but complain if
933 # we $foundfetchwithmirror as well unless we have --type=mirror.
934 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
935 # Warn if we need to set fetch.prune=false when making a mirror
936 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
937 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
938 # Warn if $usingall and any @needskip (and set them) if making a mirror
939 # Warn if making a mirror and $baseurl eq ""
940 # Warn if we have --type=mirror and !$foundfetch
943 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
944 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
945 if ($foundfetchwithmirror) {
946 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
947 "(Use
--type
=mirror to override
)\n"
948 unless $type eq "mirror
";
949 exit(255) unless $type eq "mirror
" || $dryrun;
950 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
951 unless $quiet || $type ne "mirror
";
953 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
954 if !$quiet && $neednoprune;
955 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
956 if !$quiet && $needfakeorigin;
957 if (!$usingall && @needskip) {
958 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
960 exit(255) unless $force || $dryrun;
961 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
962 unless $quiet || !$force;
964 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
965 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
967 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
968 if !$quiet && $foundfetch && !$foundfetchwithmirror;
971 if (!$noowner && !defined($owner)) {
973 $owner = $config{"gitweb
.owner
"};
974 if (!defined($owner) || $owner eq "") {
975 $owner = $Girocco::Config::admin;
976 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
979 if (!$nousers && !$makemirror && !defined($users)) {
980 # select user list for push project
981 my $findowner = $owner;
982 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
983 $findowner = lc($findowner) if defined($findowner);
984 my @owner_users = ();
985 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
986 if defined($findowner) && $findowner ne "";
987 defined($findowner) or $findowner = "";
988 if (@owner_users <= 1) {
989 $users = \@owner_users;
990 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
993 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
994 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
997 defined($users) or $users = [];
999 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
1000 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
1001 # and warn about preserving the setting)
1003 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
1004 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
1005 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
1006 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
1007 $config{"receive
.denydeletecurrent
"} ne "warn";
1009 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
1010 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
1011 if ($reflogactive || $reflogfiles) {
1012 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
1013 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
1014 exit(255) unless $force || $dryrun;
1015 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
1016 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
1019 return 0 if $dryrun && !$verbose;
1021 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
1022 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
1023 $newproj->{desc} = $desc;
1024 $newproj->{README} = $readme;
1025 $newproj->{READMEDATA} = $readmedata;
1026 $newproj->{rmtype} = $readmetype;
1027 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
1028 $newproj->{email} = $owner if defined($owner);
1029 $newproj->{users} = $users;
1030 $newproj->{crypt} = "unknown
";
1031 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
1032 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
1033 my $dummy = bless {}, "Girocco
::Project
";
1034 $dummy->{path} = "$projdir";
1035 $dummy->{configfilehash} = \%config;
1036 $dummy->_properties_load;
1037 delete $dummy->{origurl};
1038 foreach my $k (keys(%$dummy)) {
1039 $newproj->{$k} = $dummy->{$k}
1040 if exists($dummy->{$k}) && !exists($newproj->{$k});
1045 my %info = %$newproj;
1046 $info{README} = get_readme_desc($info{README}) if exists($info{README});
1047 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
1048 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1049 print $d->Dump([\%info], ['*'.$newproj->{name}]);
1051 return 0 if $dryrun;
1053 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
1055 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
1056 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
1057 if ($usingall && @needskip) {
1058 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
1062 # Write out any README.dat/README.html changes before the actual Adoption
1063 # Otherwise they will get stepped on. The Girocco::Project::adopt function
1064 # does not know how to validate README.html during adoption like the above code does.
1065 if ($readmedata ne $origreadmedata) {
1066 open my $fd, '>', "$projdir/README.dat" or die "Cannot write \"$projdir/README
.dat
\": $!\n";
1067 print $fd $readmedata or die "Error writing
\"$projdir/README
.dat
\": $!\n";
1068 close $fd or die "Error closing
\"$projdir/README
.dat
\": $!\n";
1070 if ($readme ne $origreadme || ! -e "$projdir/README
.html
") {
1071 open my $fd, '>', "$projdir/README.html" or die "Cannot write \"$projdir/README
.html
\": $!\n";
1072 print $fd $readme or die "Error writing
\"$projdir/README
.html
\": $!\n";
1073 close $fd or die "Error closing
\"$projdir/README
.html
\": $!\n";
1075 git_config($projdir, "girocco
.rmtype
", $readmetype);
1077 # Perform the actual adoption
1078 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
1080 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
1081 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
1082 if git_bool($config{"receive
.denynonfastforwards
"});
1083 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
1084 if exists($config{"receive
.denydeletecurrent
"}) &&
1085 $config{"receive
.denydeletecurrent
"} ne "warn";
1086 git_config($projdir, "core
.logAllRefUpdates
", "true
")
1091 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
1093 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
1099 my ($force, $reallydel, $keepforks);
1100 parse_options(force => \$force, "really
-delete" => \$reallydel,
1101 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
1102 @ARGV or die "Please give project name on command line
.\n";
1103 @ARGV == 1 or die_usage;
1104 my $project = get_project($ARGV[0]);
1105 my $projname = $project->{name};
1106 my $isempty = !$project->{mirror} && $project->is_empty;
1107 if (!$project->{mirror} && !$isempty && $reallydel) {
1108 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
1109 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
1113 if ($project->has_forks) {
1114 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
1115 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
1116 # Run pseudo GC on that repository so that objects don't get lost within forks
1117 my $basedir = $Girocco::Config::basedir;
1118 my $projdir = $project->{path};
1119 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
1120 my $nogcrunning = sub {
1121 die "Error: GC appears to be currently running on $projname\n"
1122 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
1125 $removenogc = ! -e "$projdir/.nogc";
1126 recreate_file("$projdir/.nogc") if $removenogc;
1127 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
1128 delete $ENV{show_progress};
1129 $ENV{'show_progress
'} = 1 unless $quiet;
1132 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
1133 or die "Running pseudo GC on project $projname failed\n";
1137 if (!$project->{mirror} && !$isempty && !$reallydel) {
1138 $archived = $project->archive_and_delete;
1139 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1143 warn "Project '$projname' removed from $Girocco::Config::name" .
1144 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1145 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1150 my ($force, $dryrun);
1151 parse_options(force => \$force, "dry-run" => \$dryrun, "quiet" => \$quiet);
1152 ($force && !$dryrun) || (!$force && $dryrun) or die_usage;
1154 my %allprojs = map({($$_[0] => $_)} Girocco::Project::get_full_list_extended());
1155 my @allprojs = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%allprojs));
1157 @projs or @projs = @allprojs;
1158 my $bd = $Girocco::Config::reporoot.'/';
1161 !$seen{$_} && $allprojs{$_} && ${$allprojs{$_}}[2] >= 65536 or next;
1163 /^[a-zA-Z0-9]/ or next;
1164 my $pd = $bd . $_ . '.git
';
1166 warn "$_: no such directory: $pd\n" unless $quiet;
1169 warn "$_: exists but not directory: $pd\n" unless $quiet;
1173 warn "\n" if @remove && !$quiet;
1175 return 0 unless @remove;
1176 my $msg = "Would remove ".scalar(@remove). " project entr";
1177 $msg .= (@remove == 1 ? "y" : "ies");
1179 $msg .= join("", map("\t$_\n", @remove));
1180 print $msg unless $quiet;
1183 my $msg = "Removed ".scalar(@remove). " project entr";
1184 $msg .= (@remove == 1 ? "y" : "ies");
1186 $msg .= join("", map("\t$_\n", @remove));
1187 my %remove = map({$_ => 1} @remove);
1188 filedb_atomic_edit(jailed_file('/etc/group
'), sub {
1189 my ($name,undef,$gid) = split /:/;
1190 $gid =~ /^\d+$/ && $gid >= 65536 or return $_;
1191 $name =~ /^[a-zA-Z0-9]/ or return $_;
1192 !exists($remove{$name}) and return $_;
1194 print $msg unless $quiet;
1200 @ARGV == 1 or die_usage;
1201 my $project = get_clean_project($ARGV[0]);
1202 my %info = %$project;
1203 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1204 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1205 print $d->Dump([\%info], ['*'.$project->{name}]);
1211 parse_options("push" => \$pushonly);
1213 @ARGV == 1 or die_usage;
1214 my $project = get_project($ARGV[0]);
1215 my $suffix = "/".$project->{name}.".git";
1216 @Gitweb::Config::git_base_url_list = ();
1217 @Gitweb::Config::git_base_push_urls = ();
1218 @Gitweb::Config::git_base_mirror_urls = ();
1220 package Gitweb::Config;
1221 do $Girocco::Config::basedir."/gitweb/gitweb_config.perl";
1222 !$! or die "could not read gitweb_config.perl: $!\n";
1223 !$@ or die "could not parse gitweb_config.perl: $@\n";
1225 my @fetch_urls = ();
1231 ref($_) eq 'ARRAY
' or die "expected ARRAY ref";
1233 defined($u) && $u ne "" and
1234 push(@$array, $u.$suffix);
1235 } elsif (defined($_) && $_ ne "") {
1236 push(@$array, $_.$suffix);
1242 $items{$_} = 1 foreach @_;
1245 &$add_url(\@fetch_urls, @Gitweb::Config::git_base_url_list);
1246 if ($project->{mirror}) {
1247 &$add_url(\@fetch_urls, @Gitweb::Config::git_base_mirror_urls);
1249 &$add_url(\@push_urls, @Gitweb::Config::git_base_push_urls);
1253 push(@urls, &$uniq(@push_urls));
1255 push(@urls, &$uniq(@fetch_urls, @push_urls));
1257 print map "$_\n", @urls;
1262 @ARGV == 1 or die_usage;
1263 my $project = get_project($ARGV[0]);
1264 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1265 my $cur = $project->{HEAD};
1266 defined($cur) or $cur = '';
1268 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1269 defined($headhash) or $headhash = '';
1271 $headhash or $curmark = '!';
1273 my $mark = $_ eq $cur ? $curmark : ' ';
1281 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1282 @ARGV == 1 or die_usage;
1283 my $project = get_project($ARGV[0]);
1285 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1287 print map("$_\n", $project->get_ctag_names);
1294 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1295 @ARGV >= 2 or die_usage;
1296 my $project = get_project(shift @ARGV);
1299 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1301 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1305 my $ctags = join(" ", @ARGV);
1306 $ctags = lc($ctags) if $ic;
1307 foreach (split(/[\s,]+/, $ctags)) {
1308 next unless exists($curtags{$_});
1309 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1312 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1314 # Avoid touching anything other than the ctags
1315 foreach my $tg (@deltags) {
1316 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1318 $project->_set_changed;
1319 $project->_set_forkchange;
1320 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1326 @ARGV >= 2 or die_usage;
1327 my $project = get_project(shift @ARGV);
1328 my $ctags = join(" ", @ARGV);
1329 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1330 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1331 my $oldmask = umask();
1332 umask($oldmask & ~0060);
1334 foreach (split(/[\s,]+/, $ctags)) {
1335 ++$changed if $project->add_ctag($_, 1);
1338 $project->_set_changed;
1339 $project->_set_forkchange;
1342 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1343 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1347 sub _get_random_val {
1352 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1359 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1361 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1362 @ARGV == 1 or die_usage;
1363 my $project = get_project($ARGV[0]);
1364 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1365 if $project->is_password_locked;
1368 if ($random eq "random") {
1369 die "refusing to set random password without --force\n" unless $force;
1370 $rmsg = "set to random value";
1371 $newpw = _get_random_val($project);
1373 die "refusing to set password hash to '$random' without --force\n" unless $force;
1374 $rmsg = "hash set to '$random'";
1380 print "Changing admin password for project $ARGV[0]\n";
1381 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1382 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1383 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1384 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1385 "the admin passwords you have entered do not match each other.\n";
1389 defined($newpw) or die "missing new password on STDIN\n";
1393 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1394 my $old = $project->{crypt};
1395 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1396 if (defined($old) && $old eq $project->{crypt}) {
1397 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1399 # Avoid touching anything other than the password hash
1400 $project->_group_update;
1401 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1407 @ARGV == 1 or die_usage;
1408 my $project = get_project($ARGV[0]);
1409 my $pwhash = $project->{crypt};
1410 defined($pwhash) or $pwhash = "";
1411 if ($pwhash eq "") {
1412 warn $project->{name}, ": no password required\n" unless $quiet;
1415 if ($project->is_password_locked) {
1416 warn $project->{name}, ": password is locked\n" unless $quiet;
1421 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1422 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1425 defined($checkpw) or die "missing admin password on STDIN\n";
1428 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1429 warn "password check failure\n" unless $quiet;
1432 warn "admin password match\n" unless $quiet;
1437 my ($force, $auto, $redelta, $recompress, $aggressive);
1438 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1439 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force,
1440 recompress => \$recompress, "no-reuse-object" => $recompress,
1441 aggressive => \$aggressive);
1442 $aggressive and $force = $redelta = 1;
1443 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1444 @ARGV or die "Please give project name on command line.\n";
1445 @ARGV == 1 or die_usage;
1446 my $project = get_project($ARGV[0]);
1447 delete $ENV{show_progress};
1448 delete $ENV{force_gc};
1449 $quiet or $ENV{"show_progress"} = 1;
1450 $force and $ENV{"force_gc"} = 1;
1451 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1452 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1454 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1455 $redelta && !$recompress and push(@args, "-f");
1456 $recompress and push(@args, "-F");
1457 my $lastgc = $project->{lastgc};
1458 system({$args[0]} @args) != 0 and return 1;
1459 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1461 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1463 system({$args[0]} @args) != 0 and return 1;
1470 my ($force, $summary);
1471 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1472 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1473 @ARGV or die "Please give project name on command line.\n";
1474 @ARGV == 1 or die_usage
;
1475 my $project = get_project
($ARGV[0]);
1476 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1477 delete $ENV{show_progress
};
1478 delete $ENV{force_update
};
1480 $ENV{"show_progress"} = 0;
1482 $ENV{"show_progress"} = ($summary ?
1 : 2);
1484 $force and $ENV{"force_update"} = 1;
1485 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1491 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1492 @ARGV or die "Please give project name on command line.\n";
1493 @ARGV == 1 or die_usage
;
1494 my $project = get_project
($ARGV[0]);
1495 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1496 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1497 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1498 exit(255) unless $force;
1499 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1501 unlink($project->_clonefail_path);
1502 unlink($project->_clonelog_path);
1503 recreate_file
($project->_clonep_path);
1504 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1505 die "cannot connect to taskd.socket: $!\n";
1506 select((select($sock),$|=1)[0]);
1507 $sock->print("clone ".$project->{name
}."\n");
1508 # Just ignore reply, we are going to succeed anyway and the I/O
1509 # would apparently get quite hairy.
1513 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1519 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1520 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1521 my $project = get_project
($ARGV[0]);
1522 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1523 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1525 warn "using invalid owner/email with --force\n" unless $quiet;
1527 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1528 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1530 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1532 my $old = $project->{email
};
1534 print "$old\n" if defined($old);
1537 if (defined($old) && $old eq $ARGV[1]) {
1538 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1540 # Avoid touching anything other than "gitweb.owner"
1541 $project->_property_fput("email", $ARGV[1]);
1542 $project->_update_index;
1543 $project->_set_changed;
1544 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1551 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1552 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1553 my $project = get_project
(shift @ARGV);
1554 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1555 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1557 warn "using invalid description with --force\n" unless $quiet;
1559 my $desc = clean_desc
(join(" ", @ARGV));
1560 if (@ARGV && length($desc) > 1024) {
1561 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1563 warn "using longer than 1024 char description with --force\n" unless $quiet;
1565 my $old = $project->{desc
};
1567 print "$old\n" if defined($old);
1570 if (defined($old) && $old eq $desc) {
1571 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1573 # Avoid touching anything other than description file
1574 $project->_property_fput("desc", $desc);
1575 $project->_set_changed;
1576 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1582 my ($force, $readmetype) = (0, undef);
1583 parse_options
(force
=> \
$force, ":type" => \
$readmetype, ":format" => \
$readmetype);
1584 @ARGV == 1 && defined($readmetype) and push(@ARGV, undef);
1585 @ARGV == 2 || (@ARGV == 1 && !$force && !defined($readmetype) && !$setopt) or die_usage
;
1586 defined($readmetype) and $readmetype = Girocco
::Project
::_normalize_rmtype
($readmetype,1);
1587 defined($readmetype) && !$readmetype and die_usage
;
1588 my $project = get_project
($ARGV[0]);
1589 my $old = $project->{READMEDATA
};
1591 chomp $old if defined($old);
1592 print "$old\n" if defined($old) && $old ne "";
1595 $readmetype or $readmetype = $project->{rmtype
};
1596 my ($new, $raw, $newname);
1598 if (!defined($ARGV[1])) {
1600 $newname = "original README data";
1601 $readmetype ne $project->{rmtype
} && $new ne "" and $raw = 1;
1602 } elsif ($ARGV[1] eq "-") {
1606 $newname = "contents of <STDIN>";
1607 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1609 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1610 $new = "<!-- suppress -->";
1614 die "missing filename for README\n" unless $fn ne "";
1615 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1616 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1621 $newname = "contents of \"$fn\"";
1623 defined($new) or $new = '';
1624 my $origrmtype = $project->{rmtype
};
1625 $project->{rmtype
} = $readmetype;
1626 $project->{READMEDATA
} = to_utf8
($new, 1);
1627 $project->_cleanup_readme;
1628 if (length($project->{READMEDATA
}) > 8192) {
1629 die "readme greater than 8192 chars is too long (use --force to override)\n"
1631 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1634 my ($cnt, $err) = $project->_lint_readme(0);
1636 my $msg = "README: $cnt error";
1637 $msg .= "s" unless $cnt == 1;
1638 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1639 unless $force && $quiet;
1640 exit(255) unless $force && $project->{rmtype
} eq 'HTML';
1641 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1642 $project->{README
} = $project->{READMEDATA
};
1645 if (defined($old) && $old eq $project->{READMEDATA
} && $readmetype eq $origrmtype && !$force) {
1646 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1648 # Avoid touching anything other than README.html file
1649 $project->_property_fput("READMEDATA", $project->{READMEDATA
}, 1);
1650 $project->_property_fput("README", $project->{README
});
1651 $project->_property_fput("rmtype", $readmetype) if $readmetype ne $origrmtype;
1652 $project->_set_changed;
1653 my $desc = get_readme_desc
($project->{README
});
1655 $newname .= " ($desc)";
1659 warn $project->{name
}, ": README $readmetype format updated to $newname\n" unless $quiet;
1665 my ($proj, $newhead) = @_;
1666 my %okheads = map({($_ => 1)} $proj->get_heads);
1667 exists($okheads{$newhead});
1671 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1672 my $project = get_project
($ARGV[0]);
1673 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1674 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1676 my $old = $project->{HEAD
};
1678 print "$old\n" if defined($old);
1681 if (defined($old) && $old eq $ARGV[1]) {
1682 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1684 # Avoid touching anything other than the HEAD symref
1685 $project->set_HEAD($ARGV[1]);
1686 $project->_set_changed;
1687 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1694 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1695 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1696 my $project = get_project
($ARGV[0]);
1697 my $projconfig = read_config_file_hash
($project->{path
}."/config");
1698 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
1699 my $rghp = realpath
($ghp);
1700 my $lhp = $project->{path
}."/hooks";
1701 my $rlhp = realpath
($lhp);
1704 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
1705 $ahp = $projconfig->{"core.hookspath"};
1706 $rahp = realpath
($ahp);
1709 if (defined($rahp) && $rahp ne "") {
1710 if ($rahp eq $rghp) {
1711 my $nc = ($ahp eq $ghp ?
"" : " non-canonical");
1712 printf "%s \t(global%s)\n", $ahp, $nc;
1713 } elsif ($rahp eq $rlhp) {
1714 my $nc = ($ahp eq $lhp ?
"" : " non-canonical");
1715 printf "%s \t(local%s)\n", $ahp, $nc;
1716 } elsif ($rahp ne $ahp) {
1717 print "$ahp \t($rahp)\n";
1721 } elsif ($ahp ne "") {
1722 print "$ahp \t(non-existent)\n";
1727 if (lc($shp) eq "global") {
1729 } elsif (lc($shp) eq "local") {
1731 } elsif (substr($shp, 0, 2) eq "~/") {
1732 $shp = $ENV{"HOME"}.substr($shp,1);
1733 } elsif ($shp =~ m
,^~([a
-zA
-Z_
][a
-zA
-Z_0
-9]*)((?
:/.*)?
)$,) {
1735 my $hd = (getpwnam($1))[7];
1736 $shp = $hd . $sfx if defined($hd) && $hd ne "" && $hd ne "/" && -d
$hd;
1738 $shp ne "" && -d
$shp or die "no such directory: $ARGV[1]\n";
1739 my $rshp = realpath
($shp);
1740 defined($rshp) && $rshp ne "" or die "could not realpath: $ARGV[1]\n";
1741 $rshp =~ m
,^/[^/], or die "invalid hookspath: $rshp\n";
1742 die "refusing to switch from current non-global hookspath without --force\n"
1743 if !$force && defined($rahp) && $rahp ne "" && $rahp ne $rghp && $rshp ne $rahp;
1744 if (!$force && defined($rahp) && $rahp ne "") {
1745 if ($rshp eq $rahp && ($ahp eq $ghp || $ahp eq $lhp)) {
1746 warn $project->{name
}, ": skipping update of hookspath to same effective value\n" unless $quiet;
1750 $rshp = $ghp if $rshp eq $rghp;
1751 $rshp = $lhp if $rshp eq $rlhp;
1752 if ($rshp eq $ahp) {
1753 warn $project->{name
}, ": skipping update of hookspath to same value\n" unless $quiet;
1756 die "refusing to set neither local nor global hookspath without --force\n"
1757 if !$force && $rshp ne $ghp && $rshp ne $lhp;
1758 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1759 'config', "core.hookspath", $rshp);
1760 my $newval = '"'.$rshp.'"';
1761 $newval = "global" if $rshp eq $ghp;
1762 $newval = "local" if $rshp eq $lhp;
1763 warn $project->{name
}, ": hookspath set to $newval\n" unless $quiet;
1779 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1780 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1781 my $project = get_project
($ARGV[0]);
1782 if (!exists($boolfields{$ARGV[1]})) {
1783 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1785 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1786 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1788 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1790 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1791 die "invalid boolean value: \"$ARGV[2]\"\n";
1793 my $bool = clean_bool
($ARGV[2]);
1794 my $old = $project->{$ARGV[1]};
1796 print "$old\n" if defined($old);
1799 if (defined($old) && $old eq $bool) {
1800 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1802 # Avoid touching anything other than $ARGV[1] field
1803 $project->_property_fput($ARGV[1], $bool);
1804 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1809 sub cmd_setjsontype
{
1810 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1811 my $project = get_project
($ARGV[0]);
1814 my $jt = lc($ARGV[1]);
1815 index($jt, "/") >= 0 or $jt = "application/".$jt;
1816 $jt eq 'application/x-www-form-urlencoded' ||
1817 $jt eq 'application/json' or
1818 die "invalid jsontype value: \"$ARGV[1]\"\n";
1821 my $old = $project->{jsontype
};
1823 print "$old\n" if defined($old);
1826 if (defined($old) && $old eq $jsontype) {
1827 warn $project->{name
}, ": skipping update of jsontype to same value\n" unless $quiet;
1829 # Avoid touching anything other than jsontype field
1830 $project->_property_fput('jsontype', $jsontype);
1831 warn $project->{name
}, ": jsontype updated to $jsontype\n" unless $quiet;
1836 sub cmd_setjsonsecret
{
1837 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1838 my $project = get_project
($ARGV[0]);
1842 $js =~ s/^\s+//; $js =~ s/\s+$//;
1845 my $old = $project->{jsonsecret
};
1847 print "$old\n" if defined($old);
1850 if (defined($old) && $old eq $jsonsecret) {
1851 warn $project->{name
}, ": skipping update of jsonsecret to same value\n" unless $quiet;
1853 # Avoid touching anything other than jsonsecret field
1854 $project->_property_fput('jsonsecret', $jsonsecret);
1855 warn $project->{name
}, ": jsonsecret updated to \"$jsonsecret\"\n" unless $quiet;
1860 sub cmd_setautogchack
{
1861 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1862 my $project = get_project
($ARGV[0]);
1863 my $aghok = $Girocco::Config
::autogchack
&&
1864 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1865 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1867 print "$old\n" if $aghok;
1871 if (lc($ARGV[1]) eq "unset") {
1874 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1875 $bool = clean_bool
($ARGV[1]);
1878 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1879 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1881 if ($old eq $bool) {
1882 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1884 if ($bool eq "unset") {
1885 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1886 'config', '--unset', "girocco.autogchack");
1888 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1889 'config', '--bool', "girocco.autogchack", $bool);
1892 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1897 my ($url, $type) = @_;
1898 $type ne 'baseurl' and return valid_web_url
($url);
1899 valid_repo_url
($url) or return 0;
1900 if ($Girocco::Config
::restrict_mirror_hosts
) {
1901 my $mh = extract_url_hostname
($url);
1902 is_dns_hostname
($mh) or return 0;
1903 !is_our_hostname
($mh) or return 0;
1911 baseurl
=> ["url" , 1],
1912 homepage
=> ["hp" , 0],
1913 notifyjson
=> ["notifyjson", 0],
1919 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1920 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1921 my $project = get_project
($ARGV[0]);
1922 if (!exists($urlfields{$ARGV[1]})) {
1923 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1925 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1926 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1928 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1930 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1931 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1933 warn "using invalid URL with --force\n" unless $quiet;
1935 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1937 print "$old\n" if defined($old);
1940 if (defined($old) && $old eq $ARGV[2]) {
1941 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1943 # Avoid touching anything other than $ARGV[1]'s field
1944 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1945 if ($ARGV[1] eq "baseurl") {
1946 $project->{url
} = $ARGV[2];
1947 $project->_set_bangagain;
1949 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1950 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1965 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1966 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1967 my $project = get_project
(shift @ARGV);
1968 my $field = shift @ARGV;
1969 if (!exists($msgsfields{$field})) {
1970 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1972 if (@ARGV && !valid_addrlist
(@ARGV)) {
1973 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1975 warn "using invalid email address list with --force\n" unless $quiet;
1977 my $old = $project->{$field};
1979 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1982 my $newlist = clean_addrlist
(join(" ",@ARGV));
1983 if (defined($old) && $old eq $newlist) {
1984 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1986 # Avoid touching anything other than $field's field
1987 $project->_property_fput($field, $newlist);
1988 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1995 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1996 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1997 my $project = get_project
(shift @ARGV);
1998 my $projname = $project->{name
};
1999 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
2002 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
2003 die "refusing to set empty users list without --force\n" unless @newusers || $force;
2005 return 0 if !@ARGV && $project->{mirror
};
2006 my $oldusers = $project->{users
};
2007 if ($oldusers && ref($oldusers) eq "ARRAY") {
2008 $oldusers = join("\n", @
$oldusers);
2013 print "$oldusers\n" if $oldusers ne "";
2016 if ($oldusers eq join("\n", @newusers)) {
2017 warn "$projname: skipping update of users list to same value\n" unless $quiet;
2019 # Avoid touching anything other than the users list
2020 $project->{users
} = \
@newusers;
2021 $project->_update_users;
2022 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
2030 owner
=> [\
&cmd_setowner
, 0],
2031 desc
=> [\
&cmd_setdesc
, 0],
2032 description
=> [\
&cmd_setdesc
, 0],
2033 readme
=> [\
&cmd_setreadme
, 0],
2034 head
=> [\
&cmd_sethead
, 0],
2035 HEAD
=> [\
&cmd_sethead
, 0],
2036 hooks
=> [\
&cmd_sethooks
, 0],
2037 hookspath
=> [\
&cmd_sethooks
, 0],
2038 cleanmirror
=> [\
&cmd_setbool
, 1],
2039 reverseorder
=> [\
&cmd_setbool
, 1],
2040 summaryonly
=> [\
&cmd_setbool
, 1],
2041 statusupdates
=> [\
&cmd_setbool
, 1],
2042 autogchack
=> [\
&cmd_setautogchack
, 0],
2043 baseurl
=> [\
&cmd_seturl
, 1],
2044 homepage
=> [\
&cmd_seturl
, 1],
2045 notifyjson
=> [\
&cmd_seturl
, 1],
2046 jsontype
=> [\
&cmd_setjsontype
, 0],
2047 jsonsecret
=> [\
&cmd_setjsonsecret
, 0],
2048 notifymail
=> [\
&cmd_setmsgs
, 1],
2049 notifytag
=> [\
&cmd_setmsgs
, 1],
2050 users
=> [\
&cmd_setusers
, 0],
2057 push(@newargs, shift) if @_ && $_[0] eq '--force';
2059 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
2060 push(@newargs, shift);
2061 shift unless ${$fieldnames{$field}}[1];
2063 diename
(($setopt ?
"set " : "get ") . $field);
2065 &{${$fieldnames{$field}}[0]}(@ARGV);
2080 create
=> \
&cmd_create
,
2081 adopt
=> \
&cmd_adopt
,
2082 remove
=> \
&cmd_remove
,
2083 trash
=> \
&cmd_remove
,
2084 delete => \
&cmd_remove
,
2085 prune
=> \
&cmd_prune
,
2088 listheads
=> \
&cmd_listheads
,
2089 listtags
=> \
&cmd_listtags
,
2090 listctags
=> \
&cmd_listtags
,
2091 deltags
=> \
&cmd_deltags
,
2092 delctags
=> \
&cmd_deltags
,
2093 addtags
=> \
&cmd_addtags
,
2094 addctags
=> \
&cmd_addtags
,
2095 chpass
=> \
&cmd_chpass
,
2096 checkpw
=> \
&cmd_checkpw
,
2098 update
=> \
&cmd_update
,
2099 remirror
=> \
&cmd_remirror
,
2100 setowner
=> \
&cmd_setowner
,
2101 setdesc
=> \
&cmd_setdesc
,
2102 setdescription
=> \
&cmd_setdesc
,
2103 setreadme
=> \
&cmd_setreadme
,
2104 sethead
=> \
&cmd_sethead
,
2105 sethooks
=> \
&cmd_sethooks
,
2106 sethookspath
=> \
&cmd_sethooks
,
2107 setbool
=> \
&cmd_setbool
,
2108 setboolean
=> \
&cmd_setbool
,
2109 setflag
=> \
&cmd_setbool
,
2110 setautogchack
=> \
&cmd_setautogchack
,
2111 seturl
=> \
&cmd_seturl
,
2112 setjsontype
=> \
&cmd_setjsontype
,
2113 setjsonsecret
=> \
&cmd_setjsonsecret
,
2114 setmsgs
=> \
&cmd_setmsgs
,
2115 setusers
=> \
&cmd_setusers
,
2121 BEGIN { %nopager = (
2122 # 1 => pager never allowed
2123 # -1 => pager defaults to off instead of on
2141 setdescription
=> -1,
2149 setautogchack
=> -1,
2152 setjsonsecret
=> -1,
2161 my $bn = basename
($0);
2162 setup_pager_stdout
($usepager);
2163 printf "%s version %s\n\n", $bn, $VERSION;
2164 if (defined($cmd) && $cmd ne '') {
2165 $cmd =~ s/^set(?=[a-zA-Z])//i;
2167 my ($lastmt, $incmd);
2168 foreach (split('\n', sprintf($help, $bn))) {
2169 $lastmt || $incmd or $lastmt = /^\s*$/, next;
2170 $incmd = 1 if $lastmt && /^\s*(?:\[?set\]?)?$cmd\s/;
2171 last if $incmd && /^\s*$/;
2172 $incmd and $cmdhelp .= $_ . "\n";
2175 print $cmdhelp and exit 0 if $cmdhelp;
2184 shift, $quiet=1, redo if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
2185 shift, $usepager=1, redo if @ARGV && $ARGV[0] =~ /^(?:-p|--pager|--paginate)$/i;
2186 shift, $usepager=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-pager|--no-paginate)$/i;
2188 dohelp
($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
2189 my $command = shift;
2192 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
2194 $command = "set" . $command;
2196 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
2197 dohelp
($command) if @ARGV && ($ARGV[0] =~ /^(?:-h|-?-help)$/i ||
2198 $ARGV[0] =~ /^help$/i && !Girocco
::Project
::does_exist
("help",1));
2199 $nopager{$command} && $nopager{$command} > 0 and $usepager = 0;
2200 my $pgdfltoff = $nopager{$command} && $nopager{$command} < 0 ?
1 : 0;
2201 setup_pager_stdout
($usepager, $pgdfltoff);
2202 &{$commands{$command}}(@ARGV);