From: Andy Parkins <andyparkins@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 1/2] Make 'cvs ci' lockless in git-cvsserver by using git-update-ref
Date: Tue, 27 Feb 2007 04:48:59 -0800 [thread overview]
Message-ID: <200702271248.59652.andyparkins@gmail.com> (raw)
In-Reply-To: <200702210908.59579.andyparkins@gmail.com>
This makes "ci" codepath lockless by following the usual
"remember the tip, do your thing, then compare and swap at the
end" update pattern using update-ref. Incidentally, by updating
the code that reads where the tip of the head is to use
show-ref, it makes it safe to use in a repository whose refs are
pack-pruned.
I noticed that other parts of the program are not yet pack-refs
safe, but tried to keep the changes to the minimum.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
This patch is actually yours (with one extra removal of lock file reference
that you'd missed, and a change of shortlog), but I don't know how to send
an email that comes from me but attributes authorship to you.
git-cvsserver.perl | 43 ++++++++++++++++---------------------------
1 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 84520e7..8e12f81 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -1031,36 +1031,35 @@ sub req_ci
exit;
}
- my $lockfile = "$state->{CVSROOT}/refs/heads/$state->{module}.lock";
- unless ( sysopen(LOCKFILE,$lockfile,O_EXCL|O_CREAT|O_WRONLY) )
- {
- $log->warn("lockfile '$lockfile' already exists, please try again");
- print "error 1 Lock file '$lockfile' already exists, please try again\n";
- exit;
- }
-
# Grab a handle to the SQLite db and do any necessary updates
my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
$updater->update();
my $tmpdir = tempdir ( DIR => $TEMP_DIR );
my ( undef, $file_index ) = tempfile ( DIR => $TEMP_DIR, OPEN => 0 );
- $log->info("Lock successful, basing commit on '$tmpdir', index file is '$file_index'");
+ $log->info("Lockless commit start, basing commit on '$tmpdir', index file is '$file_index'");
$ENV{GIT_DIR} = $state->{CVSROOT} . "/";
$ENV{GIT_INDEX_FILE} = $file_index;
+ # Remember where the head was at the beginning.
+ my $parenthash = `git show-ref -s refs/heads/$state->{module}`;
+ chomp $parenthash;
+ if ($parenthash !~ /^[0-9a-f]{40}$/) {
+ print "error 1 pserver cannot find the current HEAD of module";
+ exit;
+ }
+
chdir $tmpdir;
# populate the temporary index based
- system("git-read-tree", $state->{module});
+ system("git-read-tree", $parenthash);
unless ($? == 0)
{
die "Error running git-read-tree $state->{module} $file_index $!";
}
$log->info("Created index '$file_index' with for head $state->{module} - exit status $?");
-
my @committedfiles = ();
# foreach file specified on the command line ...
@@ -1095,8 +1094,6 @@ sub req_ci
{
# fail everything if an up to date check fails
print "error 1 Up to date check failed for $filename\n";
- close LOCKFILE;
- unlink($lockfile);
chdir "/";
exit;
}
@@ -1139,16 +1136,12 @@ sub req_ci
{
print "E No files to commit\n";
print "ok\n";
- close LOCKFILE;
- unlink($lockfile);
chdir "/";
return;
}
my $treehash = `git-write-tree`;
- my $parenthash = `cat $ENV{GIT_DIR}refs/heads/$state->{module}`;
chomp $treehash;
- chomp $parenthash;
$log->debug("Treehash : $treehash, Parenthash : $parenthash");
@@ -1165,8 +1158,6 @@ sub req_ci
{
$log->warn("Commit failed (Invalid commit hash)");
print "error 1 Commit failed (unknown reason)\n";
- close LOCKFILE;
- unlink($lockfile);
chdir "/";
exit;
}
@@ -1179,14 +1170,17 @@ sub req_ci
{
$log->warn("Commit failed (update hook declined to update ref)");
print "error 1 Commit failed (update hook declined)\n";
- close LOCKFILE;
- unlink($lockfile);
chdir "/";
exit;
}
}
- print LOCKFILE $commithash;
+ if (system(qw(git update-ref -m), "cvsserver ci",
+ "refs/heads/$state->{module}", $commithash, $parenthash)) {
+ $log->warn("update-ref for $state->{module} failed.");
+ print "error 1 Cannot commit -- update first\n";
+ exit;
+ }
$updater->update();
@@ -1215,12 +1209,7 @@ sub req_ci
}
}
- close LOCKFILE;
- my $reffile = "$ENV{GIT_DIR}refs/heads/$state->{module}";
- unlink($reffile);
- rename($lockfile, $reffile);
chdir "/";
-
print "ok\n";
}
--
1.5.0.2.778.gdcb06
--
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
next prev parent reply other threads:[~2007-02-27 12:49 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-20 7:28 Unresolved issues Junio C Hamano
[not found] ` <Pine.LNX.4.64.07022009 34270.20368@woody.linux-foundation.org>
2007-02-20 8:57 ` Andy Parkins
2007-02-20 20:10 ` [PATCH] Use git-update-ref to update a ref during commit in git-cvsserver Andy Parkins
2007-02-20 21:57 ` Nicolas Pitre
2007-02-21 5:54 ` Junio C Hamano
2007-02-21 9:08 ` Andy Parkins
2007-02-27 12:48 ` Andy Parkins [this message]
2007-02-27 13:55 ` [PATCH 1/2] Make 'cvs ci' lockless in git-cvsserver by using git-update-ref Jakub Narebski
2007-02-27 14:35 ` Nicolas Pitre
2007-02-27 23:44 ` Junio C Hamano
2007-02-28 8:44 ` Andy Parkins
2007-02-28 18:06 ` Junio C Hamano
2007-02-27 12:49 ` [PATCH 2/2] cvsserver: Remove trailing "\n" from commithash in checkin function Andy Parkins
2007-02-27 23:45 ` Junio C Hamano
2007-02-28 8:45 ` Andy Parkins
2007-02-27 23:37 ` [PATCH] Use git-update-ref to update a ref during commit in git-cvsserver Martin Langhoff
2007-02-20 17:41 ` Unresolved issues Linus Torvalds
2007-02-20 21:43 ` Junio C Hamano
2007-02-21 0:21 ` Linus Torvalds
2007-02-21 0:25 ` Junio C Hamano
2007-02-21 0:39 ` Johannes Schindelin
2007-02-21 0:56 ` Linus Torvalds
2007-02-21 0:51 ` David Lang
2007-02-21 1:12 ` Johannes Schindelin
2007-02-21 1:51 ` Nicolas Pitre
2007-02-21 2:03 ` Linus Torvalds
2007-02-21 16:32 ` Robin Rosenberg
2007-02-21 1:49 ` Theodore Tso
2007-02-21 10:42 ` Martin Waitz
2007-02-21 12:55 ` Johannes Schindelin
2007-02-21 16:57 ` Brian Gernhardt
2007-02-21 17:05 ` Shawn O. Pearce
2007-02-22 8:28 ` [PATCH] git-status: do not be totally useless in a read-only repository Junio C Hamano
2007-02-22 8:30 ` [PATCH] update-index: do not die too early " Junio C Hamano
2007-02-26 1:33 ` Unresolved issues Julian Phillips
2007-02-26 3:39 ` Junio C Hamano
2007-02-26 5:10 ` Julian Phillips
2007-02-26 5:33 ` Junio C Hamano
2007-02-27 20:10 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200702271248.59652.andyparkins@gmail.com \
--to=andyparkins@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).