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 remirror [--force] <project>
118 initiate a remirror of project <project>
120 [set]owner [--force] <project> <newowner>
121 set project <project> owner to <newowner>
122 without "set" and only 1 arg, just show current project owner
124 [set]desc [--force] <project> <newdesc>
125 set project <project> description to <newdesc>
126 without "set" and only 1 arg, just show current project desc
128 [set]readme [--force] <project> <newsetting>
129 set project <project> readme to <newsetting>
130 <newsetting> is automatic|suppressed|-|[@]filename
131 without "set" and only 2 args, just show current readme setting
133 [set]head <project> <newhead>
134 set project <project> HEAD symbolic ref to <newhead>
135 without "set" and only 1 arg, just show current project HEAD
137 [set]bool [--force] <project> <flagname> <boolvalue>
138 set project <project> boolean <flagname> to <boolvalue>
139 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
140 without "set" and only 2 args, just show current flag value
142 [set]autogchack <project> <boolvalue> | unset
143 set project <project> autogchack to <boolvalue> or "unset" it
144 without "set" just show current autogchack setting if enabled
145 with "set" autogchack must be enabled in Config.pm for the
146 type of project and maintain-auto-gc-hack.sh is always run
148 [set]url [--force] <project> <urlname> <newurlvalue>
149 set project <project> url <urlname> to <newurlvalue>
150 <urlname> is baseurl|homepage|notifyjson
151 without "set" and only 2 args, just show current url value
153 [set]msgs [--force] <project> <msgsname> <eaddrlist>
154 set project <project> msgs <msgsname> to <addrlist>
155 <msgsname> is notifymail|notifytag
156 <eaddrlist> is space or comma separated list of email addresses
157 without "set" and only 2 args, just show current msgs value
159 [set]users [--force] <project> <newuserslist>
160 set push project <project> users list to <newuserslist>
161 <newuserslist> is space or comma separated list of user names
162 without "set" and only 1 arg, just show current users list
164 get <project> <fieldname>
165 show project <project> field <fieldname>
166 <fieldname> is owner|desc|readme|head|users
167 or <flagname>|autogchack|<urlname>|<msgsname>
169 set [--force] <project> <fieldname> <newfieldvalue>
170 set project <project> field <fieldname> to <newfieldvalue>
171 <fieldname> same as for get
172 <newfieldvalue> same as for corresponding set... command
178 my $sub = shift || diename
;
180 die "Invalid arguments to $sub command -- try \"help\"\n";
182 die "Invalid arguments -- try \"help\"\n";
186 sub get_readme_desc
{
188 defined($rm) or $rm = '';
191 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
193 return $test eq '' ?
"suppressed" : "length " . length($rm);
199 sub get_ctag_counts
{
203 foreach ($project->get_ctag_names) {
206 if (open $ct, '<', $project->{path
}."/ctags/$_") {
209 defined $count or $count = '';
211 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
217 push(@ctags, $_."(".$val.")");
220 push(@ctags, [$_, $val]) if $val;
226 sub get_clean_project
{
227 my $project = get_project
(@_);
228 delete $project->{loaded
};
229 delete $project->{base_path
};
230 delete $project->{ccrypt
};
231 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
232 $project->{owner
} = $project->{email
}; delete $project->{email
};
233 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
234 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
235 my $owner = $project->{owner
};
238 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
239 $project->{owner_users
} = \
@owner_users if @owner_users;
241 my $projname = $project->{name
};
242 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
243 $project->{has_forks
} = 1 if @forks;
244 $project->{has_alternates
} = 1 if $project->has_alternates;
245 my @bundles = $project->bundles;
246 delete $project->{bundles
};
247 $project->{bundles
} = \
@bundles if @bundles;
248 $project->{mirror
} = 0 unless $project->{mirror
};
249 $project->{is_empty
} = 1 if $project->is_empty;
250 delete $project->{showpush
} unless $project->{showpush
};
251 delete $project->{users
} if $project->{mirror
};
252 delete $project->{baseurl
} unless $project->{mirror
};
253 delete $project->{banged
} unless $project->{mirror
};
254 delete $project->{lastrefresh
} unless $project->{mirror
};
255 delete $project->{cleanmirror
} unless $project->{mirror
};
256 delete $project->{statusupdates
} unless $project->{mirror
};
257 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
258 unless ($project->{banged
}) {
259 delete $project->{bangcount
};
260 delete $project->{bangfirstfail
};
261 delete $project->{bangmessagesent
};
263 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
264 my @tags = get_ctag_counts
($project, 1);
265 $project->{tags
} = \
@tags if @tags;
272 foreach (split(/[,\s]+/, $_[0])) {
274 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
276 return join(($_[1]||","), @newlist);
280 my $cleaned = clean_addrlist
(join(" ", @_));
281 return 1 if $cleaned eq "";
282 valid_email_multi
($cleaned) && length($cleaned) <= 512;
286 my ($userlist, $force, $nodie, $quiet) = @_;
290 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
291 my %users = map({($$_[1] => $_)} get_all_users
);
292 foreach (split(/[\s,]+/, $userlist)) {
293 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
294 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
297 if (Girocco
::User
::does_exist
($_, 1)) {
299 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
302 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
307 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
309 die if $badlist && !$nodie;
313 sub is_default_desc
{
314 # "Unnamed repository; edit this file 'description' to name the repository."
315 # "Unnamed repository; edit this file to name it for gitweb."
317 return 0 unless defined($_);
318 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
324 return 0 if $test =~ /[\r\n]/;
325 $test =~ s/\s\s+/ /g;
333 defined($desc) or $desc = '';
335 $desc = to_utf8
($desc, 1);
336 $desc =~ s/\s\s+/ /g;
343 Girocco
::CLIUtil
::_parse_options
(
345 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
353 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
354 name
=> sub {$$a[1] cmp $$b[1]},
355 gid
=> sub {$$a[3] <=> $$b[3]},
356 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
357 no => sub {$$a[0] <=> $$b[0]},
359 my $sortopt = 'lcname';
360 my ($verbose, $owner);
361 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
364 my $val = shift @ARGV;
365 $regex = qr
($val) or die "bad regex \"$val\"\n";
367 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
368 my $sortsub = $sortsub{$sortopt};
369 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
370 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
372 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
374 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
380 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
381 $ismirror, $desc, $fullmirror);
383 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
384 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
385 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
386 "full-mirror" => \
$fullmirror);
387 @ARGV == 1 or die_usage
;
388 !defined($pushusers) || defined($ispush) or $ispush = 1;
389 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
390 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
391 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
392 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
393 !$defaults || defined($nopasswd) or $nopasswd = 1;
394 !$defaults || defined($noowner) or $noowner = 1;
395 !defined($ispush) || defined($pushusers) or $pushusers = "";
396 my $projname = $ARGV[0];
397 $projname =~ s/\.git$//i;
398 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
399 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
400 warn "Refusing to create orphan project without --orphan\n"
401 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
402 warn "Required orphan parent directory does not exist (use -p): ",
403 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
404 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
405 die "Invalid project name: \"$projname\"\n";
407 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
408 my $newtype = $forkee ?
'fork' : 'project';
409 if (length($project) > 64) {
410 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
412 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
414 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
415 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
416 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
418 print "Enter settings for new project \"$projname\"\n" unless $defaults;
420 $settings{noalternates
} = $noalternates;
422 $settings{crypt} = "unknown";
424 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
425 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
426 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
427 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
428 "the admin passwords you have entered do not match each other.\n";
429 $settings{crypt} = scrypt_sha1
($np1);
433 $owner = prompt_or_die
("Owner/email name for project $projname");
434 unless (valid_email
($owner)) {
436 warn "Your email sure looks weird...?\n";
439 warn "Allowing invalid email with --force\n" unless $quiet;
441 if (length($owner) > 96) {
443 warn "Your email is longer than 96 characters. Do you really need that much?\n";
446 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
449 $settings{email
} = $owner;
451 my $checkmirror = sub {
452 my $checkurl = shift;
453 unless (valid_repo_url
($checkurl)) {
455 warn "Invalid mirror URL: \"$checkurl\"\n";
458 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
460 if ($Girocco::Config
::restrict_mirror_hosts
) {
461 my $mh = extract_url_hostname
($checkurl);
462 unless (is_dns_hostname
($mh)) {
464 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
467 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
469 if (is_our_hostname
($mh)) {
471 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
474 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
479 if ($ispush || $ismirror) {
480 !$ispush || $force || $Girocco::Config
::push or
481 die "Push projects are disabled, create a mirror (or use --force)\n";
482 !$ismirror || $force || $Girocco::Config
::mirror
or
483 die "Mirror projects are disabled, create a push project (or use --force)\n";
485 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
486 $baseurl = $ismirror;
487 $settings{url
} = $baseurl;
488 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
491 if ($pushusers !~ /^[\s,]*$/) {
492 eval {@newusers = validate_users
($pushusers, $force); 1;} or
493 die "Invalid --push user list\n";
495 $settings{users
} = \
@newusers;
497 } elsif ($force || $Girocco::Config
::mirror
) {{
498 if ($force || $Girocco::Config
::push) {
499 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
501 $baseurl = prompt_or_die
("URL to mirror from");
502 unless ($baseurl ne "") {
503 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
507 if ($baseurl ne "") {
508 &$checkmirror($baseurl) or redo;
509 $settings{url
} = $baseurl;
510 $settings{cleanmirror
} =
511 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
514 my $mirror = ($baseurl eq "") ?
0 : 1;
515 my $checkdesc = sub {
517 if (length($d) > 1024) {
519 warn "Short description length greater than 1024 characters!\n";
522 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
526 if (defined($desc)) {
527 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
528 $desc eq "" || &$checkdesc($desc) or
529 die "Invalid --desc description\n";
530 } elsif (!$defaults) {
531 $desc = prompt_or_die
("Short description", "");
532 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
533 $desc eq "" || &$checkdesc($desc) or redo;
534 $desc = undef if $desc eq "";
536 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
537 $settings{desc
} = $desc;
540 $homepage = prompt_or_die
("Home page URL", "");
541 if ($homepage ne "" && !valid_web_url
($homepage)) {
543 warn "Invalid home page URL: \$homepage\"\n";
546 warn "Allowing invalid home page URL with --force\n" unless $quiet;
549 $settings{hp
} = $homepage;
552 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
553 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
555 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
558 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
561 $settings{notifyjson
} = $jsonurl;
562 my $commitaddrs = "";
564 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
565 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
567 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
570 warn "using invalid commit notify email address list with --force\n" unless $quiet;
573 $settings{notifymail
} = $commitaddrs;
574 $settings{reverseorder
} = 1;
575 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
576 if !$defaults && $commitaddrs ne "";
577 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
578 if !$defaults && $commitaddrs ne "";
581 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
582 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
584 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
587 warn "using invalid tag notify email address list with --force\n" unless $quiet;
590 $settings{notifytag
} = $tagaddrs;
591 if (!$mirror && !$ispush) {
594 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
595 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
597 $settings{users
} = \
@newusers;
599 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
600 or die "Girocco::Project->ghost call failed\n";
602 $newproj->{$k} = $v while ($k, $v) = each(%settings);
603 my $killowner = sub {
604 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
605 'config', '--unset', "gitweb.owner");
608 $newproj->premirror or die "Girocco::Project->premirror failed\n";
609 !$noowner or &$killowner;
610 $newproj->clone or die "Girocco::Project->clone failed\n";
611 warn "Project $projname created and cloning successfully initiated.\n"
614 $newproj->conjure or die "Girocco::Project->conjure failed\n";
615 !$noowner or &$killowner;
616 warn "New push project fork is empty due to use of --no-alternates\n"
617 if !$quiet && $projname =~ m
,/, && $noalternates;
618 warn "Project $projname successfully created.\n" unless $quiet;
625 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
626 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
630 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
631 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
632 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
633 @ARGV or die "Please give project name on command line.\n";
634 my $projname = shift @ARGV;
635 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
636 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
637 defined($type) or $type = "";
639 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
640 $projdir = realpath
($projname);
641 $projname = $projdir;
642 $projname =~ s/\.git$//i;
643 $projname =~ s
,/+$,,;
644 $projname =~ s
,^.*/,,;
645 $projname ne "" or $projname = $projdir;
647 $projname =~ s/\.git$//i;
648 $projname ne "" or die "Invalid project name \"\".\n";
649 unless (Girocco
::Project
::does_exist
($projname, 1)) {
650 Girocco
::Project
::valid_name
($projname, 1, 1)
651 or die "Invalid project name \"$projname\".\n";
652 die "No such project to adopt: $projname\n";
654 defined(girocco
::Project
->load($projname))
655 and die "Project already known (no need to adopt): $projname\n";
656 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
657 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
659 my $config = read_config_file
($projdir . "/config");
661 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
662 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
663 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
664 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1, $quiet)];
666 if (-e
"$projdir/description") {
667 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
673 defined $desc or $desc = "";
675 $desc = to_utf8
($desc, 1);
676 is_default_desc
($desc) and $desc = "";
677 if ($desc ne "" && !valid_desc
($desc)) {
678 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
680 warn "using invalid 'description' file contents with --force\n" unless $quiet;
682 $desc = clean_desc
($desc);
683 if (length($desc) > 1024) {
684 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
686 warn "using longer than 1024 char description with --force\n" unless $quiet;
690 if (-e
"$projdir/README.html") {
691 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
697 defined $readme or $readme = "";
698 $readme = to_utf8
($readme, 1);
699 $readme =~ s/\r\n?/\n/gs;
700 $readme =~ s/^\s+//s;
701 $readme =~ s/\s+$//s;
702 $readme eq "" or $readme .= "\n";
703 if (length($readme) > 8192) {
704 die "readme greater than 8192 chars is too long (use --force to override)\n"
706 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
708 my $rd = get_readme_desc
($readme);
709 if ($rd ne "automatic" && $rd ne "suppressed") {
710 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
711 if (-f
$xmllint && -x
$xmllint) {
712 my $dummy = {README
=> $readme};
713 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
715 my $msg = "xmllint: $cnt error";
716 $msg .= "s" unless $cnt == 1;
717 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
718 unless $force && $quiet;
719 exit(255) unless $force;
720 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
723 die "xmllint not available, refusing to use raw HTML without --force\n"
725 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
729 # Inspect any remotes now
730 # Yes, Virginia, remote urls can be multi-valued
734 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
735 my ($name, $subkey) = ($1, $2);
736 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
737 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
738 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
739 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
740 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
742 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
743 # the remote names in a group are separated by runs of [ \t\n] characters
744 # remote names "", ".", ".." and any name starting with "/" are invalid
745 # a remote with no url or vcs setting is not considered valid
748 if (exists($config{"remotes
.default"})) {
749 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
750 next unless exists($remotes{$_});
751 my $rmt = $remotes{$_};
752 next if !exists($rmt->{url}) && !$rmt->{vcs};
760 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
761 next if $seenrmt{$1};
763 next unless exists($remotes{$1});
764 my $rmt = $remotes{$1};
765 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
769 my @needskip = (); # remotes that need skipDefaultUpdate set to true
772 my $foundfetchwithmirror = 0;
774 my $rmt = $remotes{$_};
775 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
776 next unless exists($rmt->{fetch});
778 ++$foundfetchwithmirror if $rmt->{mirror};
779 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
781 # if we have $foundvcs then we need to explicitly set fetch.prune to false
782 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
783 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
785 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
786 # if remote "origin
" exists we always pick up its first url or use ""
787 if (exists($remotes{origin})) {
788 my $rmt = $remotes{origin};
789 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
790 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
793 # get the first url of the @check remotes
795 my $rmt = $remotes{$_};
796 next unless exists($rmt->{url});
797 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
798 $baseurl = $rmt->{url}->[0];
802 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
804 # If we have $foundfetch we want to make a mirror but complain if
805 # we $foundfetchwithmirror as well unless we have --type=mirror.
806 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
807 # Warn if we need to set fetch.prune=false when making a mirror
808 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
809 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
810 # Warn if $usingall and any @needskip (and set them) if making a mirror
811 # Warn if making a mirror and $baseurl eq ""
812 # Warn if we have --type=mirror and !$foundfetch
815 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
816 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
817 if ($foundfetchwithmirror) {
818 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
819 "(Use
--type
=mirror to override
)\n"
820 unless $type eq "mirror
";
821 exit(255) unless $type eq "mirror
" || $dryrun;
822 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
823 unless $quiet || $type ne "mirror
";
825 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
826 if !$quiet && $neednoprune;
827 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
828 if !$quiet && $needfakeorigin;
829 if (!$usingall && @needskip) {
830 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
832 exit(255) unless $force || $dryrun;
833 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
834 unless $quiet || !$force;
836 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
837 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
839 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
840 if !$quiet && $foundfetch && !$foundfetchwithmirror;
843 if (!$noowner && !defined($owner)) {
845 $owner = $config{"gitweb
.owner
"};
846 if (!defined($owner) || $owner eq "") {
847 $owner = $Girocco::Config::admin;
848 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
851 if (!$nousers && !$makemirror && !defined($users)) {
852 # select user list for push project
853 my $findowner = $owner;
854 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
855 $findowner = lc($findowner) if defined($findowner);
856 my @owner_users = ();
857 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
858 if defined($findowner) && $findowner ne "";
859 if (@owner_users <= 1) {
860 $users = \@owner_users;
861 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
864 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
865 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
868 defined($users) or $users = [];
870 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
871 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
872 # and warn about preserving the setting)
874 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
875 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
876 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
877 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
878 $config{"receive
.denydeletecurrent
"} ne "warn";
880 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
881 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
882 if ($reflogactive || $reflogfiles) {
883 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
884 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
885 exit(255) unless $force || $dryrun;
886 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
887 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
890 return 0 if $dryrun && !$verbose;
892 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
893 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
894 $newproj->{desc} = $desc;
895 $newproj->{README} = $readme;
896 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
897 $newproj->{email} = $owner if defined($owner);
898 $newproj->{users} = $users;
899 $newproj->{crypt} = "unknown
";
900 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
901 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
902 my $dummy = bless {}, "Girocco
::Project
";
903 $dummy->{path} = "$projdir";
904 $dummy->{configfilehash} = \%config;
905 $dummy->_properties_load;
906 delete $dummy->{origurl};
907 foreach my $k (keys(%$dummy)) {
908 $newproj->{$k} = $dummy->{$k}
909 if exists($dummy->{$k}) && !exists($newproj->{$k});
914 my %info = %$newproj;
915 $info{README} = get_readme_desc($info{README}) if exists($info{README});
916 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
917 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
918 print $d->Dump([\%info], ['*'.$newproj->{name}]);
922 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
924 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
925 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
926 if ($usingall && @needskip) {
927 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
931 # Perform the actual adoption
932 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
934 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
935 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
936 if git_bool($config{"receive
.denynonfastforwards
"});
937 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
938 if exists($config{"receive
.denydeletecurrent
"}) &&
939 $config{"receive
.denydeletecurrent
"} ne "warn";
940 git_config($projdir, "core
.logAllRefUpdates
", "true
")
945 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
947 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
953 my ($force, $reallydel, $keepforks);
954 parse_options(force => \$force, "really
-delete" => \$reallydel,
955 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
956 @ARGV or die "Please give project name on command line
.\n";
957 @ARGV == 1 or die_usage;
958 my $project = get_project($ARGV[0]);
959 my $projname = $project->{name};
960 my $isempty = !$project->{mirror} && $project->is_empty;
961 if (!$project->{mirror} && !$isempty && $reallydel) {
962 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
963 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
967 if ($project->has_forks) {
968 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
969 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
970 # Run pseudo GC on that repository so that objects don't get lost within forks
971 my $basedir = $Girocco::Config::basedir;
972 my $projdir = $project->{path};
973 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
974 my $nogcrunning = sub {
975 die "Error: GC appears to be currently running on $projname\n"
976 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
979 $removenogc = ! -e "$projdir/.nogc";
980 recreate_file("$projdir/.nogc") if $removenogc;
981 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
982 delete $ENV{show_progress};
983 $ENV{'show_progress
'} = 1 unless $quiet;
986 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
987 or die "Running pseudo GC on project $projname failed\n";
991 if (!$project->{mirror} && !$isempty && !$reallydel) {
992 $archived = $project->archive_and_delete;
993 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
997 warn "Project '$projname' removed from $Girocco::Config::name" .
998 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
999 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1005 @ARGV == 1 or die_usage;
1006 my $project = get_clean_project($ARGV[0]);
1007 my %info = %$project;
1008 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1009 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1010 print $d->Dump([\%info], ['*'.$project->{name}]);
1015 @ARGV == 1 or die_usage;
1016 my $project = get_project($ARGV[0]);
1017 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1018 my $cur = $project->{HEAD};
1019 defined($cur) or $cur = '';
1021 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1022 defined($headhash) or $headhash = '';
1024 $headhash or $curmark = '!';
1026 my $mark = $_ eq $cur ? $curmark : ' ';
1034 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1035 @ARGV == 1 or die_usage;
1036 my $project = get_project($ARGV[0]);
1038 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1040 print map("$_\n", $project->get_ctag_names);
1047 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1048 @ARGV >= 2 or die_usage;
1049 my $project = get_project(shift @ARGV);
1052 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1054 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1058 my $ctags = join(" ", @ARGV);
1059 $ctags = lc($ctags) if $ic;
1060 foreach (split(/[\s,]+/, $ctags)) {
1061 next unless exists($curtags{$_});
1062 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1065 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1067 # Avoid touching anything other than the ctags
1068 foreach my $tg (@deltags) {
1069 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1071 $project->_set_changed;
1072 $project->_set_forkchange;
1073 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1079 @ARGV >= 2 or die_usage;
1080 my $project = get_project(shift @ARGV);
1081 my $ctags = join(" ", @ARGV);
1082 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1083 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1084 my $oldmask = umask();
1085 umask($oldmask & ~0060);
1087 foreach (split(/[\s,]+/, $ctags)) {
1088 ++$changed if $project->add_ctag($_, 1);
1091 $project->_set_changed;
1092 $project->_set_forkchange;
1095 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1096 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1100 sub _get_random_val {
1105 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1112 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1114 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1115 @ARGV == 1 or die_usage;
1116 my $project = get_project($ARGV[0]);
1117 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1118 if $project->is_password_locked;
1121 if ($random eq "random") {
1122 die "refusing to set random password without --force\n" unless $force;
1123 $rmsg = "set to random value";
1124 $newpw = _get_random_val($project);
1126 die "refusing to set password hash to '$random' without --force\n" unless $force;
1127 $rmsg = "hash set to '$random'";
1133 print "Changing admin password for project $ARGV[0]\n";
1134 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1135 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1136 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1137 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1138 "the admin passwords you have entered do not match each other.\n";
1142 defined($newpw) or die "missing new password on STDIN\n";
1146 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1147 my $old = $project->{crypt};
1148 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1149 if (defined($old) && $old eq $project->{crypt}) {
1150 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1152 # Avoid touching anything other than the password hash
1153 $project->_group_update;
1154 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1160 @ARGV == 1 or die_usage;
1161 my $project = get_project($ARGV[0]);
1162 my $pwhash = $project->{crypt};
1163 defined($pwhash) or $pwhash = "";
1164 if ($pwhash eq "") {
1165 warn $project->{name}, ": no password required\n" unless $quiet;
1168 if ($project->is_password_locked) {
1169 warn $project->{name}, ": password is locked\n" unless $quiet;
1174 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1175 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1178 defined($checkpw) or die "missing admin password on STDIN\n";
1181 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1182 warn "password check failure\n" unless $quiet;
1185 warn "admin password match\n" unless $quiet;
1190 my ($force, $auto, $redelta);
1191 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1192 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force);
1193 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1194 @ARGV or die "Please give project name on command line.\n";
1195 @ARGV == 1 or die_usage;
1196 my $project = get_project($ARGV[0]);
1197 $quiet or $ENV{"show_progress"} = 1;
1198 $force and $ENV{"force_gc"} = 1;
1199 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1200 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1202 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1203 $redelta and push(@args, "-f");
1204 my $lastgc = $project->{lastgc};
1205 system({$args[0]} @args) != 0 and return 1;
1206 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1208 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1210 system({$args[0]} @args) != 0 and return 1;
1218 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1219 @ARGV or die "Please give project name on command line.\n";
1220 @ARGV == 1 or die_usage
;
1221 my $project = get_project
($ARGV[0]);
1222 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1223 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1224 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1225 exit(255) unless $force;
1226 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1228 unlink($project->_clonefail_path);
1229 unlink($project->_clonelog_path);
1230 recreate_file
($project->_clonep_path);
1231 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1232 die "cannot connect to taskd.socket: $!\n";
1233 select((select($sock),$|=1)[0]);
1234 $sock->print("clone ".$project->{name
}."\n");
1235 # Just ignore reply, we are going to succeed anyway and the I/O
1236 # would apparently get quite hairy.
1240 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1246 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1247 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1248 my $project = get_project
($ARGV[0]);
1249 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1250 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1252 warn "using invalid owner/email with --force\n" unless $quiet;
1254 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1255 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1257 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1259 my $old = $project->{email
};
1261 print "$old\n" if defined($old);
1264 if (defined($old) && $old eq $ARGV[1]) {
1265 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1267 # Avoid touching anything other than "gitweb.owner"
1268 $project->_property_fput("email", $ARGV[1]);
1269 $project->_update_index;
1270 $project->_set_changed;
1271 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1278 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1279 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1280 my $project = get_project
(shift @ARGV);
1281 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1282 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1284 warn "using invalid description with --force\n" unless $quiet;
1286 my $desc = clean_desc
(join(" ", @ARGV));
1287 if (@ARGV && length($desc) > 1024) {
1288 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1290 warn "using longer than 1024 char description with --force\n" unless $quiet;
1292 my $old = $project->{desc
};
1294 print "$old\n" if defined($old);
1297 if (defined($old) && $old eq $desc) {
1298 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1300 # Avoid touching anything other than description file
1301 $project->_property_fput("desc", $desc);
1302 $project->_set_changed;
1303 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1310 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1311 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1312 my $project = get_project
($ARGV[0]);
1313 my $old = $project->{README
};
1315 chomp $old if defined($old);
1316 print "$old\n" if defined($old) && $old ne "";
1319 my ($new, $raw, $newname);
1321 if ($ARGV[1] eq "-") {
1325 $newname = "contents of <STDIN>";
1326 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1328 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1329 $new = "<!-- suppress -->";
1333 die "missing filename for README\n" unless $fn ne "";
1334 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1335 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1340 $newname = "contents of \"$fn\"";
1342 defined($new) or $new = '';
1343 $project->{README
} = to_utf8
($new, 1);
1344 $project->_cleanup_readme;
1345 if (length($project->{README
}) > 8192) {
1346 die "readme greater than 8192 chars is too long (use --force to override)\n"
1348 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1351 my $rd = get_readme_desc
($project->{README
});
1352 if ($rd ne "automatic" && $rd ne "suppressed") {
1353 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
1354 if (-f
$xmllint && -x
$xmllint) {
1355 my ($cnt, $err) = $project->_lint_readme(0);
1357 my $msg = "xmllint: $cnt error";
1358 $msg .= "s" unless $cnt == 1;
1359 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1360 unless $force && $quiet;
1361 exit(255) unless $force;
1362 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1365 die "xmllint not available, refusing to use raw HTML without --force\n"
1367 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1371 if (defined($old) && $old eq $project->{README
}) {
1372 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1374 # Avoid touching anything other than README.html file
1375 $project->_property_fput("README", $project->{README
});
1376 $project->_set_changed;
1377 my $desc = get_readme_desc
($project->{README
});
1379 $newname .= " ($desc)";
1383 warn $project->{name
}, ": README updated to $newname\n" unless $quiet;
1389 my ($proj, $newhead) = @_;
1390 my %okheads = map({($_ => 1)} $proj->get_heads);
1391 exists($okheads{$newhead});
1395 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1396 my $project = get_project
($ARGV[0]);
1397 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1398 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1400 my $old = $project->{HEAD
};
1402 print "$old\n" if defined($old);
1405 if (defined($old) && $old eq $ARGV[1]) {
1406 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1408 # Avoid touching anything other than the HEAD symref
1409 $project->set_HEAD($ARGV[1]);
1410 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1427 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1428 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1429 my $project = get_project
($ARGV[0]);
1430 if (!exists($boolfields{$ARGV[1]})) {
1431 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1433 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1434 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1436 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1438 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1439 die "invalid boolean value: \"$ARGV[2]\"\n";
1441 my $bool = clean_bool
($ARGV[2]);
1442 my $old = $project->{$ARGV[1]};
1444 print "$old\n" if defined($old);
1447 if (defined($old) && $old eq $bool) {
1448 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1450 # Avoid touching anything other than $ARGV[1] field
1451 $project->_property_fput($ARGV[1], $bool);
1452 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1457 sub cmd_setautogchack
{
1458 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1459 my $project = get_project
($ARGV[0]);
1460 my $aghok = $Girocco::Config
::autogchack
&&
1461 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1462 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1464 print "$old\n" if $aghok;
1468 if (lc($ARGV[1]) eq "unset") {
1471 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1472 $bool = clean_bool
($ARGV[1]);
1475 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1476 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1478 if ($old eq $bool) {
1479 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1481 if ($bool eq "unset") {
1482 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1483 'config', '--unset', "girocco.autogchack");
1485 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1486 'config', '--bool', "girocco.autogchack", $bool);
1489 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1494 my ($url, $type) = @_;
1495 $type ne 'baseurl' and return valid_web_url
($url);
1496 valid_repo_url
($url) or return 0;
1497 if ($Girocco::Config
::restrict_mirror_hosts
) {
1498 my $mh = extract_url_hostname
($url);
1499 is_dns_hostname
($mh) or return 0;
1500 !is_our_hostname
($mh) or return 0;
1508 baseurl
=> ["url" , 1],
1509 homepage
=> ["hp" , 0],
1510 notifyjson
=> ["notifyjson", 0],
1516 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1517 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1518 my $project = get_project
($ARGV[0]);
1519 if (!exists($urlfields{$ARGV[1]})) {
1520 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1522 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1523 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1525 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1527 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1528 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1530 warn "using invalid URL with --force\n" unless $quiet;
1532 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1534 print "$old\n" if defined($old);
1537 if (defined($old) && $old eq $ARGV[2]) {
1538 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1540 # Avoid touching anything other than $ARGV[1]'s field
1541 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1542 if ($ARGV[1] eq "baseurl") {
1543 $project->{url
} = $ARGV[2];
1544 $project->_set_bangagain;
1546 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1547 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1562 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1563 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1564 my $project = get_project
(shift @ARGV);
1565 my $field = shift @ARGV;
1566 if (!exists($msgsfields{$field})) {
1567 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1569 if (@ARGV && !valid_addrlist
(@ARGV)) {
1570 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1572 warn "using invalid email address list with --force\n" unless $quiet;
1574 my $old = $project->{$field};
1576 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1579 my $newlist = clean_addrlist
(join(" ",@ARGV));
1580 if (defined($old) && $old eq $newlist) {
1581 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1583 # Avoid touching anything other than $field's field
1584 $project->_property_fput($field, $newlist);
1585 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1592 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1593 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1594 my $project = get_project
(shift @ARGV);
1595 my $projname = $project->{name
};
1596 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
1599 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
1600 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1602 return 0 if !@ARGV && $project->{mirror
};
1603 my $oldusers = $project->{users
};
1604 if ($oldusers && ref($oldusers) eq "ARRAY") {
1605 $oldusers = join("\n", @
$oldusers);
1610 print "$oldusers\n" if $oldusers ne "";
1613 if ($oldusers eq join("\n", @newusers)) {
1614 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1616 # Avoid touching anything other than the users list
1617 $project->{users
} = \
@newusers;
1618 $project->_update_users;
1619 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1627 owner
=> [\
&cmd_setowner
, 0],
1628 desc
=> [\
&cmd_setdesc
, 0],
1629 description
=> [\
&cmd_setdesc
, 0],
1630 readme
=> [\
&cmd_setreadme
, 0],
1631 head
=> [\
&cmd_sethead
, 0],
1632 HEAD
=> [\
&cmd_sethead
, 0],
1633 cleanmirror
=> [\
&cmd_setbool
, 1],
1634 reverseorder
=> [\
&cmd_setbool
, 1],
1635 summaryonly
=> [\
&cmd_setbool
, 1],
1636 statusupdates
=> [\
&cmd_setbool
, 1],
1637 autogchack
=> [\
&cmd_setautogchack
, 0],
1638 baseurl
=> [\
&cmd_seturl
, 1],
1639 homepage
=> [\
&cmd_seturl
, 1],
1640 notifyjson
=> [\
&cmd_seturl
, 1],
1641 notifymail
=> [\
&cmd_setmsgs
, 1],
1642 notifytag
=> [\
&cmd_setmsgs
, 1],
1643 users
=> [\
&cmd_setusers
, 0],
1650 push(@newargs, shift) if @_ && $_[0] eq '--force';
1652 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
1653 push(@newargs, shift);
1654 shift unless ${$fieldnames{$field}}[1];
1656 diename
(($setopt ?
"set " : "get ") . $field);
1658 &{${$fieldnames{$field}}[0]}(@ARGV);
1673 create
=> \
&cmd_create
,
1674 adopt
=> \
&cmd_adopt
,
1675 remove
=> \
&cmd_remove
,
1676 trash
=> \
&cmd_remove
,
1677 delete => \
&cmd_remove
,
1679 listheads
=> \
&cmd_listheads
,
1680 listtags
=> \
&cmd_listtags
,
1681 listctags
=> \
&cmd_listtags
,
1682 deltags
=> \
&cmd_deltags
,
1683 delctags
=> \
&cmd_deltags
,
1684 addtags
=> \
&cmd_addtags
,
1685 addctags
=> \
&cmd_addtags
,
1686 chpass
=> \
&cmd_chpass
,
1687 checkpw
=> \
&cmd_checkpw
,
1689 remirror
=> \
&cmd_remirror
,
1690 setowner
=> \
&cmd_setowner
,
1691 setdesc
=> \
&cmd_setdesc
,
1692 setdescription
=> \
&cmd_setdesc
,
1693 setreadme
=> \
&cmd_setreadme
,
1694 sethead
=> \
&cmd_sethead
,
1695 setbool
=> \
&cmd_setbool
,
1696 setautogchack
=> \
&cmd_setautogchack
,
1697 setflag
=> \
&cmd_setbool
,
1698 seturl
=> \
&cmd_seturl
,
1699 setmsgs
=> \
&cmd_setmsgs
,
1700 setusers
=> \
&cmd_setusers
,
1707 my $bn = basename
($0);
1708 printf "%s version %s\n\n", $bn, $VERSION;
1715 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1716 dohelp
if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1717 my $command = shift;
1720 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1722 $command = "set" . $command;
1724 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1725 dohelp
if @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i && !Girocco
::Project
::does_exist
("help",1);
1726 &{$commands{$command}}(@ARGV);