aboutsummaryrefslogtreecommitdiff
path: root/src/util/git-lock.pl
diff options
context:
space:
mode:
authorschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2008-03-10 18:12:39 +0000
committerschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2008-03-10 18:12:39 +0000
commit9cbf586eb3a7bb7a57f23045cce2f4331a40f526 (patch)
tree21354efaaa9e9449f10c1e94bb48d5ad3fff97a6 /src/util/git-lock.pl
parentf86b918f68263eb829e9c4728599fbf176d5e9fd (diff)
Change git repository structure.
Introduce one repository per configuration, so that many fewer git-add and git-remove are necessary, speeding up things considerably. Move the main git repository into a subdirectory of the main Cactus directory. Lock the git repository before calling git, so that parallel make works. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@171 83718e91-0e4f-0410-abf4-91180603181f
Diffstat (limited to 'src/util/git-lock.pl')
-rwxr-xr-xsrc/util/git-lock.pl58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/util/git-lock.pl b/src/util/git-lock.pl
new file mode 100755
index 0000000..0eb7922
--- /dev/null
+++ b/src/util/git-lock.pl
@@ -0,0 +1,58 @@
+#! /usr/bin/perl -w
+
+# Obtain a lock for a git repository
+
+# 2008-03-06 Erik Schnetter <schnetter@cct.lsu.edu>
+
+use strict;
+use Cwd;
+#use Fcntl ':flock';
+use sigtrap qw(die normal-signals);
+
+
+
+# Obtain exclusive access to the repository
+
+# We cannot use flock since the file system may be remote
+#open LOCKFILE, "$cctk_home/Makefile";
+#flock LOCKFILE, LOCK_EX;
+
+my $git_dir = $ENV{'GIT_DIR'};
+$git_dir = getcwd unless defined $git_dir;
+$git_dir =~ s+/.git/*$+/+;
+
+# We are very conservative as to what characters we allow. Other
+# characters can be added, but be careful.
+$git_dir =~ m|^[[:alnum:]+-._/]+$| or die;
+
+my $lockdir = "$git_dir/GITLOCK";
+
+
+
+my $waittime = 1;
+my $maxwaittime = 10;
+while (! (mkdir $lockdir)) {
+ # Wait some time
+ my $unit = $waittime==1 ? "second" : "seconds";
+ print "Git repository is busy; waiting $waittime $unit...\n";
+ system "sleep $waittime";
+ # Back off exponentially
+ $waittime *= 2;
+ $waittime = $maxwaittime if $waittime > $maxwaittime;
+}
+
+
+
+# Execute the command
+system @ARGV;
+$? != -1 or die;
+exit $? >> 8;
+
+
+
+# Release the lock
+END {
+ my $retval = $?;
+ rmdir $lockdir;
+ $? = $retval;
+}