3 # projtool.pl - command line Girocco project maintenance tool
4 # Copyright (C) 2016,2017,2020 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.1'}
15 use Digest::MD5 qw(md5_hex);
18 use POSIX
qw(strftime);
19 use lib
"__BASEDIR__";
22 use Girocco
::HashUtil
;
27 exit(&main
(@ARGV)||0);
30 BEGIN {$help = <<'HELP'}
31 Usage: %s [--quiet] <command> <options>
34 show full help or just for <command> if given
36 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
37 list all projects (default is --sort=lcname)
38 limit to project names matching <regex> if given
39 match <regex> against owner instead of project name with --owner
41 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
42 create new project <project> (prompted)
44 --no-alternates skip setup of objects/info/alternates
45 --orphan allow creation of subproject w/o a parent
46 -p use mkdir -p during --orphan creation
47 --no-password set password crypt to invalid value "unknown"
48 --no-owner leave the gitweb.owner config unset
49 --mirror=<url> create a mirror from <url>
50 --full-mirror mirror all refs
51 --push[=<list>] create a push project
52 --desc=<string> specify project description w/o prompt
53 --defaults do no interactive prompting at all
54 Using --no-password skips the prompts for password, using
55 --no-owner skips the prompt for owner and using --mirror=<url>
56 or --push[=<list>] skips the prompts for mirror URL and
57 heads-only and push users. With --defaults if neither
58 --mirror=<url> nor --push[=<list>] is given then --push will
59 be implied. Using --desc=<string> will force a specific
60 description (including an empty string) and skip the prompt for
61 it. Otherwise a non-empty default description will always be
62 supplied in lieu of an empty or omitted description.
64 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
65 adopt project <project>
66 type of project is guessed if --type=<type> omitted
67 <users> is same as <newuserslist> for setusers command
69 --dry-run do all the checks but don't perform adoption
70 --verbose show project info dump (useful with --dry-run)
71 --no-users no push users at all (<users> must be omitted)
72 --no-owner leave the gitweb.owner config totally unchanged
73 --owner=<val> set the gitweb.owner config to <val>
74 Both --no-owner and --owner=<val> may NOT be given, with neither
75 take owner from preexisting gitweb.owner else use admin setting.
76 For mirrors <users> is ignored otherwise if no <users> and no
77 --no-users option the push users list will consist of the single
78 user name matching the owner or empty if none or more than one.
79 With --dry-run <project> can be an absolute path to a git dir.
81 remove [--force] [--really-delete] [--keep-forks] <project>
82 remove project <project>
83 do not move to _recyclebin with --really-delete (just rm -rf)
84 remove projects with forks (by keeping forks) using --keep-forks
87 show project <project>
90 list all available heads for <project> and indicate current head
92 listtags [--verbose] <project>
93 list all ctags on project <project>
95 deltags <project> [-i] <tagstodel>
96 remove any ctags on project <project> present in <tagstodel>
97 <tagstodel> is space or comma separated list of tags to remove
98 with -i match against <tagstodel> without regard to letter case
100 addtags <project> <tagstoadd>
101 add ctags to project <project>
102 <tagstoadd> is space or comma separated list of tags to add
104 chpass [--force] <project> [random | unknown]
105 change project <project> password (prompted)
106 with "random" set to random password
107 with "unknown" set password hash to invalid value "unknown"
110 check project <project> password for a match (prompted)
112 gc [--force | --auto] [--redelta | --recompress] <project>
113 run the gc.sh script on project <project>
114 with --auto let the gc.sh script decide what to do
115 with --force cause a full gc to take place (force_gc=1)
116 with neither --auto nor --force do a mini or if needed a full gc
117 (in other words just touch .needsgc and run gc.sh)
118 with --redelta a full gc will use pack-objects --no-reuse-delta
119 with --recompress a full gc uses pack-objects --no-reuse-object
120 (--no-reuse-delta and --no-reuse-object are accepted as aliases)
121 unless the global --quiet option is given show_progress=1 is used
123 update [--force] [--quiet | --summary] <project>
124 run the update.sh script on project <project>
125 with --force cause a fetch to always take place (force_update=1)
126 with --quiet only show errors (show_progress is left unset)
127 with --summary show progress and ref summary (show_progress=1)
128 with neither --quiet nor --summary show it all (show_progress=2)
130 remirror [--force] <project>
131 initiate a remirror of project <project>
133 [set]owner [--force] <project> <newowner>
134 set project <project> owner to <newowner>
135 without "set" and only 1 arg, just show current project owner
137 [set]desc [--force] <project> <newdesc>
138 set project <project> description to <newdesc>
139 without "set" and only 1 arg, just show current project desc
141 [set]readme [--force] <project> <newsetting>
142 set project <project> readme to <newsetting>
143 <newsetting> is automatic|suppressed|-|[@]filename
144 without "set" and only 2 args, just show current readme setting
146 [set]head <project> <newhead>
147 set project <project> HEAD symbolic ref to <newhead>
148 without "set" and only 1 arg, just show current project HEAD
150 [set]bool [--force] <project> <flagname> <boolvalue>
151 set project <project> boolean <flagname> to <boolvalue>
152 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
153 without "set" and only 2 args, just show current flag value
155 [set]hooks [--force] <project> local | global | <path>
156 set project <project> hookspath to local, global or <path>
157 without "set" and only 1 arg, just show current hookspath
159 [set]autogchack <project> <boolvalue> | unset
160 set project <project> autogchack to <boolvalue> or "unset" it
161 without "set" just show current autogchack setting if enabled
162 with "set" autogchack must be enabled in Config.pm for the
163 type of project and maintain-auto-gc-hack.sh is always run
165 [set]url [--force] <project> <urlname> <newurlvalue>
166 set project <project> url <urlname> to <newurlvalue>
167 <urlname> is baseurl|homepage|notifyjson
168 without "set" and only 2 args, just show current url value
170 [set]msgs [--force] <project> <msgsname> <eaddrlist>
171 set project <project> msgs <msgsname> to <addrlist>
172 <msgsname> is notifymail|notifytag
173 <eaddrlist> is space or comma separated list of email addresses
174 without "set" and only 2 args, just show current msgs value
176 [set]users [--force] <project> <newuserslist>
177 set push project <project> users list to <newuserslist>
178 <newuserslist> is space or comma separated list of user names
179 without "set" and only 1 arg, just show current users list
181 get <project> <fieldname>
182 show project <project> field <fieldname>
183 <fieldname> is owner|desc|readme|head|hooks|users
184 or <flagname>|autogchack|<urlname>|<msgsname>
186 set [--force] <project> <fieldname> <newfieldvalue>
187 set project <project> field <fieldname> to <newfieldvalue>
188 <fieldname> same as for get
189 <newfieldvalue> same as for corresponding set... command
195 my $sub = shift || diename
;
197 die "Invalid arguments to $sub command -- try \"help\"\n";
199 die "Invalid arguments -- try \"help\"\n";
203 sub get_readme_desc
{
205 defined($rm) or $rm = '';
208 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
210 return $test eq '' ?
"suppressed" : "length " . length($rm);
216 sub get_ctag_counts
{
220 foreach ($project->get_ctag_names) {
223 if (open $ct, '<', $project->{path
}."/ctags/$_") {
226 defined $count or $count = '';
228 $val = $count =~ /^[1-9]\d*$/ ?
$count : 1;
234 push(@ctags, $_."(".$val.")");
237 push(@ctags, [$_, $val]) if $val;
243 sub get_clean_project
{
244 my $project = get_project
(@_);
245 delete $project->{loaded
};
246 delete $project->{base_path
};
247 delete $project->{ccrypt
};
248 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
249 $project->{owner
} = $project->{email
}; delete $project->{email
};
250 $project->{homepage
} = $project->{hp
}; delete $project->{hp
};
251 $project->{baseurl
} = $project->{url
}; delete $project->{url
};
252 my $owner = $project->{owner
};
255 my @owner_users = map {$owner eq lc($$_[4]) ?
$$_[1] : ()} get_all_users
;
256 $project->{owner_users
} = \
@owner_users if @owner_users;
258 my $projname = $project->{name
};
259 my @forks = grep {$$_[1] =~ m
,^$projname/,} get_all_projects
;
260 $project->{has_forks
} = 1 if @forks;
261 $project->{has_alternates
} = 1 if $project->has_alternates;
262 my @bundles = $project->bundles;
263 for (my $i = 0; $i < @bundles; ++$i) {
264 my $secs = $bundles[$i]->[0];
265 $bundles[$i]->[0] = strftime
("%Y-%m-%dT%H:%M:%S%z", localtime($secs));
267 delete $project->{bundles
};
268 $project->{bundles
} = \
@bundles if @bundles;
269 $project->{mirror
} = 0 unless $project->{mirror
};
270 $project->{is_empty
} = 1 if $project->is_empty;
271 delete $project->{showpush
} unless $project->{showpush
};
272 delete $project->{users
} if $project->{mirror
};
273 delete $project->{baseurl
} unless $project->{mirror
};
274 delete $project->{banged
} unless $project->{mirror
};
275 delete $project->{lastrefresh
} unless $project->{mirror
};
276 delete $project->{cleanmirror
} unless $project->{mirror
};
277 delete $project->{statusupdates
} unless $project->{mirror
};
278 delete $project->{lastparentgc
} unless $projname =~ m
,/,;
279 unless ($project->{banged
}) {
280 delete $project->{bangcount
};
281 delete $project->{bangfirstfail
};
282 delete $project->{bangmessagesent
};
284 my $projhook = $project->_has_notifyhook;
285 if (defined($projhook) && $projhook ne "") {
286 $project->{notifyhook
} = $projhook;
288 delete $project->{notifyhook
};
290 $project->{README
} = get_readme_desc
($project->{README
}) if exists($project->{README
});
291 my @tags = get_ctag_counts
($project, 1);
292 $project->{tags
} = \
@tags if @tags;
293 my $projconfig = read_config_file_hash
($project->{path
}."/config");
294 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
295 my $ahp = $projconfig->{"core.hookspath"};
296 my $rahp = realpath
($ahp);
297 my $lhp = $project->{path
}."/hooks";
298 my $rlhp = realpath
($lhp);
299 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
300 my $rghp = realpath
($ghp);
301 $project->{has_local_hooks
} = 1 if
302 defined($rahp) && defined($rlhp) && $rahp eq $rlhp;
303 $project->{has_global_hooks
} = 1 if
304 defined($rahp) && defined($rghp) && $rahp eq $rghp;
305 $project->{hookspath
} = $ahp unless $ahp eq $lhp || $ahp eq $ghp;
313 foreach (split(/[,\s]+/, $_[0])) {
315 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
317 return join(($_[1]||","), @newlist);
321 my $cleaned = clean_addrlist
(join(" ", @_));
322 return 1 if $cleaned eq "";
323 valid_email_multi
($cleaned) && length($cleaned) <= 512;
327 my ($userlist, $force, $nodie, $quiet) = @_;
331 my $mobok = $Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob";
332 my %users = map({($$_[1] => $_)} get_all_users
);
333 foreach (split(/[\s,]+/, $userlist)) {
334 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
335 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
338 if (Girocco
::User
::does_exist
($_, 1)) {
340 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
343 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
348 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
350 die if $badlist && !$nodie;
354 sub is_default_desc
{
355 # "Unnamed repository; edit this file 'description' to name the repository."
356 # "Unnamed repository; edit this file to name it for gitweb."
358 return 0 unless defined($_);
359 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
365 return 0 if $test =~ /[\r\n]/;
366 $test =~ s/\s\s+/ /g;
374 defined($desc) or $desc = '';
376 $desc = to_utf8
($desc, 1);
377 $desc =~ s/\s\s+/ /g;
384 Girocco
::CLIUtil
::_parse_options
(
386 warn((($_[0]eq'?')?
"unrecognized":"missing argument for")." option \"$_[1]\"\n")
394 lcname
=> sub {lc($$a[1]) cmp lc($$b[1])},
395 name
=> sub {$$a[1] cmp $$b[1]},
396 gid
=> sub {$$a[3] <=> $$b[3]},
397 owner
=> sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
398 no => sub {$$a[0] <=> $$b[0]},
400 my $sortopt = 'lcname';
401 my ($verbose, $owner);
402 parse_options
(":sort" => \
$sortopt, verbose
=> \
$verbose, owner
=> \
$owner);
405 my $val = shift @ARGV;
406 $regex = qr
($val) or die "bad regex \"$val\"\n";
408 !@ARGV && exists($sortsub{$sortopt}) or die_usage
;
409 my $sortsub = $sortsub{$sortopt};
410 my $grepsub = defined($regex) ?
($owner ?
sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
411 my @projects = sort($sortsub grep {&$grepsub} get_all_projects
);
413 print map(sprintf("%s\n", join(":", (@
$_)[1..5])), @projects);
415 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ?
"<mirror>" : $$_[5]), @projects);
421 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
422 $ismirror, $desc, $fullmirror);
424 force
=> \
$force, "no-alternates" => \
$noalternates, orphan
=> \
$orphanok, p
=> \
$optp,
425 "no-password" => \
$nopasswd, "no-owner" => \
$noowner, defaults
=> \
$defaults,
426 "push" => \
$ispush, ":push" => \
$pushusers, ":mirror" => \
$ismirror, ":desc" => \
$desc,
427 ":description" => \
$desc, "full-mirror" => \
$fullmirror);
428 @ARGV == 1 or die_usage
;
429 !defined($pushusers) || defined($ispush) or $ispush = 1;
430 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
431 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
432 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
433 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
434 !$defaults || defined($nopasswd) or $nopasswd = 1;
435 !$defaults || defined($noowner) or $noowner = 1;
436 !defined($ispush) || defined($pushusers) or $pushusers = "";
437 my $projname = $ARGV[0];
438 $projname =~ s/\.git$//i;
439 Girocco
::Project
::does_exist
($projname, 1) and die "Project already exists: \"$projname\"\n";
440 if (!Girocco
::Project
::valid_name
($projname, $orphanok, $optp)) {
441 warn "Refusing to create orphan project without --orphan\n"
442 if !$quiet && !$orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
443 warn "Required orphan parent directory does not exist (use -p): ",
444 $Girocco::Config
::reporoot
.'/'.Girocco
::Project
::get_forkee_name
($projname), "\n"
445 if !$quiet && $orphanok && Girocco
::Project
::valid_name
($projname, 1, 1);
446 die "Invalid project name: \"$projname\"\n";
448 my ($forkee, $project) = ($projname =~ m
#^(.*/)?([^/]+)$#);
449 my $newtype = $forkee ?
'fork' : 'project';
450 if (length($project) > 64) {
451 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
453 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
455 unless ($Girocco::Config
::push || $Girocco::Config
::mirror
) {
456 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
457 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
459 print "Enter settings for new project \"$projname\"\n" unless $defaults;
461 $settings{noalternates
} = $noalternates;
463 $settings{crypt} = "unknown";
465 my $np1 = prompt_noecho_nl_or_die
("Admin password for project $projname (echo is off)");
466 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
467 my $np2 = prompt_noecho_nl_or_die
("Retype admin password for project $projname");
468 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
469 "the admin passwords you have entered do not match each other.\n";
470 $settings{crypt} = scrypt_sha1
($np1);
474 $owner = prompt_or_die
("Owner/email name for project $projname");
475 unless (valid_email
($owner)) {
477 warn "Your email sure looks weird...?\n";
480 warn "Allowing invalid email with --force\n" unless $quiet;
482 if (length($owner) > 96) {
484 warn "Your email is longer than 96 characters. Do you really need that much?\n";
487 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
490 $settings{email
} = $owner;
492 my $checkmirror = sub {
493 my $checkurl = shift;
494 unless (valid_repo_url
($checkurl)) {
496 warn "Invalid mirror URL: \"$checkurl\"\n";
499 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
501 if ($Girocco::Config
::restrict_mirror_hosts
) {
502 my $mh = extract_url_hostname
($checkurl);
503 unless (is_dns_hostname
($mh)) {
505 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
508 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
510 if (is_our_hostname
($mh)) {
512 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
515 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
520 if ($ispush || $ismirror) {
521 !$ispush || $force || $Girocco::Config
::push or
522 die "Push projects are disabled, create a mirror (or use --force)\n";
523 !$ismirror || $force || $Girocco::Config
::mirror
or
524 die "Mirror projects are disabled, create a push project (or use --force)\n";
526 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
527 $baseurl = $ismirror;
528 $settings{url
} = $baseurl;
529 $settings{cleanmirror
} = $fullmirror ?
0 : 1;
532 if ($pushusers !~ /^[\s,]*$/) {
533 eval {@newusers = validate_users
($pushusers, $force); 1;} or
534 die "Invalid --push user list\n";
536 $settings{users
} = \
@newusers;
538 } elsif ($force || $Girocco::Config
::mirror
) {{
539 if ($force || $Girocco::Config
::push) {
540 $baseurl = prompt_or_die
("URL to mirror from (leave blank for push project)", "");
542 $baseurl = prompt_or_die
("URL to mirror from");
543 unless ($baseurl ne "") {
544 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
548 if ($baseurl ne "") {
549 &$checkmirror($baseurl) or redo;
550 $settings{url
} = $baseurl;
551 $settings{cleanmirror
} =
552 ynprompt_or_die
("Mirror only heads, tags and notes (Y/n)", "Yes");
555 my $mirror = ($baseurl eq "") ?
0 : 1;
556 my $checkdesc = sub {
558 if (length($d) > 1024) {
560 warn "Short description length greater than 1024 characters!\n";
563 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
567 if (defined($desc)) {
568 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
569 $desc eq "" || &$checkdesc($desc) or
570 die "Invalid --desc description\n";
571 } elsif (!$defaults) {
572 $desc = prompt_or_die
("Short description", "");
573 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
574 $desc eq "" || &$checkdesc($desc) or redo;
575 $desc = undef if $desc eq "";
577 defined($desc) or $desc = $mirror ?
"Mirror of $baseurl" : "Push project $projname";
578 $settings{desc
} = $desc;
581 $homepage = prompt_or_die
("Home page URL", "");
582 if ($homepage ne "" && !valid_web_url
($homepage)) {
584 warn "Invalid home page URL: \$homepage\"\n";
587 warn "Allowing invalid home page URL with --force\n" unless $quiet;
590 $settings{hp
} = $homepage;
593 $jsonurl = prompt_or_die
("JSON notify POST URL", "");
594 if ($jsonurl ne "" && !valid_web_url
($jsonurl)) {
596 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
599 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
602 $settings{notifyjson
} = $jsonurl;
603 my $commitaddrs = "";
605 $commitaddrs = clean_addrlist
(prompt_or_die
("Commit notify email addr(s)", ""));
606 if ($commitaddrs ne "" && !valid_addrlist
($commitaddrs)) {
608 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
611 warn "using invalid commit notify email address list with --force\n" unless $quiet;
614 $settings{notifymail
} = $commitaddrs;
615 $settings{reverseorder
} = 1;
616 $settings{reverseorder
} = ynprompt_or_die
("Oldest-to-newest commit order in emails", "Yes")
617 if !$defaults && $commitaddrs ne "";
618 $settings{summaryonly
} = ynprompt_or_die
("Summary only (no diff) in emails", "No")
619 if !$defaults && $commitaddrs ne "";
622 $tagaddrs = clean_addrlist
(prompt_or_die
("Tag notify email addr(s)", ""));
623 if ($tagaddrs ne "" && !valid_addrlist
($tagaddrs)) {
625 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
628 warn "using invalid tag notify email address list with --force\n" unless $quiet;
631 $settings{notifytag
} = $tagaddrs;
632 if (!$mirror && !$ispush) {
635 my $userlist = prompt_or_die
("Push users", join(",", @newusers));
636 eval {@newusers = validate_users
($userlist, $force); 1;} or redo;
638 $settings{users
} = \
@newusers;
640 my $newproj = Girocco
::Project
->ghost($projname, $mirror, $orphanok, $optp)
641 or die "Girocco::Project->ghost call failed\n";
643 $newproj->{$k} = $v while ($k, $v) = each(%settings);
644 my $killowner = sub {
645 system($Girocco::Config
::git_bin
, '--git-dir='.$newproj->{path
},
646 'config', '--unset', "gitweb.owner");
649 $newproj->premirror or die "Girocco::Project->premirror failed\n";
650 !$noowner or &$killowner;
651 $newproj->clone or die "Girocco::Project->clone failed\n";
652 warn "Project $projname created and cloning successfully initiated.\n"
655 $newproj->conjure or die "Girocco::Project->conjure failed\n";
656 !$noowner or &$killowner;
657 warn "New push project fork is empty due to use of --no-alternates\n"
658 if !$quiet && $projname =~ m
,/, && $noalternates;
659 warn "Project $projname successfully created.\n" unless $quiet;
666 system($Girocco::Config
::git_bin
, "--git-dir=$gd", 'config', @_) == 0
667 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
671 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
672 parse_options
(force
=> \
$force, ":type" => \
$type, "no-users" => \
$nousers, "dry-run" => \
$dryrun,
673 "no-owner" => \
$noowner,":owner" => \
$owner, quiet
=> \
$quiet, q
=>\
$quiet, verbose
=> \
$verbose);
674 @ARGV or die "Please give project name on command line.\n";
675 my $projname = shift @ARGV;
676 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage
;
677 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage
;
678 defined($type) or $type = "";
680 if ($dryrun && $projname =~ m
,^/[^.\s/\\:], && is_git_dir
(realpath
($projname))) {
681 $projdir = realpath
($projname);
682 $projname = $projdir;
683 $projname =~ s/\.git$//i;
684 $projname =~ s
,/+$,,;
685 $projname =~ s
,^.*/,,;
686 $projname ne "" or $projname = $projdir;
688 $projname =~ s/\.git$//i;
689 $projname ne "" or die "Invalid project name \"\".\n";
690 unless (Girocco
::Project
::does_exist
($projname, 1)) {
691 Girocco
::Project
::valid_name
($projname, 1, 1)
692 or die "Invalid project name \"$projname\".\n";
693 die "No such project to adopt: $projname\n";
695 defined(Girocco
::Project
->load($projname))
696 and die "Project already known (no need to adopt): $projname\n";
697 $projdir = $Girocco::Config
::reporoot
. "/" . $projname . ".git";
698 is_git_dir
($projdir) or die "Not a git directory: \"$projdir\"\n";
700 my $config = read_config_file
($projdir . "/config");
702 %config = map {($$_[0], defined($$_[1])?
$$_[1]:"true")} @
$config if defined($config);
703 git_bool
($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
704 defined(read_HEAD_symref
($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
705 @ARGV and $users = [validate_users
(join(" ", @ARGV), $force, 1, $quiet)];
707 if (-e
"$projdir/description") {
708 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
714 defined $desc or $desc = "";
716 $desc = to_utf8
($desc, 1);
717 is_default_desc
($desc) and $desc = "";
718 if ($desc ne "" && !valid_desc
($desc)) {
719 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
721 warn "using invalid 'description' file contents with --force\n" unless $quiet;
723 $desc = clean_desc
($desc);
724 if (length($desc) > 1024) {
725 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
727 warn "using longer than 1024 char description with --force\n" unless $quiet;
731 if (-e
"$projdir/README.html") {
732 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
738 defined $readme or $readme = "";
739 $readme = to_utf8
($readme, 1);
740 $readme =~ s/\r\n?/\n/gs;
741 $readme =~ s/^\s+//s;
742 $readme =~ s/\s+$//s;
743 $readme eq "" or $readme .= "\n";
744 if (length($readme) > 8192) {
745 die "readme greater than 8192 chars is too long (use --force to override)\n"
747 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
749 my $rd = get_readme_desc
($readme);
750 if ($rd ne "automatic" && $rd ne "suppressed") {
751 my $xmllint = qx(sh
-c
'command -v xmllint'); chomp $xmllint;
752 if (-f
$xmllint && -x
$xmllint) {
753 my $dummy = {README
=> $readme};
754 my ($cnt, $err) = Girocco
::Project
::_lint_readme
($dummy, 0);
756 my $msg = "xmllint: $cnt error";
757 $msg .= "s" unless $cnt == 1;
758 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
759 unless $force && $quiet;
760 exit(255) unless $force;
761 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
764 die "xmllint not available, refusing to use raw HTML without --force\n"
766 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
770 # Inspect any remotes now
771 # Yes, Virginia, remote urls can be multi-valued
775 next unless $k =~ /^remote\.([^\/].*?
)\
.([^.]+)$/; # remote name cannot start with "/"
776 my ($name, $subkey) = ($1, $2);
777 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate
" || $subkey eq "skipfetchall
";
778 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror
"; # we might want this
779 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs
";
780 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
781 ($subkey eq "url
" || $subkey eq "fetch
" || $subkey eq "push" || $subkey eq "pushurl
");
783 # remotes.default is the default remote group to fetch for "git remote update
" otherwise --all
784 # the remote names in a group are separated by runs of [ \t\n] characters
785 # remote names "", ".", ".." and any name starting with "/" are invalid
786 # a remote with no url or vcs setting is not considered valid
789 if (exists($config{"remotes
.default"})) {
790 foreach (split(/[ \t\n]+/, $config{"remotes
.default"})) {
791 next unless exists($remotes{$_});
792 my $rmt = $remotes{$_};
793 next if !exists($rmt->{url}) && !$rmt->{vcs};
801 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
802 next if $seenrmt{$1};
804 next unless exists($remotes{$1});
805 my $rmt = $remotes{$1};
806 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
810 my @needskip = (); # remotes that need skipDefaultUpdate set to true
813 my $foundfetchwithmirror = 0;
815 my $rmt = $remotes{$_};
816 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
817 next unless exists($rmt->{fetch});
819 ++$foundfetchwithmirror if $rmt->{mirror};
820 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
822 # if we have $foundvcs then we need to explicitly set fetch.prune to false
823 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
824 my $neednoprune = !exists($config{"fetch
.prune
"}) && ($foundvcs || $foundfetch > 1);
826 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
827 # if remote "origin
" exists we always pick up its first url or use ""
828 if (exists($remotes{origin})) {
829 my $rmt = $remotes{origin};
830 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
831 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
834 # get the first url of the @check remotes
836 my $rmt = $remotes{$_};
837 next unless exists($rmt->{url});
838 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
839 $baseurl = $rmt->{url}->[0];
843 my $makemirror = $type eq "mirror
" || ($type eq "" && $foundfetch);
845 # If we have $foundfetch we want to make a mirror but complain if
846 # we $foundfetchwithmirror as well unless we have --type=mirror.
847 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
848 # Warn if we need to set fetch.prune=false when making a mirror
849 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
850 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
851 # Warn if $usingall and any @needskip (and set them) if making a mirror
852 # Warn if making a mirror and $baseurl eq ""
853 # Warn if we have --type=mirror and !$foundfetch
856 warn "No base URL to mirror from
for adopted
\"$projname\"\n" unless $quiet || $baseurl ne "";
857 warn "Adopting mirror
\"$projname\" without any fetch remotes
\n" unless $quiet || $foundfetch;
858 if ($foundfetchwithmirror) {
859 warn "Refusing to adopt mirror
\"$projname\" with active remote
.<name
>.mirror
=true remote
(s
)\n".
860 "(Use
--type
=mirror to override
)\n"
861 unless $type eq "mirror
";
862 exit(255) unless $type eq "mirror
" || $dryrun;
863 warn "Adopting mirror
\"$projname\" with active remote
.<name
>.mirror
=true remotes
\n"
864 unless $quiet || $type ne "mirror
";
866 warn "Setting explicit fetch
.prune
=false
for adoption of mirror
\"$projname\"\n"
867 if !$quiet && $neednoprune;
868 warn "Setting remote
.origin
.skipDefaultUpdate
=true
for adoption of mirror
\"$projname\"\n"
869 if !$quiet && $needfakeorigin;
870 if (!$usingall && @needskip) {
871 warn "Refusing to adopt mirror empty fetch remote
(s
) (override with
--force
)\n"
873 exit(255) unless $force || $dryrun;
874 warn "Adopting mirror with empty fetch remote
(s
) with
--force
\n"
875 unless $quiet || !$force;
877 warn "Will set skipDefaultUpdate
=true on non
-fetch remote
(s
)\n" if !$quiet && $usingall && @needskip;
878 warn "Adopting mirror with base URL
\"$baseurl\"\n" unless $quiet || $baseurl eq "";
880 warn "Adopting
push \"$projname\" but active non
-mirror remotes are present
\n"
881 if !$quiet && $foundfetch && !$foundfetchwithmirror;
884 if (!$noowner && !defined($owner)) {
886 $owner = $config{"gitweb
.owner
"};
887 if (!defined($owner) || $owner eq "") {
888 $owner = $Girocco::Config::admin;
889 warn "Using owner
\"$owner\" for adopted project
\n" unless $quiet;
892 if (!$nousers && !$makemirror && !defined($users)) {
893 # select user list for push project
894 my $findowner = $owner;
895 defined($findowner) or $findowner = $config{"gitweb
.owner
"};
896 $findowner = lc($findowner) if defined($findowner);
897 my @owner_users = ();
898 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
899 if defined($findowner) && $findowner ne "";
900 if (@owner_users <= 1) {
901 $users = \@owner_users;
902 warn "No users found that match owner
\"$findowner\"\n" unless @owner_users || $quiet;
905 warn "Found
".scalar(@owner_users)." users
for owner
\"$findowner\" (" .
906 join(" ", @owner_users) . ") not setting any
\n" unless $quiet;
909 defined($users) or $users = [];
911 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
912 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
913 # and warn about preserving the setting)
915 warn "Preserving existing receive
.denyNonFastForwards
=true
\n"
916 if !$quiet && git_bool($config{"receive
.denynonfastforwards
"});
917 warn "Preserving existing receive
.denyDeleteCurrent
=$config{'receive.denydeletecurrent'}\n"
918 if !$quiet && exists($config{"receive
.denydeletecurrent
"}) &&
919 $config{"receive
.denydeletecurrent
"} ne "warn";
921 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs
");
922 my $reflogactive = git_bool($config{"core
.logallrefupdates
"});
923 if ($reflogactive || $reflogfiles) {
924 warn "Refusing to adopt
\"$projname\" with active
ref logs without
--force
\n" if $reflogfiles && !$force;
925 warn "Refusing to adopt
\"$projname\" with core
.logAllRefUpdates
=true without
--force
\n" if $reflogactive && !$force;
926 exit(255) unless $force || $dryrun;
927 warn "Adopting
\"$projname\" with active
ref logs with
--force
\n" unless $quiet || ($reflogfiles && !$force);
928 warn "Adopting
\"$projname\" with core
.logAllRefUpdates
=true with
--force
\n" unless $quiet || ($reflogactive && !$force);
931 return 0 if $dryrun && !$verbose;
933 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
934 defined($newproj) or die "Girocco
::Project
::ghost failed
: $@
\n";
935 $newproj->{desc} = $desc;
936 $newproj->{README} = $readme;
937 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb
.baseurl
"});
938 $newproj->{email} = $owner if defined($owner);
939 $newproj->{users} = $users;
940 $newproj->{crypt} = "unknown
";
941 $newproj->{reverseorder} = 1 unless exists($config{"hooks
.reverseorder
"});
942 $newproj->{summaryonly} = 1 unless exists($config{"hooks
.summaryonly
"});
943 my $dummy = bless {}, "Girocco
::Project
";
944 $dummy->{path} = "$projdir";
945 $dummy->{configfilehash} = \%config;
946 $dummy->_properties_load;
947 delete $dummy->{origurl};
948 foreach my $k (keys(%$dummy)) {
949 $newproj->{$k} = $dummy->{$k}
950 if exists($dummy->{$k}) && !exists($newproj->{$k});
955 my %info = %$newproj;
956 $info{README} = get_readme_desc($info{README}) if exists($info{README});
957 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
958 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
959 print $d->Dump([\%info], ['*'.$newproj->{name}]);
963 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
965 git_config($projdir, "fetch
.prune
", "false
") if $neednoprune;
966 git_config($projdir, "remote
.origin
.skipDefaultUpdate
", "true
") if $needfakeorigin;
967 if ($usingall && @needskip) {
968 git_config($projdir, "remote
.$_.skipDefaultUpdate
", "true
") foreach @needskip;
972 # Perform the actual adoption
973 $newproj->adopt or die "Girocco
::Project
::adopt failed
\n";
975 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
976 git_config($projdir, "receive
.denyNonFastForwards
", "true
")
977 if git_bool($config{"receive
.denynonfastforwards
"});
978 git_config($projdir, "receive
.denyDeleteCurrent
", $config{"receive
.denydeletecurrent
"})
979 if exists($config{"receive
.denydeletecurrent
"}) &&
980 $config{"receive
.denydeletecurrent
"} ne "warn";
981 git_config($projdir, "core
.logAllRefUpdates
", "true
")
986 warn "Mirror project
\"$projname\" successfully adopted
.\n" unless $quiet;
988 warn "Push project
\"$projname\" successfully adopted
.\n" unless $quiet;
994 my ($force, $reallydel, $keepforks);
995 parse_options(force => \$force, "really
-delete" => \$reallydel,
996 "keep
-forks
" => \$keepforks, quiet => \$quiet, q =>\$quiet);
997 @ARGV or die "Please give project name on command line
.\n";
998 @ARGV == 1 or die_usage;
999 my $project = get_project($ARGV[0]);
1000 my $projname = $project->{name};
1001 my $isempty = !$project->{mirror} && $project->is_empty;
1002 if (!$project->{mirror} && !$isempty && $reallydel) {
1003 die "refusing to remove
and delete non
-empty
push project without
--force
: $projname\n" unless $force;
1004 warn "allowing removal
and deletion of non
-empty
push project with
--force
\n" unless $quiet;
1008 if ($project->has_forks) {
1009 die "refusing to remove project with forks
(use --keep
-forks
): $projname\n" unless $keepforks;
1010 warn "allowing removal of forked project
while preserving its forks with
--keep
-forks
\n" unless $quiet;
1011 # Run pseudo GC on that repository so that objects don't get lost within forks
1012 my $basedir = $Girocco::Config::basedir;
1013 my $projdir = $project->{path};
1014 warn "We have to run pseudo GC on the repo so that the forks don
't lose data. Hang on...\n" unless $quiet;
1015 my $nogcrunning = sub {
1016 die "Error: GC appears to be currently running on $projname\n"
1017 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
1020 $removenogc = ! -e "$projdir/.nogc";
1021 recreate_file("$projdir/.nogc") if $removenogc;
1022 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
1023 delete $ENV{show_progress};
1024 $ENV{'show_progress
'} = 1 unless $quiet;
1027 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
1028 or die "Running pseudo GC on project $projname failed\n";
1032 if (!$project->{mirror} && !$isempty && !$reallydel) {
1033 $archived = $project->archive_and_delete;
1034 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
1038 warn "Project '$projname' removed from $Girocco::Config::name" .
1039 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
1040 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1046 @ARGV == 1 or die_usage;
1047 my $project = get_clean_project($ARGV[0]);
1048 my %info = %$project;
1049 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1050 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1051 print $d->Dump([\%info], ['*'.$project->{name}]);
1056 @ARGV == 1 or die_usage;
1057 my $project = get_project($ARGV[0]);
1058 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1059 my $cur = $project->{HEAD};
1060 defined($cur) or $cur = '';
1062 my $headhash = get_git("--git-dir=$project->{path}", 'rev
-parse
', '--quiet
', '--verify
', 'HEAD
');
1063 defined($headhash) or $headhash = '';
1065 $headhash or $curmark = '!';
1067 my $mark = $_ eq $cur ? $curmark : ' ';
1075 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose
' || $ARGV[0] eq '-v
');
1076 @ARGV == 1 or die_usage;
1077 my $project = get_project($ARGV[0]);
1079 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1081 print map("$_\n", $project->get_ctag_names);
1088 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1089 @ARGV >= 2 or die_usage;
1090 my $project = get_project(shift @ARGV);
1093 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1095 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1099 my $ctags = join(" ", @ARGV);
1100 $ctags = lc($ctags) if $ic;
1101 foreach (split(/[\s,]+/, $ctags)) {
1102 next unless exists($curtags{$_});
1103 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1106 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1108 # Avoid touching anything other than the ctags
1109 foreach my $tg (@deltags) {
1110 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1112 $project->_set_changed;
1113 $project->_set_forkchange;
1114 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1120 @ARGV >= 2 or die_usage;
1121 my $project = get_project(shift @ARGV);
1122 my $ctags = join(" ", @ARGV);
1123 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1124 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1125 my $oldmask = umask();
1126 umask($oldmask & ~0060);
1128 foreach (split(/[\s,]+/, $ctags)) {
1129 ++$changed if $project->add_ctag($_, 1);
1132 $project->_set_changed;
1133 $project->_set_forkchange;
1136 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1137 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1141 sub _get_random_val {
1146 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1153 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force
';
1155 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1156 @ARGV == 1 or die_usage;
1157 my $project = get_project($ARGV[0]);
1158 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1159 if $project->is_password_locked;
1162 if ($random eq "random") {
1163 die "refusing to set random password without --force\n" unless $force;
1164 $rmsg = "set to random value";
1165 $newpw = _get_random_val($project);
1167 die "refusing to set password hash to '$random' without --force\n" unless $force;
1168 $rmsg = "hash set to '$random'";
1174 print "Changing admin password for project $ARGV[0]\n";
1175 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1176 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1177 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1178 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1179 "the admin passwords you have entered do not match each other.\n";
1183 defined($newpw) or die "missing new password on STDIN\n";
1187 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1188 my $old = $project->{crypt};
1189 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1190 if (defined($old) && $old eq $project->{crypt}) {
1191 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1193 # Avoid touching anything other than the password hash
1194 $project->_group_update;
1195 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1201 @ARGV == 1 or die_usage;
1202 my $project = get_project($ARGV[0]);
1203 my $pwhash = $project->{crypt};
1204 defined($pwhash) or $pwhash = "";
1205 if ($pwhash eq "") {
1206 warn $project->{name}, ": no password required\n" unless $quiet;
1209 if ($project->is_password_locked) {
1210 warn $project->{name}, ": password is locked\n" unless $quiet;
1215 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1216 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1219 defined($checkpw) or die "missing admin password on STDIN\n";
1222 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1223 warn "password check failure\n" unless $quiet;
1226 warn "admin password match\n" unless $quiet;
1231 my ($force, $auto, $redelta, $recompress);
1232 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1233 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force,
1234 recompress => \$recompress, "no-reuse-object" => $recompress);
1235 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1236 @ARGV or die "Please give project name on command line.\n";
1237 @ARGV == 1 or die_usage;
1238 my $project = get_project($ARGV[0]);
1239 delete $ENV{show_progress};
1240 delete $ENV{force_gc};
1241 $quiet or $ENV{"show_progress"} = 1;
1242 $force and $ENV{"force_gc"} = 1;
1243 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1244 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1246 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1247 $redelta && !$recompress and push(@args, "-f");
1248 $recompress and push(@args, "-F");
1249 my $lastgc = $project->{lastgc};
1250 system({$args[0]} @args) != 0 and return 1;
1251 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's
not set
1253 my $newlastgc = get_git
("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1255 system({$args[0]} @args) != 0 and return 1;
1262 my ($force, $summary);
1263 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet, summary
=> \
$summary);
1264 $quiet && $summary and die "--quiet and --summary are mutually exclusive options\n";
1265 @ARGV or die "Please give project name on command line.\n";
1266 @ARGV == 1 or die_usage
;
1267 my $project = get_project
($ARGV[0]);
1268 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1269 delete $ENV{show_progress
};
1270 delete $ENV{force_update
};
1272 $ENV{"show_progress"} = 0;
1274 $ENV{"show_progress"} = ($summary ?
1 : 2);
1276 $force and $ENV{"force_update"} = 1;
1277 system($Girocco::Config
::basedir
. "/jobd/update.sh", $project->{name
}) != 0 and return 1;
1283 parse_options
(force
=> \
$force, quiet
=> \
$quiet, q
=> \
$quiet);
1284 @ARGV or die "Please give project name on command line.\n";
1285 @ARGV == 1 or die_usage
;
1286 my $project = get_project
($ARGV[0]);
1287 $project->{mirror
} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1288 if ($project->{clone_in_progress
} && !$project->{clone_failed
}) {
1289 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1290 exit(255) unless $force;
1291 yes_to_continue_or_die
("Are you sure you want to force a remirror");
1293 unlink($project->_clonefail_path);
1294 unlink($project->_clonelog_path);
1295 recreate_file
($project->_clonep_path);
1296 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or
1297 die "cannot connect to taskd.socket: $!\n";
1298 select((select($sock),$|=1)[0]);
1299 $sock->print("clone ".$project->{name
}."\n");
1300 # Just ignore reply, we are going to succeed anyway and the I/O
1301 # would apparently get quite hairy.
1305 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1311 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1312 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1313 my $project = get_project
($ARGV[0]);
1314 if (@ARGV == 2 && !valid_email
($ARGV[1])) {
1315 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1317 warn "using invalid owner/email with --force\n" unless $quiet;
1319 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1320 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1322 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1324 my $old = $project->{email
};
1326 print "$old\n" if defined($old);
1329 if (defined($old) && $old eq $ARGV[1]) {
1330 warn $project->{name
}, ": skipping update of owner/email to same value\n" unless $quiet;
1332 # Avoid touching anything other than "gitweb.owner"
1333 $project->_property_fput("email", $ARGV[1]);
1334 $project->_update_index;
1335 $project->_set_changed;
1336 warn $project->{name
}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1343 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1344 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1345 my $project = get_project
(shift @ARGV);
1346 if (@ARGV && !valid_desc
(join(" ", @ARGV))) {
1347 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1349 warn "using invalid description with --force\n" unless $quiet;
1351 my $desc = clean_desc
(join(" ", @ARGV));
1352 if (@ARGV && length($desc) > 1024) {
1353 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1355 warn "using longer than 1024 char description with --force\n" unless $quiet;
1357 my $old = $project->{desc
};
1359 print "$old\n" if defined($old);
1362 if (defined($old) && $old eq $desc) {
1363 warn $project->{name
}, ": skipping update of description to same value\n" unless $quiet;
1365 # Avoid touching anything other than description file
1366 $project->_property_fput("desc", $desc);
1367 $project->_set_changed;
1368 warn $project->{name
}, ": description updated to \"$desc\"\n" unless $quiet;
1375 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1376 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1377 my $project = get_project
($ARGV[0]);
1378 my $old = $project->{README
};
1380 chomp $old if defined($old);
1381 print "$old\n" if defined($old) && $old ne "";
1384 my ($new, $raw, $newname);
1386 if ($ARGV[1] eq "-") {
1390 $newname = "contents of <STDIN>";
1391 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1393 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1394 $new = "<!-- suppress -->";
1398 die "missing filename for README\n" unless $fn ne "";
1399 die "no such file: \"$fn\"\n" unless -f
$fn && -r
$fn;
1400 open F
, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1405 $newname = "contents of \"$fn\"";
1407 defined($new) or $new = '';
1408 $project->{README
} = to_utf8
($new, 1);
1409 $project->_cleanup_readme;
1410 if (length($project->{README
}) > 8192) {
1411 die "readme greater than 8192 chars is too long (use --force to override)\n"
1413 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1416 my $rd = get_readme_desc
($project->{README
});
1417 if ($rd ne "automatic" && $rd ne "suppressed") {
1418 my $xmllint = qx(command
-v xmllint
); chomp $xmllint;
1419 if (-f
$xmllint && -x
$xmllint) {
1420 my ($cnt, $err) = $project->_lint_readme(0);
1422 my $msg = "xmllint: $cnt error";
1423 $msg .= "s" unless $cnt == 1;
1424 print STDERR
"$msg\n", "-" x
length($msg), "\n", $err
1425 unless $force && $quiet;
1426 exit(255) unless $force;
1427 warn $project->{name
} . ": using invalid raw HTML with --force\n" unless $quiet;
1430 die "xmllint not available, refusing to use raw HTML without --force\n"
1432 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1436 if (defined($old) && $old eq $project->{README
}) {
1437 warn $project->{name
}, ": skipping update of README to same value\n" unless $quiet;
1439 # Avoid touching anything other than README.html file
1440 $project->_property_fput("README", $project->{README
});
1441 $project->_set_changed;
1442 my $desc = get_readme_desc
($project->{README
});
1444 $newname .= " ($desc)";
1448 warn $project->{name
}, ": README updated to $newname\n" unless $quiet;
1454 my ($proj, $newhead) = @_;
1455 my %okheads = map({($_ => 1)} $proj->get_heads);
1456 exists($okheads{$newhead});
1460 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1461 my $project = get_project
($ARGV[0]);
1462 if (@ARGV == 2 && !valid_head
($project, $ARGV[1])) {
1463 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1465 my $old = $project->{HEAD
};
1467 print "$old\n" if defined($old);
1470 if (defined($old) && $old eq $ARGV[1]) {
1471 warn $project->{name
}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1473 # Avoid touching anything other than the HEAD symref
1474 $project->set_HEAD($ARGV[1]);
1475 warn $project->{name
}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1482 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1483 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1484 my $project = get_project
($ARGV[0]);
1485 my $projconfig = read_config_file_hash
($project->{path
}."/config");
1486 my $ghp = $Girocco::Config
::reporoot
."/_global/hooks";
1487 my $rghp = realpath
($ghp);
1488 my $lhp = $project->{path
}."/hooks";
1489 my $rlhp = realpath
($lhp);
1492 if (defined($projconfig) && defined($projconfig->{"core.hookspath"})) {
1493 $ahp = $projconfig->{"core.hookspath"};
1494 $rahp = realpath
($ahp);
1497 if (defined($rahp) && $rahp ne "") {
1498 if ($rahp eq $rghp) {
1499 my $nc = ($ahp eq $ghp ?
"" : " non-canonical");
1500 printf "%s \t(global%s)\n", $ahp, $nc;
1501 } elsif ($rahp eq $rlhp) {
1502 my $nc = ($ahp eq $lhp ?
"" : " non-canonical");
1503 printf "%s \t(local%s)\n", $ahp, $nc;
1504 } elsif ($rahp ne $ahp) {
1505 print "$ahp \t($rahp)\n";
1509 } elsif ($ahp ne "") {
1510 print "$ahp \t(non-existent)\n";
1515 if (lc($shp) eq "global") {
1517 } elsif (lc($shp) eq "local") {
1519 } elsif (substr($shp, 0, 2) eq "~/") {
1520 $shp = $ENV{"HOME"}.substr($shp,1);
1521 } elsif ($shp =~ m
,^~([a
-zA
-Z_
][a
-zA
-Z_0
-9]*)((?
:/.*)?
)$,) {
1523 my $hd = (getpwnam($1))[7];
1524 $shp = $hd . $sfx if defined($hd) && $hd ne "" && $hd ne "/" && -d
$hd;
1526 $shp ne "" && -d
$shp or die "no such directory: $ARGV[1]\n";
1527 my $rshp = realpath
($shp);
1528 defined($rshp) && $rshp ne "" or die "could not realpath: $ARGV[1]\n";
1529 $rshp =~ m
,^/[^/], or die "invalid hookspath: $rshp\n";
1530 die "refusing to switch from current non-global hookspath without --force\n"
1531 if !$force && defined($rahp) && $rahp ne "" && $rahp ne $rghp && $rshp ne $rahp;
1532 if (!$force && defined($rahp) && $rahp ne "") {
1533 if ($rshp eq $rahp && ($ahp eq $ghp || $ahp eq $lhp)) {
1534 warn $project->{name
}, ": skipping update of hookspath to same effective value\n" unless $quiet;
1538 $rshp = $ghp if $rshp eq $rghp;
1539 $rshp = $lhp if $rshp eq $rlhp;
1540 if ($rshp eq $ahp) {
1541 warn $project->{name
}, ": skipping update of hookspath to same value\n" unless $quiet;
1544 die "refusing to set neither local nor global hookspath without --force\n"
1545 if !$force && $rshp ne $ghp && $rshp ne $lhp;
1546 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1547 'config', "core.hookspath", $rshp);
1548 my $newval = '"'.$rshp.'"';
1549 $newval = "global" if $rshp eq $ghp;
1550 $newval = "local" if $rshp eq $lhp;
1551 warn $project->{name
}, ": hookspath set to $newval\n" unless $quiet;
1567 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1568 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1569 my $project = get_project
($ARGV[0]);
1570 if (!exists($boolfields{$ARGV[1]})) {
1571 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1573 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror
}) {
1574 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1576 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1578 if (@ARGV == 3 && !valid_bool
($ARGV[2])) {
1579 die "invalid boolean value: \"$ARGV[2]\"\n";
1581 my $bool = clean_bool
($ARGV[2]);
1582 my $old = $project->{$ARGV[1]};
1584 print "$old\n" if defined($old);
1587 if (defined($old) && $old eq $bool) {
1588 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1590 # Avoid touching anything other than $ARGV[1] field
1591 $project->_property_fput($ARGV[1], $bool);
1592 warn $project->{name
}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1597 sub cmd_setautogchack
{
1598 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage
;
1599 my $project = get_project
($ARGV[0]);
1600 my $aghok = $Girocco::Config
::autogchack
&&
1601 ($project->{mirror
} || $Girocco::Config
::autogchack
ne "mirror");
1602 my $old = defined($project->{autogchack
}) ? clean_bool
($project->{autogchack
}) : "unset";
1604 print "$old\n" if $aghok;
1608 if (lc($ARGV[1]) eq "unset") {
1611 valid_bool
($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1612 $bool = clean_bool
($ARGV[1]);
1615 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config
::autogchack
;
1616 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1618 if ($old eq $bool) {
1619 warn $project->{name
}, ": autogchack value unchanged\n" unless $quiet;
1621 if ($bool eq "unset") {
1622 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1623 'config', '--unset', "girocco.autogchack");
1625 system($Girocco::Config
::git_bin
, '--git-dir='.$project->{path
},
1626 'config', '--bool', "girocco.autogchack", $bool);
1629 return system($Girocco::Config
::basedir
. "/jobd/maintain-auto-gc-hack.sh", $project->{name
}) == 0
1634 my ($url, $type) = @_;
1635 $type ne 'baseurl' and return valid_web_url
($url);
1636 valid_repo_url
($url) or return 0;
1637 if ($Girocco::Config
::restrict_mirror_hosts
) {
1638 my $mh = extract_url_hostname
($url);
1639 is_dns_hostname
($mh) or return 0;
1640 !is_our_hostname
($mh) or return 0;
1648 baseurl
=> ["url" , 1],
1649 homepage
=> ["hp" , 0],
1650 notifyjson
=> ["notifyjson", 0],
1656 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1657 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1658 my $project = get_project
($ARGV[0]);
1659 if (!exists($urlfields{$ARGV[1]})) {
1660 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1662 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror
}) {
1663 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1665 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1667 if (@ARGV == 3 && !valid_url
($ARGV[2], $ARGV[1])) {
1668 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1670 warn "using invalid URL with --force\n" unless $quiet;
1672 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1674 print "$old\n" if defined($old);
1677 if (defined($old) && $old eq $ARGV[2]) {
1678 warn $project->{name
}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1680 # Avoid touching anything other than $ARGV[1]'s field
1681 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1682 if ($ARGV[1] eq "baseurl") {
1683 $project->{url
} = $ARGV[2];
1684 $project->_set_bangagain;
1686 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1687 warn $project->{name
}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1702 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1703 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage
;
1704 my $project = get_project
(shift @ARGV);
1705 my $field = shift @ARGV;
1706 if (!exists($msgsfields{$field})) {
1707 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1709 if (@ARGV && !valid_addrlist
(@ARGV)) {
1710 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1712 warn "using invalid email address list with --force\n" unless $quiet;
1714 my $old = $project->{$field};
1716 printf "%s\n", clean_addrlist
($old, " ") if defined($old);
1719 my $newlist = clean_addrlist
(join(" ",@ARGV));
1720 if (defined($old) && $old eq $newlist) {
1721 warn $project->{name
}, ": skipping update of $field to same value\n" unless $quiet;
1723 # Avoid touching anything other than $field's field
1724 $project->_property_fput($field, $newlist);
1725 warn $project->{name
}, ": $field updated to \"$newlist\"\n" unless $quiet;
1732 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1733 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage
;
1734 my $project = get_project
(shift @ARGV);
1735 my $projname = $project->{name
};
1736 !@ARGV || !$project->{mirror
} or die "cannot set users list for mirror project: \"$projname\"\n";
1739 eval {@newusers = validate_users
(join(" ", @ARGV), $force); 1;} or exit 255;
1740 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1742 return 0 if !@ARGV && $project->{mirror
};
1743 my $oldusers = $project->{users
};
1744 if ($oldusers && ref($oldusers) eq "ARRAY") {
1745 $oldusers = join("\n", @
$oldusers);
1750 print "$oldusers\n" if $oldusers ne "";
1753 if ($oldusers eq join("\n", @newusers)) {
1754 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1756 # Avoid touching anything other than the users list
1757 $project->{users
} = \
@newusers;
1758 $project->_update_users;
1759 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1767 owner
=> [\
&cmd_setowner
, 0],
1768 desc
=> [\
&cmd_setdesc
, 0],
1769 description
=> [\
&cmd_setdesc
, 0],
1770 readme
=> [\
&cmd_setreadme
, 0],
1771 head
=> [\
&cmd_sethead
, 0],
1772 HEAD
=> [\
&cmd_sethead
, 0],
1773 hooks
=> [\
&cmd_sethooks
, 0],
1774 hookspath
=> [\
&cmd_sethooks
, 0],
1775 cleanmirror
=> [\
&cmd_setbool
, 1],
1776 reverseorder
=> [\
&cmd_setbool
, 1],
1777 summaryonly
=> [\
&cmd_setbool
, 1],
1778 statusupdates
=> [\
&cmd_setbool
, 1],
1779 autogchack
=> [\
&cmd_setautogchack
, 0],
1780 baseurl
=> [\
&cmd_seturl
, 1],
1781 homepage
=> [\
&cmd_seturl
, 1],
1782 notifyjson
=> [\
&cmd_seturl
, 1],
1783 notifymail
=> [\
&cmd_setmsgs
, 1],
1784 notifytag
=> [\
&cmd_setmsgs
, 1],
1785 users
=> [\
&cmd_setusers
, 0],
1792 push(@newargs, shift) if @_ && $_[0] eq '--force';
1794 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage
;
1795 push(@newargs, shift);
1796 shift unless ${$fieldnames{$field}}[1];
1798 diename
(($setopt ?
"set " : "get ") . $field);
1800 &{${$fieldnames{$field}}[0]}(@ARGV);
1815 create
=> \
&cmd_create
,
1816 adopt
=> \
&cmd_adopt
,
1817 remove
=> \
&cmd_remove
,
1818 trash
=> \
&cmd_remove
,
1819 delete => \
&cmd_remove
,
1821 listheads
=> \
&cmd_listheads
,
1822 listtags
=> \
&cmd_listtags
,
1823 listctags
=> \
&cmd_listtags
,
1824 deltags
=> \
&cmd_deltags
,
1825 delctags
=> \
&cmd_deltags
,
1826 addtags
=> \
&cmd_addtags
,
1827 addctags
=> \
&cmd_addtags
,
1828 chpass
=> \
&cmd_chpass
,
1829 checkpw
=> \
&cmd_checkpw
,
1831 update
=> \
&cmd_update
,
1832 remirror
=> \
&cmd_remirror
,
1833 setowner
=> \
&cmd_setowner
,
1834 setdesc
=> \
&cmd_setdesc
,
1835 setdescription
=> \
&cmd_setdesc
,
1836 setreadme
=> \
&cmd_setreadme
,
1837 sethead
=> \
&cmd_sethead
,
1838 sethooks
=> \
&cmd_sethooks
,
1839 sethookspath
=> \
&cmd_sethooks
,
1840 setbool
=> \
&cmd_setbool
,
1841 setboolean
=> \
&cmd_setbool
,
1842 setflag
=> \
&cmd_setbool
,
1843 setautogchack
=> \
&cmd_setautogchack
,
1844 seturl
=> \
&cmd_seturl
,
1845 setmsgs
=> \
&cmd_setmsgs
,
1846 setusers
=> \
&cmd_setusers
,
1854 my $bn = basename
($0);
1855 printf "%s version %s\n\n", $bn, $VERSION;
1856 if (defined($cmd) && $cmd ne '') {
1857 $cmd =~ s/^set(?=[a-zA-Z])//i;
1859 my ($lastmt, $incmd);
1860 foreach (split('\n', sprintf($help, $bn))) {
1861 $lastmt || $incmd or $lastmt = /^\s*$/, next;
1862 $incmd = 1 if $lastmt && /^\s*(?:\[?set\]?)?$cmd\s/;
1863 last if $incmd && /^\s*$/;
1864 $incmd and $cmdhelp .= $_ . "\n";
1867 print $cmdhelp and exit 0 if $cmdhelp;
1875 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1876 dohelp
($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1877 my $command = shift;
1880 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1882 $command = "set" . $command;
1884 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1885 dohelp
($command) if @ARGV && $ARGV[0] =~ /^(?:-h|-?-help)$/i ||
1886 $ARGV[0] =~ /^help$/i && !Girocco
::Project
::does_exist
("help",1);
1887 &{$commands{$command}}(@ARGV);