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
end
def fetch_changesets
+ create_or_sync_cache if cache
+
scm_info = scm.info
if scm_info
# latest revision found in database
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