compile, pm: factor out new repo creation
...also wrap_chdir, wrap_open, $ABRT, and $WARN
This commit is contained in:
parent
5696b13f62
commit
c3b5e3b1af
|
@ -9,8 +9,9 @@
|
||||||
# the name of this file will change as soon as its function/feature set
|
# the name of this file will change as soon as its function/feature set
|
||||||
# stabilises enough ;-)
|
# stabilises enough ;-)
|
||||||
|
|
||||||
# right now all it does is define a function that tells you where to find the
|
# right now all it does is
|
||||||
# rc file
|
# - define a function that tells you where to find the rc file
|
||||||
|
# - define a function that creates a new repo and give it our update hook
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# where is the rc file hiding?
|
# where is the rc file hiding?
|
||||||
|
@ -42,4 +43,32 @@ sub where_is_rc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ABRT = "\n\t\t***** ABORTING *****\n ";
|
||||||
|
$WARN = "\n\t\t***** WARNING *****\n ";
|
||||||
|
sub wrap_chdir {
|
||||||
|
chdir($_[0]) or die "$ABRT chdir $_[0] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub wrap_open {
|
||||||
|
open (my $fh, $_[0], $_[1]) or die "$ABRT open $_[1] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n" .
|
||||||
|
( $_[2] || '' ); # suffix custom error message if given
|
||||||
|
return $fh;
|
||||||
|
}
|
||||||
|
|
||||||
|
# NOTE: this sub will change your cwd; caller beware!
|
||||||
|
sub new_repo
|
||||||
|
{
|
||||||
|
my ($repo, $hooks_dir) = @_;
|
||||||
|
|
||||||
|
umask($REPO_UMASK);
|
||||||
|
|
||||||
|
system("mkdir", "-p", "$repo.git") and die "$ABRT mkdir $repo.git failed: $!\n";
|
||||||
|
# erm, note that's "and die" not "or die" as is normal in perl
|
||||||
|
wrap_chdir("$repo.git");
|
||||||
|
system("git --bare init >&2");
|
||||||
|
# propagate our own, plus any local admin-defined, hooks
|
||||||
|
system("cp $hooks_dir/* hooks/");
|
||||||
|
chmod 0755, "hooks/update";
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -52,12 +52,7 @@ $Data::Dumper::Sortkeys = 1;
|
||||||
open STDOUT, ">", "/dev/null" if (@ARGV and shift eq '-q');
|
open STDOUT, ">", "/dev/null" if (@ARGV and shift eq '-q');
|
||||||
|
|
||||||
our ($GL_ADMINDIR, $GL_CONF, $GL_KEYDIR, $GL_CONF_COMPILED, $REPO_BASE, $REPO_UMASK, $PROJECTS_LIST, $GIT_PATH);
|
our ($GL_ADMINDIR, $GL_CONF, $GL_KEYDIR, $GL_CONF_COMPILED, $REPO_BASE, $REPO_UMASK, $PROJECTS_LIST, $GIT_PATH);
|
||||||
|
our ($ABRT, $WARN);
|
||||||
# now that this thing *may* be run via "push to admin", any errors have to
|
|
||||||
# grab the admin's ATTENTION so he won't miss them among the other messages a
|
|
||||||
# typical push generates
|
|
||||||
my $ABRT = "\n\t\t***** ABORTING *****\n ";
|
|
||||||
my $WARN = "\n\t\t***** WARNING *****\n ";
|
|
||||||
|
|
||||||
# the common setup module is in the same directory as this running program is
|
# the common setup module is in the same directory as this running program is
|
||||||
my $bindir = $0;
|
my $bindir = $0;
|
||||||
|
@ -118,16 +113,6 @@ umask($REPO_UMASK);
|
||||||
# subroutines
|
# subroutines
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
sub wrap_chdir {
|
|
||||||
chdir($_[0]) or die "$ABRT chdir $_[0] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
sub wrap_open {
|
|
||||||
open (my $fh, $_[0], $_[1]) or die "$ABRT open $_[1] failed: $! at ", (caller)[1], " line ", (caller)[2], "\n" .
|
|
||||||
( $_[2] || '' ); # suffix custom error message if given
|
|
||||||
return $fh;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub expand_list
|
sub expand_list
|
||||||
{
|
{
|
||||||
my @list = @_;
|
my @list = @_;
|
||||||
|
@ -337,15 +322,10 @@ for my $repo (keys %repos)
|
||||||
{
|
{
|
||||||
unless (-d "$repo.git")
|
unless (-d "$repo.git")
|
||||||
{
|
{
|
||||||
system("mkdir", "-p", "$repo.git") and die "$ABRT mkdir $repo.git failed: $!\n";
|
new_repo($repo, "$GL_ADMINDIR/src/hooks");
|
||||||
# erm, note that's "and die" not "or die" as is normal in perl
|
|
||||||
wrap_chdir("$repo.git");
|
|
||||||
system("git --bare init");
|
|
||||||
# propagate our own, plus any local admin-defined, hooks
|
|
||||||
system("cp $GL_ADMINDIR/src/hooks/* hooks/");
|
|
||||||
chmod 0755, "hooks/update";
|
|
||||||
wrap_chdir("$repo_base_abs");
|
|
||||||
$git_too_old++ if $git_version < 10602; # that's 1.6.2 to you
|
$git_too_old++ if $git_version < 10602; # that's 1.6.2 to you
|
||||||
|
# new_repo would have chdir'd us away; come back
|
||||||
|
wrap_chdir("$repo_base_abs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
warn "\n\t\t***** WARNING *****\n" .
|
warn "\n\t\t***** WARNING *****\n" .
|
||||||
|
|
Loading…
Reference in a new issue