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 | --recompress] <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 with --recompress a full gc uses pack-objects --no-reuse-object
116 (--no-reuse-delta and --no-reuse-object are accepted as aliases)
117 unless the global --quiet option is given show_progress=1 is used
119 update [--force] [--quiet | --summary] <project>
120 run the update.sh script on project <project>
121 with --force cause a fetch to always take place (force_update=1)
122 with --quiet only show errors (show_progress is left unset)
123 with --summary show progress and ref summary (show_progress=1)
124 with neither --quiet nor --summary show it all (show_progress=2)
126 remirror [--force] <project>
127 initiate a remirror of project <project>
129 [set]owner [--force] <project> <newowner>
130 set project <project> owner to <newowner>
131 without "set" and only 1 arg, just show current project owner
133 [set]desc [--force] <project> <newdesc>
134 set project <project> description to <newdesc>
135 without "set" and only 1 arg, just show current project desc
137 [set]readme [--force] <project> <newsetting>
138 set project <project> readme to <newsetting>
139 <newsetting> is automatic|suppressed|-|[@]filename
140 without "set" and only 2 args, just show current readme setting
142 [set]head <project> <newhead>
143 set project <project> HEAD symbolic ref to <newhead>
144 without "set" and only 1 arg, just show current project HEAD
146 [set]bool [--force] <project> <flagname> <boolvalue>
147 set project <project> boolean <flagname> to <boolvalue>
148 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
149 without "set" and only 2 args, just show current flag value
151 [set]hooks [--force] <project> local | global | <path>
152 set project <project> hookspath to local, global or <path>
153 without "set" and only 1 arg, just show current hookspath
155 [set]autogchack <project> <boolvalue> | unset
156 set project <project> autogchack to <boolvalue> or "unset" it
157 without "set" just show current autogchack setting if enabled
158 with "set" autogchack must be enabled in Config.pm for the
159 type of project and maintain-auto-gc-hack.sh is always run
161 [set]url [--force] <project> <urlname> <newurlvalue>
162 set project <project> url <urlname> to <newurlvalue>
163 <urlname> is baseurl|homepage|notifyjson
164 without "set" and only 2 args, just show current url value
166 [set]msgs [--force] <project> <msgsname> <eaddrlist>
167 set project <project> msgs <msgsname> to <addrlist>
168 <msgsname> is notifymail|notifytag
169 <eaddrlist> is space or comma separated list of email addresses
170 without "set" and only 2 args, just show current msgs value
172 [set]users [--force] <project> <newuserslist>
173 set push project <project> users list to <newuserslist>
174 <newuserslist> is space or comma separated list of user names
175 without "set" and only 1 arg, just show current users list
177 get <project> <fieldname>
178 show project <project> field <fieldname>
179 <fieldname> is owner|desc|readme|head|hooks|users
180 or <flagname>|autogchack|<urlname>|<msgsname>
182 set [--force] <project> <fieldname> <newfieldvalue>
183 set project <project> field <fieldname> to <newfieldvalue>
184 <fieldname> same as for get
185 <newfieldvalue> same as for corresponding set... command
191 my $sub = shift || diename
;
193 die "Invalid arguments to $sub command -- try \"help\"\n";
195 die "Invalid arguments -- try \"help\"\n";
199 sub get_readme_desc
{
201 defined($rm) or $rm = '';
204 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
206 return $test eq '' ?
"suppressed" : "length " . length($rm);
212 sub get_ctag_counts
{
216 foreach ($project->get_ctag_names) {
219 if (open $ct, '<', $project->{path
}."/ctags/$_") {
222 defined $count or $count = '';
224 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
230 push(@ctags, $_."(".$val.")");
233 push(@ctags, [$_, $val]) if $val;
239 sub get_clean_project
{
240 my $project = get_project
(@_);
241 delete $project->{loaded
};
242 delete $project->{base_path
};
243 delete $project->{ccrypt
};
244 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
245 $project->{owner
} = $project->{email
}; delete $project->{email
};
246 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
247 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
248 my $owner = $project->{owner
};
251 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
252 $project->{owner_users
} = \
@owner_users if @owner_users;
254 my $projname = $project->{name
};
255 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
256 $project->{has_forks
} = 1 if @forks;
257 $project->{has_alternates
} = 1 if $project->has_alternates;
258 my @bundles = $project->bundles;
259 delete $project->{bundles
};
260 $project->{bundles
} = \
@bundles if @bundles;
261 $project->{mirror
} = 0 unless $project->{mirror
};
262 $project->{is_empty
} = 1 if $project->is_empty;
263 delete $project->{showpush
} unless $project->{showpush
};
264 delete $project->{users
} if $project->{mirror
};
265 delete $project->{baseurl
} unless $project->{mirror
};
266 delete $project->{banged
} unless $project->{mirror
};
267 delete $project->{lastrefresh
} unless $project->{mirror
};
268 delete $project->{cleanmirror
} unless $project->{mirror
};
269 delete $project->{statusupdates
} unless $project->{mirror
};
270 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
271 unless ($project->{banged
}) {
272 delete $project->{bangcount
};
273 delete $project->{bangfirstfail
};
274 delete $project->{bangmessagesent
};
276 my $projhook = $project->_has_notifyhook;
277 if (defined($projhook) && $projhook ne "") {
278 $project->{notifyhook
} = $projhook;
280 delete $project->{notifyhook
};
282 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
283 my @tags = get_ctag_counts
($project, 1);
284 $project->{tags
} = \
@tags if @tags;
285 my $projconfig = read_config_file_hash
($project->{path
}."/config");
286 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
287 my $ahp = $projconfig->{"core.hookspath"};
288 my $rahp = realpath
($ahp);
289 my $lhp = $project->{path
}."/hooks";
290 my $rlhp = realpath
($lhp);
291 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
292 my $rghp = realpath
($ghp);
293 $project->{has_local_hooks
} = 1 if
294 defined($rahp) && defined($rlhp) && $rahp eq $rlhp;
295 $project->{has_global_hooks
} = 1 if
296 defined($rahp) && defined($rghp) && $rahp eq $rghp;
297 $project->{hookspath
} = $ahp unless $ahp eq $lhp || $ahp eq $ghp;
305 foreach (split(/[,\s]+/, $_[0])) {
307 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
309 return join(($_[1]||","), @newlist);
313 my $cleaned = clean_addrlist
(join(" ", @_));
314 return 1 if $cleaned eq "";
315 valid_email_multi
($cleaned) && length($cleaned) <= 512;
319 my ($userlist, $force, $nodie, $quiet) = @_;
323 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
324 my %users = map({($$_[1] => $_)} get_all_users
);
325 foreach (split(/[\s,]+/, $userlist)) {
326 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
327 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
330 if (Girocco
::User
::does_exist
($_, 1)) {
332 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
335 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
340 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
342 die if $badlist && !$nodie;
346 sub is_default_desc
{
347 # "Unnamed repository; edit this file 'description' to name the repository."
348 # "Unnamed repository; edit this file to name it for gitweb."
350 return 0 unless defined($_);
351 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
357 return 0 if $test =~ /[\r\n]/;
358 $test =~ s/\s\s+/ /g;
366 defined($desc) or $desc = '';
368 $desc = to_utf8
($desc, 1);
369 $desc =~ s/\s\s+/ /g;
376 Girocco
::CLIUtil
::_parse_options
(
378 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
386 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
387 name
=> sub {$$a[1] cmp $$b[1]},
388 gid
=> sub {$$a[3] <=> $$b[3]},
389 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
390 no => sub {$$a[0] <=> $$b[0]},
392 my $sortopt = 'lcname';
393 my ($verbose, $owner);
394 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
397 my $val = shift @ARGV;
398 $regex = qr
($val) or die "bad regex \"$val\"\n";
400 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
401 my $sortsub = $sortsub{$sortopt};
402 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
403 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
405 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
407 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
413 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
414 $ismirror, $desc, $fullmirror);
416 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
417 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
418 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
419 ":description" => \
$desc, "full-mirror" => \
$fullmirror);
420 @ARGV == 1 or die_usage
;
421 !defined($pushusers) || defined($ispush) or $ispush = 1;
422 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
423 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
424 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
425 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
426 !$defaults || defined($nopasswd) or $nopasswd = 1;
427 !$defaults || defined($noowner) or $noowner = 1;
428 !defined($ispush) || defined($pushusers) or $pushusers = "";
429 my $projname = $ARGV[0];
430 $projname =~ s/\.git$//i;
431 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
432 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
433 warn "Refusing to create orphan project without --orphan\n"
434 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
435 warn "Required orphan parent directory does not exist (use -p): ",
436 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
437 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
438 die "Invalid project name: \"$projname\"\n";
440 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
441 my $newtype = $forkee ?
'fork' : 'project';
442 if (length($project) > 64) {
443 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
445 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
447 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
448 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
449 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
451 print "Enter settings for new project \"$projname\"\n" unless $defaults;
453 $settings{noalternates
} = $noalternates;
455 $settings{crypt} = "unknown";
457 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
458 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
459 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
460 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
461 "the admin passwords you have entered do not match each other.\n";
462 $settings{crypt} = scrypt_sha1
($np1);
466 $owner = prompt_or_die
("Owner/email name for project $projname");
467 unless (valid_email
($owner)) {
469 warn "Your email sure looks weird...?\n";
472 warn "Allowing invalid email with --force\n" unless $quiet;
474 if (length($owner) > 96) {
476 warn "Your email is longer than 96 characters. Do you really need that much?\n";
479 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
482 $settings{email
} = $owner;
484 my $checkmirror = sub {
485 my $checkurl = shift;
486 unless (valid_repo_url
($checkurl)) {
488 warn "Invalid mirror URL: \"$checkurl\"\n";
491 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
493 if ($Girocco::Config
::restrict_mirror_hosts
) {
494 my $mh = extract_url_hostname
($checkurl);
495 unless (is_dns_hostname
($mh)) {
497 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
500 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
502 if (is_our_hostname
($mh)) {
504 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
507 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
512 if ($ispush || $ismirror) {
513 !$ispush || $force || $Girocco::Config
::push or
514 die "Push projects are disabled, create a mirror (or use --force)\n";
515 !$ismirror || $force || $Girocco::Config
::mirror
or
516 die "Mirror projects are disabled, create a push project (or use --force)\n";
518 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
519 $baseurl = $ismirror;
520 $settings{url
} = $baseurl;
521 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
524 if ($pushusers !~ /^[\s,]*$/) {
525 eval {@newusers = validate_users
($pushusers, $force); 1;} or
526 die "Invalid --push user list\n";
528 $settings{users
} = \
@newusers;
530 } elsif ($force || $Girocco::Config
::mirror
) {{
531 if ($force || $Girocco::Config
::push) {
532 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
534 $baseurl = prompt_or_die
("URL to mirror from");
535 unless ($baseurl ne "") {
536 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
540 if ($baseurl ne "") {
541 &$checkmirror($baseurl) or redo;
542 $settings{url
} = $baseurl;
543 $settings{cleanmirror
} =
544 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
547 my $mirror = ($baseurl eq "") ?
0 : 1;
548 my $checkdesc = sub {
550 if (length($d) > 1024) {
552 warn "Short description length greater than 1024 characters!\n";
555 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
559 if (defined($desc)) {
560 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
561 $desc eq "" || &$checkdesc($desc) or
562 die "Invalid --desc description\n";
563 } elsif (!$defaults) {
564 $desc = prompt_or_die
("Short description", "");
565 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
566 $desc eq "" || &$checkdesc($desc) or redo;
567 $desc = undef if $desc eq "";
569 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
570 $settings{desc
} = $desc;
573 $homepage = prompt_or_die
("Home page URL", "");
574 if ($homepage ne "" && !valid_web_url
($homepage)) {
576 warn "Invalid home page URL: \$homepage\"\n";
579 warn "Allowing invalid home page URL with --force\n" unless $quiet;
582 $settings{hp
} = $homepage;
585 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
586 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
588 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
591 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
594 $settings{notifyjson
} = $jsonurl;
595 my $commitaddrs = "";
597 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
598 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
600 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
603 warn "using invalid commit notify email address list with --force\n" unless $quiet;
606 $settings{notifymail
} = $commitaddrs;
607 $settings{reverseorder
} = 1;
608 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
609 if !$defaults && $commitaddrs ne "";
610 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
611 if !$defaults && $commitaddrs ne "";
614 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
615 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
617 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
620 warn "using invalid tag notify email address list with --force\n" unless $quiet;
623 $settings{notifytag
} = $tagaddrs;
624 if (!$mirror && !$ispush) {
627 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
628 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
630 $settings{users
} = \
@newusers;
632 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
633 or die "Girocco::Project->ghost call failed\n";
635 $newproj->{$k} = $v while ($k, $v) = each(%settings);
636 my $killowner = sub {
637 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
638 'config', '--unset', "gitweb.owner");
641 $newproj->premirror or die "Girocco::Project->premirror failed\n";
642 !$noowner or &$killowner;
643 $newproj->clone or die "Girocco::Project->clone failed\n";
644 warn "Project $projname created and cloning successfully initiated.\n"
647 $newproj->conjure or die "Girocco::Project->conjure failed\n";
648 !$noowner or &$killowner;
649 warn "New push project fork is empty due to use of --no-alternates\n"
650 if !$quiet && $projname =~ m
,/, && $noalternates;
651 warn "Project $projname successfully created.\n" unless $quiet;
658 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
659 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
663 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
664 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
665 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
666 @ARGV or die "Please give project name on command line.\n";
667 my $projname = shift @ARGV;
668 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
669 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
670 defined($type) or $type = "";
672 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
673 $projdir = realpath
($projname);
674 $projname = $projdir;
675 $projname =~ s/\.git$//i;
676 $projname =~ s
,/+$,,;
677 $projname =~ s
,^.*/,,;
678 $projname ne "" or $projname = $projdir;
680 $projname =~ s/\.git$//i;
681 $projname ne "" or die "Invalid project name \"\".\n";
682 unless (Girocco
::Project
::does_exist
($projname, 1)) {
683 Girocco
::Project
::valid_name
($projname, 1, 1)
684 or die "Invalid project name \"$projname\".\n";
685 die "No such project to adopt: $projname\n";
687 defined(Girocco
::Project
->load($projname))
688 and die "Project already known (no need to adopt): $projname\n";
689 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
690 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
692 my $config = read_config_file
($projdir . "/config");
694 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
695 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
696 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
697 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1, $quiet)];
699 if (-e
"$projdir/description") {
700 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
706 defined $desc or $desc = "";
708 $desc = to_utf8
($desc, 1);
709 is_default_desc
($desc) and $desc = "";
710 if ($desc ne "" && !valid_desc
($desc)) {
711 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
713 warn "using invalid 'description' file contents with --force\n" unless $quiet;
715 $desc = clean_desc
($desc);
716 if (length($desc) > 1024) {
717 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
719 warn "using longer than 1024 char description with --force\n" unless $quiet;
723 if (-e
"$projdir/README.html") {
724 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
730 defined $readme or $readme = "";
731 $readme = to_utf8
($readme, 1);
732 $readme =~ s/\r\n?/\n/gs;
733 $readme =~ s/^\s+//s;
734 $readme =~ s/\s+$//s;
735 $readme eq "" or $readme .= "\n";
736 if (length($readme) > 8192) {
737 die "readme greater than 8192 chars is too long (use --force to override)\n"
739 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
741 my $rd = get_readme_desc
($readme);
742 if ($rd ne "automatic" && $rd ne "suppressed") {
743 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
744 if (-f
$xmllint && -x
$xmllint) {
745 my $dummy = {README
=> $readme};
746 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
748 my $msg = "xmllint: $cnt error";
749 $msg .= "s" unless $cnt == 1;
750 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
751 unless $force && $quiet;
752 exit(255) unless $force;
753 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
756 die "xmllint not available, refusing to use raw HTML without --force\n"
758 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
762 # Inspect any remotes now
763 # Yes, Virginia, remote urls can be multi-valued
767 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
768 my ($name, $subkey) = ($1, $2);
769 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
770 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
771 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
772 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
773 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
775 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
776 # the remote names in a group are separated by runs of [ \t\n] characters
777 # remote names "", ".", ".." and any name starting with "/" are invalid
778 # a remote with no url or vcs setting is not considered valid
781 if (exists($config{"remotes
.default"})) {
782 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
783 next unless exists($remotes{$_});
784 my $rmt = $remotes{$_};
785 next if !exists($rmt->{url}) && !$rmt->{vcs};
793 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
794 next if $seenrmt{$1};
796 next unless exists($remotes{$1});
797 my $rmt = $remotes{$1};
798 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
802 my @needskip = (); # remotes that need skipDefaultUpdate set to true
805 my $foundfetchwithmirror = 0;
807 my $rmt = $remotes{$_};
808 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
809 next unless exists($rmt->{fetch});
811 ++$foundfetchwithmirror if $rmt->{mirror};
812 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
814 # if we have $foundvcs then we need to explicitly set fetch.prune to false
815 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
816 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
818 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
819 # if remote "origin
" exists we always pick up its first url or use ""
820 if (exists($remotes{origin})) {
821 my $rmt = $remotes{origin};
822 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
823 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
826 # get the first url of the @check remotes
828 my $rmt = $remotes{$_};
829 next unless exists($rmt->{url});
830 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
831 $baseurl = $rmt->{url}->[0];
835 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
837 # If we have $foundfetch we want to make a mirror but complain if
838 # we $foundfetchwithmirror as well unless we have --type=mirror.
839 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
840 # Warn if we need to set fetch.prune=false when making a mirror
841 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
842 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
843 # Warn if $usingall and any @needskip (and set them) if making a mirror
844 # Warn if making a mirror and $baseurl eq ""
845 # Warn if we have --type=mirror and !$foundfetch
848 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
849 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
850 if ($foundfetchwithmirror) {
851 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
852 "(Use
--type
=mirror to override
)\n"
853 unless $type eq "mirror
";
854 exit(255) unless $type eq "mirror
" || $dryrun;
855 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
856 unless $quiet || $type ne "mirror
";
858 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
859 if !$quiet && $neednoprune;
860 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
861 if !$quiet && $needfakeorigin;
862 if (!$usingall && @needskip) {
863 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
865 exit(255) unless $force || $dryrun;
866 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
867 unless $quiet || !$force;
869 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
870 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
872 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
873 if !$quiet && $foundfetch && !$foundfetchwithmirror;
876 if (!$noowner && !defined($owner)) {
878 $owner = $config{"gitweb
.owner
"};
879 if (!defined($owner) || $owner eq "") {
880 $owner = $Girocco::Config::admin;
881 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
884 if (!$nousers && !$makemirror && !defined($users)) {
885 # select user list for push project
886 my $findowner = $owner;
887 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
888 $findowner = lc($findowner) if defined($findowner);
889 my @owner_users = ();
890 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
891 if defined($findowner) && $findowner ne "";
892 if (@owner_users <= 1) {
893 $users = \@owner_users;
894 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
897 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
898 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
901 defined($users) or $users = [];
903 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
904 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
905 # and warn about preserving the setting)
907 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
908 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
909 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
910 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
911 $config{"receive
.denydeletecurrent
"} ne "warn";
913 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
914 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
915 if ($reflogactive || $reflogfiles) {
916 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
917 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
918 exit(255) unless $force || $dryrun;
919 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
920 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
923 return 0 if $dryrun && !$verbose;
925 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
926 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
927 $newproj->{desc} = $desc;
928 $newproj->{README} = $readme;
929 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
930 $newproj->{email} = $owner if defined($owner);
931 $newproj->{users} = $users;
932 $newproj->{crypt} = "unknown
";
933 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
934 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
935 my $dummy = bless {}, "Girocco
::Project
";
936 $dummy->{path} = "$projdir";
937 $dummy->{configfilehash} = \%config;
938 $dummy->_properties_load;
939 delete $dummy->{origurl};
940 foreach my $k (keys(%$dummy)) {
941 $newproj->{$k} = $dummy->{$k}
942 if exists($dummy->{$k}) && !exists($newproj->{$k});
947 my %info = %$newproj;
948 $info{README} = get_readme_desc($info{README}) if exists($info{README});
949 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
950 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
951 print $d->Dump([\%info], ['*'.$newproj->{name}]);
955 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
957 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
958 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
959 if ($usingall && @needskip) {
960 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
964 # Perform the actual adoption
965 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
967 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
968 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
969 if git_bool($config{"receive
.denynonfastforwards
"});
970 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
971 if exists($config{"receive
.denydeletecurrent
"}) &&
972 $config{"receive
.denydeletecurrent
"} ne "warn";
973 git_config($projdir, "core
.logAllRefUpdates
", "true
")
978 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
980 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
986 my ($force, $reallydel, $keepforks);
987 parse_options(force => \$force, "really
-delete" => \$reallydel,
988 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
989 @ARGV or die "Please give project name on command line
.\n";
990 @ARGV == 1 or die_usage;
991 my $project = get_project($ARGV[0]);
992 my $projname = $project->{name};
993 my $isempty = !$project->{mirror} && $project->is_empty;
994 if (!$project->{mirror} && !$isempty && $reallydel) {
995 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
996 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
1000 if ($project->has_forks) {
1001 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
1002 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
1003 # Run pseudo GC on that repository so that objects don't get lost within forks
1004 my $basedir = $Girocco::Config::basedir;
1005 my $projdir = $project->{path};
1006 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
1007 my $nogcrunning = sub {
1008 die "Error: GC appears to be currently running on $projname\n"
1009 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
1012 $removenogc = ! -e "$projdir/.nogc";
1013 recreate_file("$projdir/.nogc") if $removenogc;
1014 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
1015 delete $ENV{show_progress};
1016 $ENV{'show_progress
'} = 1 unless $quiet;
1019 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
1020 or die "Running pseudo GC on project $projname failed\n";
1024 if (!$project->{mirror} && !$isempty && !$reallydel) {
1025 $archived = $project->archive_and_delete;
1026 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1030 warn "Project '$projname' removed from $Girocco::Config::name" .
1031 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1032 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1038 @ARGV == 1 or die_usage;
1039 my $project = get_clean_project($ARGV[0]);
1040 my %info = %$project;
1041 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1042 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1043 print $d->Dump([\%info], ['*'.$project->{name}]);
1048 @ARGV == 1 or die_usage;
1049 my $project = get_project($ARGV[0]);
1050 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1051 my $cur = $project->{HEAD};
1052 defined($cur) or $cur = '';
1054 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1055 defined($headhash) or $headhash = '';
1057 $headhash or $curmark = '!';
1059 my $mark = $_ eq $cur ? $curmark : ' ';
1067 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1068 @ARGV == 1 or die_usage;
1069 my $project = get_project($ARGV[0]);
1071 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1073 print map("$_\n", $project->get_ctag_names);
1080 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1081 @ARGV >= 2 or die_usage;
1082 my $project = get_project(shift @ARGV);
1085 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1087 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1091 my $ctags = join(" ", @ARGV);
1092 $ctags = lc($ctags) if $ic;
1093 foreach (split(/[\s,]+/, $ctags)) {
1094 next unless exists($curtags{$_});
1095 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1098 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1100 # Avoid touching anything other than the ctags
1101 foreach my $tg (@deltags) {
1102 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1104 $project->_set_changed;
1105 $project->_set_forkchange;
1106 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1112 @ARGV >= 2 or die_usage;
1113 my $project = get_project(shift @ARGV);
1114 my $ctags = join(" ", @ARGV);
1115 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1116 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1117 my $oldmask = umask();
1118 umask($oldmask & ~0060);
1120 foreach (split(/[\s,]+/, $ctags)) {
1121 ++$changed if $project->add_ctag($_, 1);
1124 $project->_set_changed;
1125 $project->_set_forkchange;
1128 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1129 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1133 sub _get_random_val {
1138 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1145 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1147 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1148 @ARGV == 1 or die_usage;
1149 my $project = get_project($ARGV[0]);
1150 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1151 if $project->is_password_locked;
1154 if ($random eq "random") {
1155 die "refusing to set random password without --force\n" unless $force;
1156 $rmsg = "set to random value";
1157 $newpw = _get_random_val($project);
1159 die "refusing to set password hash to '$random' without --force\n" unless $force;
1160 $rmsg = "hash set to '$random'";
1166 print "Changing admin password for project $ARGV[0]\n";
1167 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1168 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1169 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1170 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1171 "the admin passwords you have entered do not match each other.\n";
1175 defined($newpw) or die "missing new password on STDIN\n";
1179 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1180 my $old = $project->{crypt};
1181 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1182 if (defined($old) && $old eq $project->{crypt}) {
1183 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1185 # Avoid touching anything other than the password hash
1186 $project->_group_update;
1187 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1193 @ARGV == 1 or die_usage;
1194 my $project = get_project($ARGV[0]);
1195 my $pwhash = $project->{crypt};
1196 defined($pwhash) or $pwhash = "";
1197 if ($pwhash eq "") {
1198 warn $project->{name}, ": no password required\n" unless $quiet;
1201 if ($project->is_password_locked) {
1202 warn $project->{name}, ": password is locked\n" unless $quiet;
1207 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1208 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1211 defined($checkpw) or die "missing admin password on STDIN\n";
1214 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1215 warn "password check failure\n" unless $quiet;
1218 warn "admin password match\n" unless $quiet;
1223 my ($force, $auto, $redelta, $recompress);
1224 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1225 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force,
1226 recompress => \$recompress, "no-reuse-object" => $recompress);
1227 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1228 @ARGV or die "Please give project name on command line.\n";
1229 @ARGV == 1 or die_usage;
1230 my $project = get_project($ARGV[0]);
1231 delete $ENV{show_progress};
1232 delete $ENV{force_gc};
1233 $quiet or $ENV{"show_progress"} = 1;
1234 $force and $ENV{"force_gc"} = 1;
1235 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1236 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1238 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1239 $redelta && !$recompress and push(@args, "-f");
1240 $recompress and push(@args, "-F");
1241 my $lastgc = $project->{lastgc};
1242 system({$args[0]} @args) != 0 and return 1;
1243 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1245 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1247 system({$args[0]} @args) != 0 and return 1;
1254 my ($force, $summary);
1255 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1256 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1257 @ARGV or die "Please give project name on command line.\n";
1258 @ARGV == 1 or die_usage
;
1259 my $project = get_project
($ARGV[0]);
1260 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1261 delete $ENV{show_progress
};
1262 delete $ENV{force_update
};
1264 $ENV{"show_progress"} = 0;
1266 $ENV{"show_progress"} = ($summary ?
1 : 2);
1268 $force and $ENV{"force_update"} = 1;
1269 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1275 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1276 @ARGV or die "Please give project name on command line.\n";
1277 @ARGV == 1 or die_usage
;
1278 my $project = get_project
($ARGV[0]);
1279 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1280 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1281 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1282 exit(255) unless $force;
1283 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1285 unlink($project->_clonefail_path);
1286 unlink($project->_clonelog_path);
1287 recreate_file
($project->_clonep_path);
1288 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1289 die "cannot connect to taskd.socket: $!\n";
1290 select((select($sock),$|=1)[0]);
1291 $sock->print("clone ".$project->{name
}."\n");
1292 # Just ignore reply, we are going to succeed anyway and the I/O
1293 # would apparently get quite hairy.
1297 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1303 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1304 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1305 my $project = get_project
($ARGV[0]);
1306 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1307 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1309 warn "using invalid owner/email with --force\n" unless $quiet;
1311 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1312 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1314 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1316 my $old = $project->{email
};
1318 print "$old\n" if defined($old);
1321 if (defined($old) && $old eq $ARGV[1]) {
1322 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1324 # Avoid touching anything other than "gitweb.owner"
1325 $project->_property_fput("email", $ARGV[1]);
1326 $project->_update_index;
1327 $project->_set_changed;
1328 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1335 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1336 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1337 my $project = get_project
(shift @ARGV);
1338 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1339 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1341 warn "using invalid description with --force\n" unless $quiet;
1343 my $desc = clean_desc
(join(" ", @ARGV));
1344 if (@ARGV && length($desc) > 1024) {
1345 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1347 warn "using longer than 1024 char description with --force\n" unless $quiet;
1349 my $old = $project->{desc
};
1351 print "$old\n" if defined($old);
1354 if (defined($old) && $old eq $desc) {
1355 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1357 # Avoid touching anything other than description file
1358 $project->_property_fput("desc", $desc);
1359 $project->_set_changed;
1360 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1367 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1368 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1369 my $project = get_project
($ARGV[0]);
1370 my $old = $project->{README
};
1372 chomp $old if defined($old);
1373 print "$old\n" if defined($old) && $old ne "";
1376 my ($new, $raw, $newname);
1378 if ($ARGV[1] eq "-") {
1382 $newname = "contents of <STDIN>";
1383 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1385 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1386 $new = "<!-- suppress -->";
1390 die "missing filename for README\n" unless $fn ne "";
1391 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1392 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1397 $newname = "contents of \"$fn\"";
1399 defined($new) or $new = '';
1400 $project->{README
} = to_utf8
($new, 1);
1401 $project->_cleanup_readme;
1402 if (length($project->{README
}) > 8192) {
1403 die "readme greater than 8192 chars is too long (use --force to override)\n"
1405 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1408 my $rd = get_readme_desc
($project->{README
});
1409 if ($rd ne "automatic" && $rd ne "suppressed") {
1410 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
1411 if (-f
$xmllint && -x
$xmllint) {
1412 my ($cnt, $err) = $project->_lint_readme(0);
1414 my $msg = "xmllint: $cnt error";
1415 $msg .= "s" unless $cnt == 1;
1416 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1417 unless $force && $quiet;
1418 exit(255) unless $force;
1419 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1422 die "xmllint not available, refusing to use raw HTML without --force\n"
1424 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1428 if (defined($old) && $old eq $project->{README
}) {
1429 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1431 # Avoid touching anything other than README.html file
1432 $project->_property_fput("README", $project->{README
});
1433 $project->_set_changed;
1434 my $desc = get_readme_desc
($project->{README
});
1436 $newname .= " ($desc)";
1440 warn $project->{name
}, ": README updated to $newname\n" unless $quiet;
1446 my ($proj, $newhead) = @_;
1447 my %okheads = map({($_ => 1)} $proj->get_heads);
1448 exists($okheads{$newhead});
1452 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1453 my $project = get_project
($ARGV[0]);
1454 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1455 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1457 my $old = $project->{HEAD
};
1459 print "$old\n" if defined($old);
1462 if (defined($old) && $old eq $ARGV[1]) {
1463 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1465 # Avoid touching anything other than the HEAD symref
1466 $project->set_HEAD($ARGV[1]);
1467 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1474 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1475 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1476 my $project = get_project
($ARGV[0]);
1477 my $projconfig = read_config_file_hash
($project->{path
}."/config");
1478 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
1479 my $rghp = realpath
($ghp);
1480 my $lhp = $project->{path
}."/hooks";
1481 my $rlhp = realpath
($lhp);
1484 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
1485 $ahp = $projconfig->{"core.hookspath"};
1486 $rahp = realpath
($ahp);
1489 if (defined($rahp) && $rahp ne "") {
1490 if ($rahp eq $rghp) {
1491 my $nc = ($ahp eq $ghp ?
"" : " non-canonical");
1492 printf "%s \t(global%s)\n", $ahp, $nc;
1493 } elsif ($rahp eq $rlhp) {
1494 my $nc = ($ahp eq $lhp ?
"" : " non-canonical");
1495 printf "%s \t(local%s)\n", $ahp, $nc;
1496 } elsif ($rahp ne $ahp) {
1497 print "$ahp \t($rahp)\n";
1501 } elsif ($ahp ne "") {
1502 print "$ahp \t(non-existent)\n";
1507 if (lc($shp) eq "global") {
1509 } elsif (lc($shp) eq "local") {
1511 } elsif (substr($shp, 0, 2) eq "~/") {
1512 $shp = $ENV{"HOME"}.substr($shp,1);
1513 } elsif ($shp =~ m
,^~([a
-zA
-Z_
][a
-zA
-Z_0
-9]*)((?
:/.*)?
)$,) {
1515 my $hd = (getpwnam($1))[7];
1516 $shp = $hd . $sfx if defined($hd) && $hd ne "" && $hd ne "/" && -d
$hd;
1518 $shp ne "" && -d
$shp or die "no such directory: $ARGV[1]\n";
1519 my $rshp = realpath
($shp);
1520 defined($rshp) && $rshp ne "" or die "could not realpath: $ARGV[1]\n";
1521 $rshp =~ m
,^/[^/], or die "invalid hookspath: $rshp\n";
1522 die "refusing to switch from current non-global hookspath without --force\n"
1523 if !$force && defined($rahp) && $rahp ne "" && $rahp ne $rghp && $rshp ne $rahp;
1524 if (!$force && defined($rahp) && $rahp ne "") {
1525 if ($rshp eq $rahp && ($ahp eq $ghp || $ahp eq $lhp)) {
1526 warn $project->{name
}, ": skipping update of hookspath to same effective value\n" unless $quiet;
1530 $rshp = $ghp if $rshp eq $rghp;
1531 $rshp = $lhp if $rshp eq $rlhp;
1532 if ($rshp eq $ahp) {
1533 warn $project->{name
}, ": skipping update of hookspath to same value\n" unless $quiet;
1536 die "refusing to set neither local nor global hookspath without --force\n"
1537 if !$force && $rshp ne $ghp && $rshp ne $lhp;
1538 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1539 'config', "core.hookspath", $rshp);
1540 my $newval = '"'.$rshp.'"';
1541 $newval = "global" if $rshp eq $ghp;
1542 $newval = "local" if $rshp eq $lhp;
1543 warn $project->{name
}, ": hookspath set to $newval\n" unless $quiet;
1559 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1560 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1561 my $project = get_project
($ARGV[0]);
1562 if (!exists($boolfields{$ARGV[1]})) {
1563 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1565 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1566 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1568 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1570 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1571 die "invalid boolean value: \"$ARGV[2]\"\n";
1573 my $bool = clean_bool
($ARGV[2]);
1574 my $old = $project->{$ARGV[1]};
1576 print "$old\n" if defined($old);
1579 if (defined($old) && $old eq $bool) {
1580 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1582 # Avoid touching anything other than $ARGV[1] field
1583 $project->_property_fput($ARGV[1], $bool);
1584 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1589 sub cmd_setautogchack
{
1590 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1591 my $project = get_project
($ARGV[0]);
1592 my $aghok = $Girocco::Config
::autogchack
&&
1593 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1594 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1596 print "$old\n" if $aghok;
1600 if (lc($ARGV[1]) eq "unset") {
1603 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1604 $bool = clean_bool
($ARGV[1]);
1607 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1608 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1610 if ($old eq $bool) {
1611 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1613 if ($bool eq "unset") {
1614 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1615 'config', '--unset', "girocco.autogchack");
1617 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1618 'config', '--bool', "girocco.autogchack", $bool);
1621 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1626 my ($url, $type) = @_;
1627 $type ne 'baseurl' and return valid_web_url
($url);
1628 valid_repo_url
($url) or return 0;
1629 if ($Girocco::Config
::restrict_mirror_hosts
) {
1630 my $mh = extract_url_hostname
($url);
1631 is_dns_hostname
($mh) or return 0;
1632 !is_our_hostname
($mh) or return 0;
1640 baseurl
=> ["url" , 1],
1641 homepage
=> ["hp" , 0],
1642 notifyjson
=> ["notifyjson", 0],
1648 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1649 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1650 my $project = get_project
($ARGV[0]);
1651 if (!exists($urlfields{$ARGV[1]})) {
1652 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1654 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1655 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1657 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1659 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1660 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1662 warn "using invalid URL with --force\n" unless $quiet;
1664 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1666 print "$old\n" if defined($old);
1669 if (defined($old) && $old eq $ARGV[2]) {
1670 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1672 # Avoid touching anything other than $ARGV[1]'s field
1673 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1674 if ($ARGV[1] eq "baseurl") {
1675 $project->{url
} = $ARGV[2];
1676 $project->_set_bangagain;
1678 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1679 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1694 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1695 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1696 my $project = get_project
(shift @ARGV);
1697 my $field = shift @ARGV;
1698 if (!exists($msgsfields{$field})) {
1699 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1701 if (@ARGV && !valid_addrlist
(@ARGV)) {
1702 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1704 warn "using invalid email address list with --force\n" unless $quiet;
1706 my $old = $project->{$field};
1708 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1711 my $newlist = clean_addrlist
(join(" ",@ARGV));
1712 if (defined($old) && $old eq $newlist) {
1713 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1715 # Avoid touching anything other than $field's field
1716 $project->_property_fput($field, $newlist);
1717 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1724 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1725 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1726 my $project = get_project
(shift @ARGV);
1727 my $projname = $project->{name
};
1728 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
1731 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
1732 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1734 return 0 if !@ARGV && $project->{mirror
};
1735 my $oldusers = $project->{users
};
1736 if ($oldusers && ref($oldusers) eq "ARRAY") {
1737 $oldusers = join("\n", @
$oldusers);
1742 print "$oldusers\n" if $oldusers ne "";
1745 if ($oldusers eq join("\n", @newusers)) {
1746 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1748 # Avoid touching anything other than the users list
1749 $project->{users
} = \
@newusers;
1750 $project->_update_users;
1751 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1759 owner
=> [\
&cmd_setowner
, 0],
1760 desc
=> [\
&cmd_setdesc
, 0],
1761 description
=> [\
&cmd_setdesc
, 0],
1762 readme
=> [\
&cmd_setreadme
, 0],
1763 head
=> [\
&cmd_sethead
, 0],
1764 HEAD
=> [\
&cmd_sethead
, 0],
1765 hooks
=> [\
&cmd_sethooks
, 0],
1766 hookspath
=> [\
&cmd_sethooks
, 0],
1767 cleanmirror
=> [\
&cmd_setbool
, 1],
1768 reverseorder
=> [\
&cmd_setbool
, 1],
1769 summaryonly
=> [\
&cmd_setbool
, 1],
1770 statusupdates
=> [\
&cmd_setbool
, 1],
1771 autogchack
=> [\
&cmd_setautogchack
, 0],
1772 baseurl
=> [\
&cmd_seturl
, 1],
1773 homepage
=> [\
&cmd_seturl
, 1],
1774 notifyjson
=> [\
&cmd_seturl
, 1],
1775 notifymail
=> [\
&cmd_setmsgs
, 1],
1776 notifytag
=> [\
&cmd_setmsgs
, 1],
1777 users
=> [\
&cmd_setusers
, 0],
1784 push(@newargs, shift) if @_ && $_[0] eq '--force';
1786 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
1787 push(@newargs, shift);
1788 shift unless ${$fieldnames{$field}}[1];
1790 diename
(($setopt ?
"set " : "get ") . $field);
1792 &{${$fieldnames{$field}}[0]}(@ARGV);
1807 create
=> \
&cmd_create
,
1808 adopt
=> \
&cmd_adopt
,
1809 remove
=> \
&cmd_remove
,
1810 trash
=> \
&cmd_remove
,
1811 delete => \
&cmd_remove
,
1813 listheads
=> \
&cmd_listheads
,
1814 listtags
=> \
&cmd_listtags
,
1815 listctags
=> \
&cmd_listtags
,
1816 deltags
=> \
&cmd_deltags
,
1817 delctags
=> \
&cmd_deltags
,
1818 addtags
=> \
&cmd_addtags
,
1819 addctags
=> \
&cmd_addtags
,
1820 chpass
=> \
&cmd_chpass
,
1821 checkpw
=> \
&cmd_checkpw
,
1823 update
=> \
&cmd_update
,
1824 remirror
=> \
&cmd_remirror
,
1825 setowner
=> \
&cmd_setowner
,
1826 setdesc
=> \
&cmd_setdesc
,
1827 setdescription
=> \
&cmd_setdesc
,
1828 setreadme
=> \
&cmd_setreadme
,
1829 sethead
=> \
&cmd_sethead
,
1830 sethooks
=> \
&cmd_sethooks
,
1831 sethookspath
=> \
&cmd_sethooks
,
1832 setbool
=> \
&cmd_setbool
,
1833 setboolean
=> \
&cmd_setbool
,
1834 setflag
=> \
&cmd_setbool
,
1835 setautogchack
=> \
&cmd_setautogchack
,
1836 seturl
=> \
&cmd_seturl
,
1837 setmsgs
=> \
&cmd_setmsgs
,
1838 setusers
=> \
&cmd_setusers
,
1845 my $bn = basename
($0);
1846 printf "%s version %s\n\n", $bn, $VERSION;
1853 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1854 dohelp
if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1855 my $command = shift;
1858 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1860 $command = "set" . $command;
1862 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1863 dohelp
if @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i && !Girocco
::Project
::does_exist
("help",1);
1864 &{$commands{$command}}(@ARGV);