changeset 438:34214e593c67 cannam-pre-20110113-merge

Merge from branch bug_169
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Mon, 06 Jun 2011 13:32:07 +0100
parents 897979555864 (current diff) 102056ec2de9 (diff)
children d3faf348b287
files
diffstat 5 files changed, 53 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/sys_controller.rb	Mon Jun 06 10:58:52 2011 +0100
+++ b/app/controllers/sys_controller.rb	Mon Jun 06 13:32:07 2011 +0100
@@ -69,6 +69,16 @@
     render :nothing => true, :status => 404
   end
 
+  def clear_repository_cache
+    project = Project.find(params[:id])
+    if project.repository
+      project.repository.clear_cache
+    end
+    render :nothing => true, :status => 200
+  rescue ActiveRecord::RecordNotFound
+    render :nothing => true, :status => 404
+  end
+  
   def set_embedded_active
     project = Project.find(params[:id])
     mods = project.enabled_modules
--- a/app/models/repository.rb	Mon Jun 06 10:58:52 2011 +0100
+++ b/app/models/repository.rb	Mon Jun 06 13:32:07 2011 +0100
@@ -203,6 +203,10 @@
     nil
   end
   
+  def clear_cache
+    clear_changesets
+  end
+
   private
   
   def before_save
--- a/config/routes.rb	Mon Jun 06 10:58:52 2011 +0100
+++ b/config/routes.rb	Mon Jun 06 13:32:07 2011 +0100
@@ -237,8 +237,9 @@
   map.with_options :controller => 'sys' do |sys|
     sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get}
     sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post}
-    sys.connect 'sys/projects/:id/external-repository.:format', :action => 'get_external_repo_url', :conditions => {:method => :get}
+    sys.connect 'sys/projects/:id/external_repository.:format', :action => 'get_external_repo_url', :conditions => {:method => :get}
     sys.connect 'sys/projects/:id/embedded.:format', :action => 'set_embedded_active', :conditions => { :method => :post }
+    sys.connect 'sys/projects/:id/repository_cache.:format', :action => 'clear_repository_cache', :conditions => {:method => :post}
   end
  
   # Install the default route as the lowest priority.
--- a/extra/soundsoftware/convert-external-repos.rb	Mon Jun 06 10:58:52 2011 +0100
+++ b/extra/soundsoftware/convert-external-repos.rb	Mon Jun 06 13:32:07 2011 +0100
@@ -62,6 +62,8 @@
 $http_pass    = ''
 $test         = false
 
+$mirrordir    = '/var/mirror'
+
 def log(text, options={})
   level = options[:level] || 0
   puts text unless $quiet or level > $verbose
@@ -168,6 +170,14 @@
   end
 
   system($command, project.identifier, repos_path, external_url)
+  
+  $cache_clearance_file = File.join($mirrordir, project.identifier, 'url_changed')
+  if File.file?($cache_clearance_file)
+    log("\tproject repo url has changed, requesting cache clearance")
+    if project.post(:repository_cache, :key => $api_key)
+      File.delete($cache_clearance_file)
+    end
+  end
 
 end
   
--- a/extra/soundsoftware/update-external-repo.sh	Mon Jun 06 10:58:52 2011 +0100
+++ b/extra/soundsoftware/update-external-repo.sh	Mon Jun 06 13:32:07 2011 +0100
@@ -60,6 +60,28 @@
 
 success=""
 
+# If we have a record of the last successfully updated remote repo
+# URL, check it against our current remote URL: if it has changed, we
+# will need to start again with a new clone rather than pulling
+# updates into the existing local mirror
+
+successfile="$project_mirror/last_successful_url"
+if [ -f "$successfile" ]; then
+    last=$(cat "$successfile")
+    if [ x"$last" = x"$remote_repo" ]; then
+	echo "$$: Remote URL is unchanged from last successful update"
+    else
+	echo "$$: Remote URL has changed since last successful update:"
+	echo "$$: Last URL was $last, current is $remote_repo"
+	suffix="$$.$(date +%s)"
+	echo "$$: Moving existing repos to $suffix suffix and starting afresh"
+	mv "$project_repo_mirror" "$project_repo_mirror"."$suffix"
+	mv "$local_repo" "$local_repo"."$suffix"
+	mv "$successfile" "$successfile"."$suffix"
+	touch "$project_mirror/url_changed"
+    fi
+fi
+
 if [ -d "$project_repo_mirror" ]; then
 
     # Repo mirror exists: update it
@@ -96,12 +118,12 @@
 
 if [ -n "$success" ]; then
     echo "$$: Update successful, pulling into local repo at $local_repo"
+    if [ ! -d "$local_repo" ]; then
+	"$hg" init "$local_repo"
+    fi
     if [ -d "$project_repo_mirror/.git" ]; then
-	if [ ! -d "$local_repo" ]; then
-	    "$hg" init "$local_repo"
-	fi
-	( cd "$local_repo" && "$hg" --config extensions.hggit= pull "$project_repo_mirror" )
+	( cd "$local_repo" && "$hg" --config extensions.hggit= pull "$project_repo_mirror" ) && echo "$remote_repo" > "$successfile"
     else 
-	( cd "$local_repo" && "$hg" pull "$project_repo_mirror" )
+	( cd "$local_repo" && "$hg" pull "$project_repo_mirror" ) && echo "$remote_repo" > "$successfile"
     fi
 fi