From c113da97a61813d5684eebb966f6fb9b8b3efeca Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 18:07:14 -0700 Subject: Refactor and alter git repo caching strategy Our previous strategy occasionally failed if a build got the cached git repo into an odd state (such as leaving a git lockfile), so now we clone a new repo for every build from our local cached copy. The only operations performed in the cached repo is a git fetch --prune --- lib/jitterbug/Builder.pm | 63 ++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'lib/jitterbug') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 33efea2..5befade 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -95,42 +95,47 @@ sub _prepare_git_repo { my ($self, $task, $buildconf, $build_dir, $cached_repo_dir) = @_; my $repo = $task->project->url; - unless ($buildconf->{reuse_repo}) { - debug("Removing $build_dir"); - rmtree($build_dir, { error => \my $err } ); - warn @$err if @$err; + my $name = $task->project->name; - _clone_into($repo, $build_dir); + debug("Removing $build_dir"); + rmtree($build_dir, { error => \my $err } ); + warn @$err if @$err; + # If we aren't reusing/caching git repos, clone from remote into the build dir + unless ($buildconf->{reuse_repo}) { + _clone_into($repo, $build_dir); } else { - # If this is the first time, the repo won't exist yet + # We are caching git repos, so we clone a new repo from our local + # cached git repo, then checkout the correct sha1 + debug("build_dir = $build_dir"); - if( -d $build_dir ){ - my $pwd = getcwd; - chdir $build_dir; - # TODO: Error Checking - debug("Cleaning git repo"); - system("git clean -dfx"); - debug("Fetching new commits into $repo"); - system("git fetch"); - debug("Checking out correct commit"); - - # TODO: this may fail on non-unixy systems - system("git checkout " . $task->commit->sha256 . "&>/dev/null" ); - chdir $pwd; - } else { - _clone_into($repo, $build_dir); + unless ( -d $cached_repo_dir ) { + # If this is the first time, the repo won't exist yet + # Clone it into our cached repo directory + _clone_into($repo, $cached_repo_dir); } - } - $self->sleep(1); # avoid race conditions + my $pwd = getcwd; - debug("Checking out " . $task->commit->sha256 . " from $repo into $build_dir\n"); - my $pwd = getcwd; - chdir $build_dir; + chdir $cached_repo_dir; + # TODO: Error Checking - # TODO: this may fail on non-unixy systems - system("git checkout " . $task->commit->sha256 . "&>/dev/null"); - chdir $pwd; + debug("Fetching new commits into $repo"); + system("git fetch --prune"); + chdir $pwd; + + debug("Cloning from cached repo $cached_repo_dir into $build_dir"); + + _clone_into($cached_repo_dir, $build_dir); + chdir $build_dir; + + $self->sleep(1); # avoid race conditions + + # TODO: this may fail on non-unixy systems + debug("checking out " . $task->commit->sha256); + system("git checkout " . $task->commit->sha256 . "&>/dev/null" ); + + chdir $pwd; + } } sub build_task { -- cgit 1.4.1