]> source.dussan.org Git - redmine.git/commitdiff
implement local cache for mercurial remote repositories
authorNicolas Chuche <nicolas.chuche@barna.be>
Sat, 27 Sep 2008 11:00:05 +0000 (11:00 +0000)
committerNicolas Chuche <nicolas.chuche@barna.be>
Sat, 27 Sep 2008 11:00:05 +0000 (11:00 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1908 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/mercurial.rb
lib/redmine/scm/adapters/mercurial_adapter.rb

index 18cbc9495a76cc221c56d40c7484bd112fbc0477..c3fd154e22f7bc4f1ed24f27097a380948e68801 100644 (file)
@@ -21,6 +21,15 @@ class Repository::Mercurial < Repository
   attr_protected :root_url
   validates_presence_of :url
 
+  def init_cache
+    return unless dir = repositories_cache_directory
+    # we need to use a cache only if repository isn't local and dir exists
+    if url[/^(|https?|ssh):\/\//]
+      update_attribute(:cache_path, dir + project.identifier)
+      update_attribute(:cache, true)
+    end
+  end
+
   def scm_adapter
     Redmine::Scm::Adapters::MercurialAdapter
   end
@@ -53,6 +62,8 @@ class Repository::Mercurial < Repository
   end
 
   def fetch_changesets
+    create_or_sync_cache if cache
+
     scm_info = scm.info
     if scm_info
       # latest revision found in database
index 4eed776d8b3f64cec3a9c29c090f722b694fffca..9eecb6086687c530e76b5b2a85290c47094964e4 100644 (file)
@@ -199,6 +199,18 @@ module Redmine
           return nil if $? && $?.exitstatus != 0
           blame
         end
+
+        def create_cache
+          cmd = "#{HG_BIN} clone #{@orig_url} #{@root_url}"
+          shellout(cmd) { |io| io.read }
+        end
+
+        def synchronize
+          return unless File.directory?(@url)
+          cmd = "#{HG_BIN} -R #{@url} pull"
+          shellout(cmd)
+        end
+
       end
     end
   end