3 # projtool.pl - command line Girocco project maintenance tool
4 # Copyright (C) 2016,2017 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'}
15 use Digest::MD5 qw(md5_hex);
18 use lib
"__BASEDIR__";
21 use Girocco
::HashUtil
;
26 exit(&main
(@ARGV)||0);
29 BEGIN {$help = <<'HELP'}
30 Usage: %s [--quiet] <command> <options>
32 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
33 list all projects (default is --sort=lcname)
34 limit to project names matching <regex> if given
35 match <regex> against owner instead of project name with --owner
37 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
38 create new project <project> (prompted)
40 --no-alternates skip setup of objects/info/alternates
41 --orphan allow creation of subproject w/o a parent
42 -p use mkdir -p during --orphan creation
43 --no-password set password crypt to invalid value "unknown"
44 --no-owner leave the gitweb.owner config unset
45 --mirror=<url> create a mirror from <url>
46 --full-mirror mirror all refs
47 --push[=<list>] create a push project
48 --desc=<string> specify project description w/o prompt
49 --defaults do no interactive prompting at all
50 Using --no-password skips the prompts for password, using
51 --no-owner skips the prompt for owner and using --mirror=<url>
52 or --push[=<list>] skips the prompts for mirror URL and
53 heads-only and push users. With --defaults if neither
54 --mirror=<url> nor --push[=<list>] is given then --push will
55 be implied. Using --desc=<string> will force a specific
56 description (including an empty string) and skip the prompt for
57 it. Otherwise a non-empty default description will always be
58 supplied in lieu of an empty or omitted description.
60 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
61 adopt project <project>
62 type of project is guessed if --type=<type> omitted
63 <users> is same as <newuserslist> for setusers command
65 --dry-run do all the checks but don't perform adoption
66 --verbose show project info dump (useful with --dry-run)
67 --no-users no push users at all (<users> must be omitted)
68 --no-owner leave the gitweb.owner config totally unchanged
69 --owner=<val> set the gitweb.owner config to <val>
70 Both --no-owner and --owner=<val> may NOT be given, with neither
71 take owner from preexisting gitweb.owner else use admin setting.
72 For mirrors <users> is ignored otherwise if no <users> and no
73 --no-users option the push users list will consist of the single
74 user name matching the owner or empty if none or more than one.
75 With --dry-run <project> can be an absolute path to a git dir.
77 remove [--force] [--really-delete] [--keep-forks] <project>
78 remove project <project>
79 do not move to _recyclebin with --really-delete (just rm -rf)
80 remove projects with forks (by keeping forks) using --keep-forks
83 show project <project>
86 list all available heads for <project> and indicate current head
88 listtags [--verbose] <project>
89 list all ctags on project <project>
91 deltags <project> [-i] <tagstodel>
92 remove any ctags on project <project> present in <tagstodel>
93 <tagstodel> is space or comma separated list of tags to remove
94 with -i match against <tagstodel> without regard to letter case
96 addtags <project> <tagstoadd>
97 add ctags to project <project>
98 <tagstoadd> is space or comma separated list of tags to add
100 chpass [--force] <project> [random | unknown]
101 change project <project> password (prompted)
102 with "random" set to random password
103 with "unknown" set password hash to invalid value "unknown"
106 check project <project> password for a match (prompted)
108 gc [--force | --auto] [--redelta] <project>
109 run the gc.sh script on project <project>
110 with --auto let the gc.sh script decide what to do
111 with --force cause a full gc to take place (force_gc=1)
112 with neither --auto nor --force do a mini or if needed a full gc
113 (in other words just touch .needsgc and run gc.sh)
114 with --redelta a full gc will use pack-objects --no-reuse-delta
115 unless the global --quiet option is given show_progress=1 is used
117 update [--force] [--quiet | --summary] <project>
118 run the update.sh script on project <project>
119 with --force cause a fetch to always take place (force_update=1)
120 with --quiet only show errors (show_progress is left unset)
121 with --summary show progress and ref summary (show_progress=1)
122 with neither --quiet nor --summary show it all (show_progress=2)
124 remirror [--force] <project>
125 initiate a remirror of project <project>
127 [set]owner [--force] <project> <newowner>
128 set project <project> owner to <newowner>
129 without "set" and only 1 arg, just show current project owner
131 [set]desc [--force] <project> <newdesc>
132 set project <project> description to <newdesc>
133 without "set" and only 1 arg, just show current project desc
135 [set]readme [--force] <project> <newsetting>
136 set project <project> readme to <newsetting>
137 <newsetting> is automatic|suppressed|-|[@]filename
138 without "set" and only 2 args, just show current readme setting
140 [set]head <project> <newhead>
141 set project <project> HEAD symbolic ref to <newhead>
142 without "set" and only 1 arg, just show current project HEAD
144 [set]bool [--force] <project> <flagname> <boolvalue>
145 set project <project> boolean <flagname> to <boolvalue>
146 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
147 without "set" and only 2 args, just show current flag value
149 [set]autogchack <project> <boolvalue> | unset
150 set project <project> autogchack to <boolvalue> or "unset" it
151 without "set" just show current autogchack setting if enabled
152 with "set" autogchack must be enabled in Config.pm for the
153 type of project and maintain-auto-gc-hack.sh is always run
155 [set]url [--force] <project> <urlname> <newurlvalue>
156 set project <project> url <urlname> to <newurlvalue>
157 <urlname> is baseurl|homepage|notifyjson
158 without "set" and only 2 args, just show current url value
160 [set]msgs [--force] <project> <msgsname> <eaddrlist>
161 set project <project> msgs <msgsname> to <addrlist>
162 <msgsname> is notifymail|notifytag
163 <eaddrlist> is space or comma separated list of email addresses
164 without "set" and only 2 args, just show current msgs value
166 [set]users [--force] <project> <newuserslist>
167 set push project <project> users list to <newuserslist>
168 <newuserslist> is space or comma separated list of user names
169 without "set" and only 1 arg, just show current users list
171 get <project> <fieldname>
172 show project <project> field <fieldname>
173 <fieldname> is owner|desc|readme|head|users
174 or <flagname>|autogchack|<urlname>|<msgsname>
176 set [--force] <project> <fieldname> <newfieldvalue>
177 set project <project> field <fieldname> to <newfieldvalue>
178 <fieldname> same as for get
179 <newfieldvalue> same as for corresponding set... command
185 my $sub = shift || diename
;
187 die "Invalid arguments to $sub command -- try \"help\"\n";
189 die "Invalid arguments -- try \"help\"\n";
193 sub get_readme_desc
{
195 defined($rm) or $rm = '';
198 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
200 return $test eq '' ?
"suppressed" : "length " . length($rm);
206 sub get_ctag_counts
{
210 foreach ($project->get_ctag_names) {
213 if (open $ct, '<', $project->{path
}."/ctags/$_") {
216 defined $count or $count = '';
218 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
224 push(@ctags, $_."(".$val.")");
227 push(@ctags, [$_, $val]) if $val;
233 sub get_clean_project
{
234 my $project = get_project
(@_);
235 delete $project->{loaded
};
236 delete $project->{base_path
};
237 delete $project->{ccrypt
};
238 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
239 $project->{owner
} = $project->{email
}; delete $project->{email
};
240 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
241 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
242 my $owner = $project->{owner
};
245 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
246 $project->{owner_users
} = \
@owner_users if @owner_users;
248 my $projname = $project->{name
};
249 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
250 $project->{has_forks
} = 1 if @forks;
251 $project->{has_alternates
} = 1 if $project->has_alternates;
252 my @bundles = $project->bundles;
253 delete $project->{bundles
};
254 $project->{bundles
} = \
@bundles if @bundles;
255 $project->{mirror
} = 0 unless $project->{mirror
};
256 $project->{is_empty
} = 1 if $project->is_empty;
257 delete $project->{showpush
} unless $project->{showpush
};
258 delete $project->{users
} if $project->{mirror
};
259 delete $project->{baseurl
} unless $project->{mirror
};
260 delete $project->{banged
} unless $project->{mirror
};
261 delete $project->{lastrefresh
} unless $project->{mirror
};
262 delete $project->{cleanmirror
} unless $project->{mirror
};
263 delete $project->{statusupdates
} unless $project->{mirror
};
264 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
265 unless ($project->{banged
}) {
266 delete $project->{bangcount
};
267 delete $project->{bangfirstfail
};
268 delete $project->{bangmessagesent
};
270 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
271 my @tags = get_ctag_counts
($project, 1);
272 $project->{tags
} = \
@tags if @tags;
279 foreach (split(/[,\s]+/, $_[0])) {
281 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
283 return join(($_[1]||","), @newlist);
287 my $cleaned = clean_addrlist
(join(" ", @_));
288 return 1 if $cleaned eq "";
289 valid_email_multi
($cleaned) && length($cleaned) <= 512;
293 my ($userlist, $force, $nodie, $quiet) = @_;
297 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
298 my %users = map({($$_[1] => $_)} get_all_users
);
299 foreach (split(/[\s,]+/, $userlist)) {
300 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
301 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
304 if (Girocco
::User
::does_exist
($_, 1)) {
306 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
309 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
314 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
316 die if $badlist && !$nodie;
320 sub is_default_desc
{
321 # "Unnamed repository; edit this file 'description' to name the repository."
322 # "Unnamed repository; edit this file to name it for gitweb."
324 return 0 unless defined($_);
325 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
331 return 0 if $test =~ /[\r\n]/;
332 $test =~ s/\s\s+/ /g;
340 defined($desc) or $desc = '';
342 $desc = to_utf8
($desc, 1);
343 $desc =~ s/\s\s+/ /g;
350 Girocco
::CLIUtil
::_parse_options
(
352 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
360 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
361 name
=> sub {$$a[1] cmp $$b[1]},
362 gid
=> sub {$$a[3] <=> $$b[3]},
363 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
364 no => sub {$$a[0] <=> $$b[0]},
366 my $sortopt = 'lcname';
367 my ($verbose, $owner);
368 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
371 my $val = shift @ARGV;
372 $regex = qr
($val) or die "bad regex \"$val\"\n";
374 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
375 my $sortsub = $sortsub{$sortopt};
376 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
377 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
379 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
381 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
387 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
388 $ismirror, $desc, $fullmirror);
390 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
391 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
392 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
393 "full-mirror" => \
$fullmirror);
394 @ARGV == 1 or die_usage
;
395 !defined($pushusers) || defined($ispush) or $ispush = 1;
396 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
397 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
398 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
399 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
400 !$defaults || defined($nopasswd) or $nopasswd = 1;
401 !$defaults || defined($noowner) or $noowner = 1;
402 !defined($ispush) || defined($pushusers) or $pushusers = "";
403 my $projname = $ARGV[0];
404 $projname =~ s/\.git$//i;
405 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
406 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
407 warn "Refusing to create orphan project without --orphan\n"
408 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
409 warn "Required orphan parent directory does not exist (use -p): ",
410 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
411 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
412 die "Invalid project name: \"$projname\"\n";
414 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
415 my $newtype = $forkee ?
'fork' : 'project';
416 if (length($project) > 64) {
417 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
419 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
421 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
422 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
423 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
425 print "Enter settings for new project \"$projname\"\n" unless $defaults;
427 $settings{noalternates
} = $noalternates;
429 $settings{crypt} = "unknown";
431 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
432 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
433 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
434 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
435 "the admin passwords you have entered do not match each other.\n";
436 $settings{crypt} = scrypt_sha1
($np1);
440 $owner = prompt_or_die
("Owner/email name for project $projname");
441 unless (valid_email
($owner)) {
443 warn "Your email sure looks weird...?\n";
446 warn "Allowing invalid email with --force\n" unless $quiet;
448 if (length($owner) > 96) {
450 warn "Your email is longer than 96 characters. Do you really need that much?\n";
453 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
456 $settings{email
} = $owner;
458 my $checkmirror = sub {
459 my $checkurl = shift;
460 unless (valid_repo_url
($checkurl)) {
462 warn "Invalid mirror URL: \"$checkurl\"\n";
465 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
467 if ($Girocco::Config
::restrict_mirror_hosts
) {
468 my $mh = extract_url_hostname
($checkurl);
469 unless (is_dns_hostname
($mh)) {
471 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
474 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
476 if (is_our_hostname
($mh)) {
478 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
481 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
486 if ($ispush || $ismirror) {
487 !$ispush || $force || $Girocco::Config
::push or
488 die "Push projects are disabled, create a mirror (or use --force)\n";
489 !$ismirror || $force || $Girocco::Config
::mirror
or
490 die "Mirror projects are disabled, create a push project (or use --force)\n";
492 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
493 $baseurl = $ismirror;
494 $settings{url
} = $baseurl;
495 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
498 if ($pushusers !~ /^[\s,]*$/) {
499 eval {@newusers = validate_users
($pushusers, $force); 1;} or
500 die "Invalid --push user list\n";
502 $settings{users
} = \
@newusers;
504 } elsif ($force || $Girocco::Config
::mirror
) {{
505 if ($force || $Girocco::Config
::push) {
506 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
508 $baseurl = prompt_or_die
("URL to mirror from");
509 unless ($baseurl ne "") {
510 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
514 if ($baseurl ne "") {
515 &$checkmirror($baseurl) or redo;
516 $settings{url
} = $baseurl;
517 $settings{cleanmirror
} =
518 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
521 my $mirror = ($baseurl eq "") ?
0 : 1;
522 my $checkdesc = sub {
524 if (length($d) > 1024) {
526 warn "Short description length greater than 1024 characters!\n";
529 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
533 if (defined($desc)) {
534 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
535 $desc eq "" || &$checkdesc($desc) or
536 die "Invalid --desc description\n";
537 } elsif (!$defaults) {
538 $desc = prompt_or_die
("Short description", "");
539 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
540 $desc eq "" || &$checkdesc($desc) or redo;
541 $desc = undef if $desc eq "";
543 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
544 $settings{desc
} = $desc;
547 $homepage = prompt_or_die
("Home page URL", "");
548 if ($homepage ne "" && !valid_web_url
($homepage)) {
550 warn "Invalid home page URL: \$homepage\"\n";
553 warn "Allowing invalid home page URL with --force\n" unless $quiet;
556 $settings{hp
} = $homepage;
559 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
560 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
562 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
565 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
568 $settings{notifyjson
} = $jsonurl;
569 my $commitaddrs = "";
571 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
572 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
574 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
577 warn "using invalid commit notify email address list with --force\n" unless $quiet;
580 $settings{notifymail
} = $commitaddrs;
581 $settings{reverseorder
} = 1;
582 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
583 if !$defaults && $commitaddrs ne "";
584 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
585 if !$defaults && $commitaddrs ne "";
588 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
589 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
591 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
594 warn "using invalid tag notify email address list with --force\n" unless $quiet;
597 $settings{notifytag
} = $tagaddrs;
598 if (!$mirror && !$ispush) {
601 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
602 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
604 $settings{users
} = \
@newusers;
606 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
607 or die "Girocco::Project->ghost call failed\n";
609 $newproj->{$k} = $v while ($k, $v) = each(%settings);
610 my $killowner = sub {
611 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
612 'config', '--unset', "gitweb.owner");
615 $newproj->premirror or die "Girocco::Project->premirror failed\n";
616 !$noowner or &$killowner;
617 $newproj->clone or die "Girocco::Project->clone failed\n";
618 warn "Project $projname created and cloning successfully initiated.\n"
621 $newproj->conjure or die "Girocco::Project->conjure failed\n";
622 !$noowner or &$killowner;
623 warn "New push project fork is empty due to use of --no-alternates\n"
624 if !$quiet && $projname =~ m
,/, && $noalternates;
625 warn "Project $projname successfully created.\n" unless $quiet;
632 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
633 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
637 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
638 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
639 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
640 @ARGV or die "Please give project name on command line.\n";
641 my $projname = shift @ARGV;
642 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
643 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
644 defined($type) or $type = "";
646 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
647 $projdir = realpath
($projname);
648 $projname = $projdir;
649 $projname =~ s/\.git$//i;
650 $projname =~ s
,/+$,,;
651 $projname =~ s
,^.*/,,;
652 $projname ne "" or $projname = $projdir;
654 $projname =~ s/\.git$//i;
655 $projname ne "" or die "Invalid project name \"\".\n";
656 unless (Girocco
::Project
::does_exist
($projname, 1)) {
657 Girocco
::Project
::valid_name
($projname, 1, 1)
658 or die "Invalid project name \"$projname\".\n";
659 die "No such project to adopt: $projname\n";
661 defined(Girocco
::Project
->load($projname))
662 and die "Project already known (no need to adopt): $projname\n";
663 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
664 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
666 my $config = read_config_file
($projdir . "/config");
668 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
669 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
670 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
671 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1, $quiet)];
673 if (-e
"$projdir/description") {
674 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
680 defined $desc or $desc = "";
682 $desc = to_utf8
($desc, 1);
683 is_default_desc
($desc) and $desc = "";
684 if ($desc ne "" && !valid_desc
($desc)) {
685 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
687 warn "using invalid 'description' file contents with --force\n" unless $quiet;
689 $desc = clean_desc
($desc);
690 if (length($desc) > 1024) {
691 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
693 warn "using longer than 1024 char description with --force\n" unless $quiet;
697 if (-e
"$projdir/README.html") {
698 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
704 defined $readme or $readme = "";
705 $readme = to_utf8
($readme, 1);
706 $readme =~ s/\r\n?/\n/gs;
707 $readme =~ s/^\s+//s;
708 $readme =~ s/\s+$//s;
709 $readme eq "" or $readme .= "\n";
710 if (length($readme) > 8192) {
711 die "readme greater than 8192 chars is too long (use --force to override)\n"
713 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
715 my $rd = get_readme_desc
($readme);
716 if ($rd ne "automatic" && $rd ne "suppressed") {
717 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
718 if (-f
$xmllint && -x
$xmllint) {
719 my $dummy = {README
=> $readme};
720 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
722 my $msg = "xmllint: $cnt error";
723 $msg .= "s" unless $cnt == 1;
724 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
725 unless $force && $quiet;
726 exit(255) unless $force;
727 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
730 die "xmllint not available, refusing to use raw HTML without --force\n"
732 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
736 # Inspect any remotes now
737 # Yes, Virginia, remote urls can be multi-valued
741 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
742 my ($name, $subkey) = ($1, $2);
743 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
744 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
745 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
746 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
747 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
749 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
750 # the remote names in a group are separated by runs of [ \t\n] characters
751 # remote names "", ".", ".." and any name starting with "/" are invalid
752 # a remote with no url or vcs setting is not considered valid
755 if (exists($config{"remotes
.default"})) {
756 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
757 next unless exists($remotes{$_});
758 my $rmt = $remotes{$_};
759 next if !exists($rmt->{url}) && !$rmt->{vcs};
767 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
768 next if $seenrmt{$1};
770 next unless exists($remotes{$1});
771 my $rmt = $remotes{$1};
772 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
776 my @needskip = (); # remotes that need skipDefaultUpdate set to true
779 my $foundfetchwithmirror = 0;
781 my $rmt = $remotes{$_};
782 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
783 next unless exists($rmt->{fetch});
785 ++$foundfetchwithmirror if $rmt->{mirror};
786 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
788 # if we have $foundvcs then we need to explicitly set fetch.prune to false
789 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
790 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
792 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
793 # if remote "origin
" exists we always pick up its first url or use ""
794 if (exists($remotes{origin})) {
795 my $rmt = $remotes{origin};
796 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
797 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
800 # get the first url of the @check remotes
802 my $rmt = $remotes{$_};
803 next unless exists($rmt->{url});
804 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
805 $baseurl = $rmt->{url}->[0];
809 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
811 # If we have $foundfetch we want to make a mirror but complain if
812 # we $foundfetchwithmirror as well unless we have --type=mirror.
813 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
814 # Warn if we need to set fetch.prune=false when making a mirror
815 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
816 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
817 # Warn if $usingall and any @needskip (and set them) if making a mirror
818 # Warn if making a mirror and $baseurl eq ""
819 # Warn if we have --type=mirror and !$foundfetch
822 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
823 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
824 if ($foundfetchwithmirror) {
825 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
826 "(Use
--type
=mirror to override
)\n"
827 unless $type eq "mirror
";
828 exit(255) unless $type eq "mirror
" || $dryrun;
829 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
830 unless $quiet || $type ne "mirror
";
832 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
833 if !$quiet && $neednoprune;
834 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
835 if !$quiet && $needfakeorigin;
836 if (!$usingall && @needskip) {
837 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
839 exit(255) unless $force || $dryrun;
840 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
841 unless $quiet || !$force;
843 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
844 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
846 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
847 if !$quiet && $foundfetch && !$foundfetchwithmirror;
850 if (!$noowner && !defined($owner)) {
852 $owner = $config{"gitweb
.owner
"};
853 if (!defined($owner) || $owner eq "") {
854 $owner = $Girocco::Config::admin;
855 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
858 if (!$nousers && !$makemirror && !defined($users)) {
859 # select user list for push project
860 my $findowner = $owner;
861 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
862 $findowner = lc($findowner) if defined($findowner);
863 my @owner_users = ();
864 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
865 if defined($findowner) && $findowner ne "";
866 if (@owner_users <= 1) {
867 $users = \@owner_users;
868 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
871 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
872 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
875 defined($users) or $users = [];
877 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
878 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
879 # and warn about preserving the setting)
881 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
882 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
883 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
884 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
885 $config{"receive
.denydeletecurrent
"} ne "warn";
887 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
888 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
889 if ($reflogactive || $reflogfiles) {
890 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
891 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
892 exit(255) unless $force || $dryrun;
893 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
894 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
897 return 0 if $dryrun && !$verbose;
899 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
900 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
901 $newproj->{desc} = $desc;
902 $newproj->{README} = $readme;
903 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
904 $newproj->{email} = $owner if defined($owner);
905 $newproj->{users} = $users;
906 $newproj->{crypt} = "unknown
";
907 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
908 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
909 my $dummy = bless {}, "Girocco
::Project
";
910 $dummy->{path} = "$projdir";
911 $dummy->{configfilehash} = \%config;
912 $dummy->_properties_load;
913 delete $dummy->{origurl};
914 foreach my $k (keys(%$dummy)) {
915 $newproj->{$k} = $dummy->{$k}
916 if exists($dummy->{$k}) && !exists($newproj->{$k});
921 my %info = %$newproj;
922 $info{README} = get_readme_desc($info{README}) if exists($info{README});
923 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
924 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
925 print $d->Dump([\%info], ['*'.$newproj->{name}]);
929 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
931 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
932 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
933 if ($usingall && @needskip) {
934 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
938 # Perform the actual adoption
939 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
941 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
942 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
943 if git_bool($config{"receive
.denynonfastforwards
"});
944 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
945 if exists($config{"receive
.denydeletecurrent
"}) &&
946 $config{"receive
.denydeletecurrent
"} ne "warn";
947 git_config($projdir, "core
.logAllRefUpdates
", "true
")
952 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
954 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
960 my ($force, $reallydel, $keepforks);
961 parse_options(force => \$force, "really
-delete" => \$reallydel,
962 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
963 @ARGV or die "Please give project name on command line
.\n";
964 @ARGV == 1 or die_usage;
965 my $project = get_project($ARGV[0]);
966 my $projname = $project->{name};
967 my $isempty = !$project->{mirror} && $project->is_empty;
968 if (!$project->{mirror} && !$isempty && $reallydel) {
969 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
970 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
974 if ($project->has_forks) {
975 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
976 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
977 # Run pseudo GC on that repository so that objects don't get lost within forks
978 my $basedir = $Girocco::Config::basedir;
979 my $projdir = $project->{path};
980 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
981 my $nogcrunning = sub {
982 die "Error: GC appears to be currently running on $projname\n"
983 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
986 $removenogc = ! -e "$projdir/.nogc";
987 recreate_file("$projdir/.nogc") if $removenogc;
988 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
989 delete $ENV{show_progress};
990 $ENV{'show_progress
'} = 1 unless $quiet;
993 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
994 or die "Running pseudo GC on project $projname failed\n";
998 if (!$project->{mirror} && !$isempty && !$reallydel) {
999 $archived = $project->archive_and_delete;
1000 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1004 warn "Project '$projname' removed from $Girocco::Config::name" .
1005 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1006 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1012 @ARGV == 1 or die_usage;
1013 my $project = get_clean_project($ARGV[0]);
1014 my %info = %$project;
1015 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1016 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1017 print $d->Dump([\%info], ['*'.$project->{name}]);
1022 @ARGV == 1 or die_usage;
1023 my $project = get_project($ARGV[0]);
1024 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1025 my $cur = $project->{HEAD};
1026 defined($cur) or $cur = '';
1028 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1029 defined($headhash) or $headhash = '';
1031 $headhash or $curmark = '!';
1033 my $mark = $_ eq $cur ? $curmark : ' ';
1041 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1042 @ARGV == 1 or die_usage;
1043 my $project = get_project($ARGV[0]);
1045 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1047 print map("$_\n", $project->get_ctag_names);
1054 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1055 @ARGV >= 2 or die_usage;
1056 my $project = get_project(shift @ARGV);
1059 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1061 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1065 my $ctags = join(" ", @ARGV);
1066 $ctags = lc($ctags) if $ic;
1067 foreach (split(/[\s,]+/, $ctags)) {
1068 next unless exists($curtags{$_});
1069 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1072 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1074 # Avoid touching anything other than the ctags
1075 foreach my $tg (@deltags) {
1076 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1078 $project->_set_changed;
1079 $project->_set_forkchange;
1080 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1086 @ARGV >= 2 or die_usage;
1087 my $project = get_project(shift @ARGV);
1088 my $ctags = join(" ", @ARGV);
1089 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1090 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1091 my $oldmask = umask();
1092 umask($oldmask & ~0060);
1094 foreach (split(/[\s,]+/, $ctags)) {
1095 ++$changed if $project->add_ctag($_, 1);
1098 $project->_set_changed;
1099 $project->_set_forkchange;
1102 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1103 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1107 sub _get_random_val {
1112 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1119 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1121 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1122 @ARGV == 1 or die_usage;
1123 my $project = get_project($ARGV[0]);
1124 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1125 if $project->is_password_locked;
1128 if ($random eq "random") {
1129 die "refusing to set random password without --force\n" unless $force;
1130 $rmsg = "set to random value";
1131 $newpw = _get_random_val($project);
1133 die "refusing to set password hash to '$random' without --force\n" unless $force;
1134 $rmsg = "hash set to '$random'";
1140 print "Changing admin password for project $ARGV[0]\n";
1141 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1142 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1143 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1144 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1145 "the admin passwords you have entered do not match each other.\n";
1149 defined($newpw) or die "missing new password on STDIN\n";
1153 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1154 my $old = $project->{crypt};
1155 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1156 if (defined($old) && $old eq $project->{crypt}) {
1157 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1159 # Avoid touching anything other than the password hash
1160 $project->_group_update;
1161 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1167 @ARGV == 1 or die_usage;
1168 my $project = get_project($ARGV[0]);
1169 my $pwhash = $project->{crypt};
1170 defined($pwhash) or $pwhash = "";
1171 if ($pwhash eq "") {
1172 warn $project->{name}, ": no password required\n" unless $quiet;
1175 if ($project->is_password_locked) {
1176 warn $project->{name}, ": password is locked\n" unless $quiet;
1181 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1182 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1185 defined($checkpw) or die "missing admin password on STDIN\n";
1188 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1189 warn "password check failure\n" unless $quiet;
1192 warn "admin password match\n" unless $quiet;
1197 my ($force, $auto, $redelta);
1198 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1199 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force);
1200 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1201 @ARGV or die "Please give project name on command line.\n";
1202 @ARGV == 1 or die_usage;
1203 my $project = get_project($ARGV[0]);
1204 delete $ENV{show_progress};
1205 delete $ENV{force_gc};
1206 $quiet or $ENV{"show_progress"} = 1;
1207 $force and $ENV{"force_gc"} = 1;
1208 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1209 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1211 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1212 $redelta and push(@args, "-f");
1213 my $lastgc = $project->{lastgc};
1214 system({$args[0]} @args) != 0 and return 1;
1215 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1217 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1219 system({$args[0]} @args) != 0 and return 1;
1226 my ($force, $summary);
1227 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1228 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1229 @ARGV or die "Please give project name on command line.\n";
1230 @ARGV == 1 or die_usage
;
1231 my $project = get_project
($ARGV[0]);
1232 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1233 delete $ENV{show_progress
};
1234 delete $ENV{force_update
};
1236 $ENV{"show_progress"} = 0;
1238 $ENV{"show_progress"} = ($summary ?
1 : 2);
1240 $force and $ENV{"force_update"} = 1;
1241 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1247 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1248 @ARGV or die "Please give project name on command line.\n";
1249 @ARGV == 1 or die_usage
;
1250 my $project = get_project
($ARGV[0]);
1251 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1252 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1253 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1254 exit(255) unless $force;
1255 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1257 unlink($project->_clonefail_path);
1258 unlink($project->_clonelog_path);
1259 recreate_file
($project->_clonep_path);
1260 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1261 die "cannot connect to taskd.socket: $!\n";
1262 select((select($sock),$|=1)[0]);
1263 $sock->print("clone ".$project->{name
}."\n");
1264 # Just ignore reply, we are going to succeed anyway and the I/O
1265 # would apparently get quite hairy.
1269 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1275 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1276 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1277 my $project = get_project
($ARGV[0]);
1278 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1279 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1281 warn "using invalid owner/email with --force\n" unless $quiet;
1283 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1284 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1286 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1288 my $old = $project->{email
};
1290 print "$old\n" if defined($old);
1293 if (defined($old) && $old eq $ARGV[1]) {
1294 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1296 # Avoid touching anything other than "gitweb.owner"
1297 $project->_property_fput("email", $ARGV[1]);
1298 $project->_update_index;
1299 $project->_set_changed;
1300 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1307 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1308 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1309 my $project = get_project
(shift @ARGV);
1310 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1311 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1313 warn "using invalid description with --force\n" unless $quiet;
1315 my $desc = clean_desc
(join(" ", @ARGV));
1316 if (@ARGV && length($desc) > 1024) {
1317 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1319 warn "using longer than 1024 char description with --force\n" unless $quiet;
1321 my $old = $project->{desc
};
1323 print "$old\n" if defined($old);
1326 if (defined($old) && $old eq $desc) {
1327 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1329 # Avoid touching anything other than description file
1330 $project->_property_fput("desc", $desc);
1331 $project->_set_changed;
1332 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1339 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1340 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1341 my $project = get_project
($ARGV[0]);
1342 my $old = $project->{README
};
1344 chomp $old if defined($old);
1345 print "$old\n" if defined($old) && $old ne "";
1348 my ($new, $raw, $newname);
1350 if ($ARGV[1] eq "-") {
1354 $newname = "contents of <STDIN>";
1355 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1357 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1358 $new = "<!-- suppress -->";
1362 die "missing filename for README\n" unless $fn ne "";
1363 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1364 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1369 $newname = "contents of \"$fn\"";
1371 defined($new) or $new = '';
1372 $project->{README
} = to_utf8
($new, 1);
1373 $project->_cleanup_readme;
1374 if (length($project->{README
}) > 8192) {
1375 die "readme greater than 8192 chars is too long (use --force to override)\n"
1377 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1380 my $rd = get_readme_desc
($project->{README
});
1381 if ($rd ne "automatic" && $rd ne "suppressed") {
1382 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
1383 if (-f
$xmllint && -x
$xmllint) {
1384 my ($cnt, $err) = $project->_lint_readme(0);
1386 my $msg = "xmllint: $cnt error";
1387 $msg .= "s" unless $cnt == 1;
1388 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1389 unless $force && $quiet;
1390 exit(255) unless $force;
1391 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1394 die "xmllint not available, refusing to use raw HTML without --force\n"
1396 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1400 if (defined($old) && $old eq $project->{README
}) {
1401 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1403 # Avoid touching anything other than README.html file
1404 $project->_property_fput("README", $project->{README
});
1405 $project->_set_changed;
1406 my $desc = get_readme_desc
($project->{README
});
1408 $newname .= " ($desc)";
1412 warn $project->{name
}, ": README updated to $newname\n" unless $quiet;
1418 my ($proj, $newhead) = @_;
1419 my %okheads = map({($_ => 1)} $proj->get_heads);
1420 exists($okheads{$newhead});
1424 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1425 my $project = get_project
($ARGV[0]);
1426 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1427 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1429 my $old = $project->{HEAD
};
1431 print "$old\n" if defined($old);
1434 if (defined($old) && $old eq $ARGV[1]) {
1435 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1437 # Avoid touching anything other than the HEAD symref
1438 $project->set_HEAD($ARGV[1]);
1439 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1456 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1457 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1458 my $project = get_project
($ARGV[0]);
1459 if (!exists($boolfields{$ARGV[1]})) {
1460 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1462 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1463 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1465 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1467 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1468 die "invalid boolean value: \"$ARGV[2]\"\n";
1470 my $bool = clean_bool
($ARGV[2]);
1471 my $old = $project->{$ARGV[1]};
1473 print "$old\n" if defined($old);
1476 if (defined($old) && $old eq $bool) {
1477 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1479 # Avoid touching anything other than $ARGV[1] field
1480 $project->_property_fput($ARGV[1], $bool);
1481 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1486 sub cmd_setautogchack
{
1487 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1488 my $project = get_project
($ARGV[0]);
1489 my $aghok = $Girocco::Config
::autogchack
&&
1490 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1491 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1493 print "$old\n" if $aghok;
1497 if (lc($ARGV[1]) eq "unset") {
1500 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1501 $bool = clean_bool
($ARGV[1]);
1504 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1505 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1507 if ($old eq $bool) {
1508 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1510 if ($bool eq "unset") {
1511 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1512 'config', '--unset', "girocco.autogchack");
1514 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1515 'config', '--bool', "girocco.autogchack", $bool);
1518 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1523 my ($url, $type) = @_;
1524 $type ne 'baseurl' and return valid_web_url
($url);
1525 valid_repo_url
($url) or return 0;
1526 if ($Girocco::Config
::restrict_mirror_hosts
) {
1527 my $mh = extract_url_hostname
($url);
1528 is_dns_hostname
($mh) or return 0;
1529 !is_our_hostname
($mh) or return 0;
1537 baseurl
=> ["url" , 1],
1538 homepage
=> ["hp" , 0],
1539 notifyjson
=> ["notifyjson", 0],
1545 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1546 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1547 my $project = get_project
($ARGV[0]);
1548 if (!exists($urlfields{$ARGV[1]})) {
1549 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1551 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1552 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1554 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1556 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1557 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1559 warn "using invalid URL with --force\n" unless $quiet;
1561 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1563 print "$old\n" if defined($old);
1566 if (defined($old) && $old eq $ARGV[2]) {
1567 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1569 # Avoid touching anything other than $ARGV[1]'s field
1570 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1571 if ($ARGV[1] eq "baseurl") {
1572 $project->{url
} = $ARGV[2];
1573 $project->_set_bangagain;
1575 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1576 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1591 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1592 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1593 my $project = get_project
(shift @ARGV);
1594 my $field = shift @ARGV;
1595 if (!exists($msgsfields{$field})) {
1596 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1598 if (@ARGV && !valid_addrlist
(@ARGV)) {
1599 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1601 warn "using invalid email address list with --force\n" unless $quiet;
1603 my $old = $project->{$field};
1605 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1608 my $newlist = clean_addrlist
(join(" ",@ARGV));
1609 if (defined($old) && $old eq $newlist) {
1610 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1612 # Avoid touching anything other than $field's field
1613 $project->_property_fput($field, $newlist);
1614 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1621 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1622 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1623 my $project = get_project
(shift @ARGV);
1624 my $projname = $project->{name
};
1625 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
1628 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
1629 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1631 return 0 if !@ARGV && $project->{mirror
};
1632 my $oldusers = $project->{users
};
1633 if ($oldusers && ref($oldusers) eq "ARRAY") {
1634 $oldusers = join("\n", @
$oldusers);
1639 print "$oldusers\n" if $oldusers ne "";
1642 if ($oldusers eq join("\n", @newusers)) {
1643 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1645 # Avoid touching anything other than the users list
1646 $project->{users
} = \
@newusers;
1647 $project->_update_users;
1648 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1656 owner
=> [\
&cmd_setowner
, 0],
1657 desc
=> [\
&cmd_setdesc
, 0],
1658 description
=> [\
&cmd_setdesc
, 0],
1659 readme
=> [\
&cmd_setreadme
, 0],
1660 head
=> [\
&cmd_sethead
, 0],
1661 HEAD
=> [\
&cmd_sethead
, 0],
1662 cleanmirror
=> [\
&cmd_setbool
, 1],
1663 reverseorder
=> [\
&cmd_setbool
, 1],
1664 summaryonly
=> [\
&cmd_setbool
, 1],
1665 statusupdates
=> [\
&cmd_setbool
, 1],
1666 autogchack
=> [\
&cmd_setautogchack
, 0],
1667 baseurl
=> [\
&cmd_seturl
, 1],
1668 homepage
=> [\
&cmd_seturl
, 1],
1669 notifyjson
=> [\
&cmd_seturl
, 1],
1670 notifymail
=> [\
&cmd_setmsgs
, 1],
1671 notifytag
=> [\
&cmd_setmsgs
, 1],
1672 users
=> [\
&cmd_setusers
, 0],
1679 push(@newargs, shift) if @_ && $_[0] eq '--force';
1681 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
1682 push(@newargs, shift);
1683 shift unless ${$fieldnames{$field}}[1];
1685 diename
(($setopt ?
"set " : "get ") . $field);
1687 &{${$fieldnames{$field}}[0]}(@ARGV);
1702 create
=> \
&cmd_create
,
1703 adopt
=> \
&cmd_adopt
,
1704 remove
=> \
&cmd_remove
,
1705 trash
=> \
&cmd_remove
,
1706 delete => \
&cmd_remove
,
1708 listheads
=> \
&cmd_listheads
,
1709 listtags
=> \
&cmd_listtags
,
1710 listctags
=> \
&cmd_listtags
,
1711 deltags
=> \
&cmd_deltags
,
1712 delctags
=> \
&cmd_deltags
,
1713 addtags
=> \
&cmd_addtags
,
1714 addctags
=> \
&cmd_addtags
,
1715 chpass
=> \
&cmd_chpass
,
1716 checkpw
=> \
&cmd_checkpw
,
1718 update
=> \
&cmd_update
,
1719 remirror
=> \
&cmd_remirror
,
1720 setowner
=> \
&cmd_setowner
,
1721 setdesc
=> \
&cmd_setdesc
,
1722 setdescription
=> \
&cmd_setdesc
,
1723 setreadme
=> \
&cmd_setreadme
,
1724 sethead
=> \
&cmd_sethead
,
1725 setbool
=> \
&cmd_setbool
,
1726 setautogchack
=> \
&cmd_setautogchack
,
1727 setflag
=> \
&cmd_setbool
,
1728 seturl
=> \
&cmd_seturl
,
1729 setmsgs
=> \
&cmd_setmsgs
,
1730 setusers
=> \
&cmd_setusers
,
1737 my $bn = basename
($0);
1738 printf "%s version %s\n\n", $bn, $VERSION;
1745 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1746 dohelp
if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1747 my $command = shift;
1750 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1752 $command = "set" . $command;
1754 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1755 dohelp
if @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i && !Girocco
::Project
::does_exist
("help",1);
1756 &{$commands{$command}}(@ARGV);