OSDN Git Service

Fixed: view file at given revision with CVS.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Jun 2008 15:47:28 +0000 (15:47 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Jun 2008 15:47:28 +0000 (15:47 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1553 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
app/models/repository.rb
app/models/repository/cvs.rb
lib/redmine/scm/adapters/cvs_adapter.rb
test/functional/repositories_cvs_controller_test.rb
test/functional/repositories_subversion_controller_test.rb

index ef49cf2..c144492 100644 (file)
@@ -73,7 +73,7 @@ class RepositoriesController < ApplicationController
   end
   
   def changes
-    @entry = @repository.scm.entry(@path, @rev)
+    @entry = @repository.entry(@path, @rev)
     show_error_not_found and return unless @entry
     @changesets = @repository.changesets_for_path(@path)
   rescue Redmine::Scm::Adapters::CommandFailed => e
@@ -96,13 +96,13 @@ class RepositoriesController < ApplicationController
   end
   
   def entry
-    @entry = @repository.scm.entry(@path, @rev)
+    @entry = @repository.entry(@path, @rev)
     show_error_not_found and return unless @entry
     
     # If the entry is a dir, show the browser
     browse and return if @entry.is_dir?
     
-    @content = @repository.scm.cat(@path, @rev)
+    @content = @repository.cat(@path, @rev)
     show_error_not_found and return unless @content
     if 'raw' == params[:format] || @content.is_binary_data?
       # Force the download if it's a binary file
index 1cf6139..c7bf0db 100644 (file)
@@ -51,10 +51,18 @@ class Repository < ActiveRecord::Base
     scm.supports_annotate?
   end
   
+  def entry(path=nil, identifier=nil)
+    scm.entry(path, identifier)
+  end
+  
   def entries(path=nil, identifier=nil)
     scm.entries(path, identifier)
   end
   
+  def cat(path, identifier=nil)
+    scm.cat(path, identifier)
+  end
+  
   def diff(path, rev, rev_to)
     scm.diff(path, rev, rev_to)
   end
index 5ff7af9..dd9d35c 100644 (file)
@@ -29,9 +29,9 @@ class Repository::Cvs < Repository
     'CVS'
   end
   
-  def entry(path, identifier)
-    e = entries(path, identifier)
-    e ? e.first : nil
+  def entry(path=nil, identifier=nil)
+    rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
+    scm.entry(path, rev.nil? ? nil : rev.committed_on)
   end
   
   def entries(path=nil, identifier=nil)
@@ -53,6 +53,11 @@ class Repository::Cvs < Repository
     entries
   end
   
+  def cat(path, identifier=nil)
+    rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
+    scm.cat(path, rev.nil? ? nil : rev.committed_on)
+  end
+  
   def diff(path, rev, rev_to)
     #convert rev to revision. CVS can't handle changesets here
     diff=[]
index 18f26b9..089a6b1 100644 (file)
@@ -245,7 +245,9 @@ module Redmine
           identifier = (identifier) ? identifier : "HEAD"
           logger.debug "<cvs> cat path:'#{path}',identifier #{identifier}"
           path_with_project="#{url}#{with_leading_slash(path)}"
-          cmd = "#{CVS_BIN} -d #{root_url} co -r#{identifier} -p #{shell_quote path_with_project}"
+          cmd = "#{CVS_BIN} -d #{root_url} co"
+          cmd << " -D \"#{time_to_cvstime(identifier)}\"" if identifier
+          cmd << " -p #{shell_quote path_with_project}"
           cat = nil
           shellout(cmd) do |io|
             cat = io.read
index e12bb53..254fbc6 100644 (file)
@@ -89,6 +89,19 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase
       get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb']
       assert_response :success
       assert_template 'entry'
+      assert_no_tag :tag => 'td', :attributes => { :class => /line-code/},
+                                  :content => /before_filter/
+    end
+    
+    def test_entry_at_given_revision
+      # changesets must be loaded
+      Project.find(1).repository.fetch_changesets
+      get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :rev => 2
+      assert_response :success
+      assert_template 'entry'
+      # this line was removed in r3
+      assert_tag :tag => 'td', :attributes => { :class => /line-code/},
+                               :content => /before_filter/
     end
     
     def test_entry_not_found
index efb8249..6af5cd5 100644 (file)
@@ -78,6 +78,15 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
       assert_template 'entry'
     end
     
+    def test_entry_at_given_revision
+      get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
+      assert_response :success
+      assert_template 'entry'
+      # this line was removed in r3 and file was moved in r6
+      assert_tag :tag => 'td', :attributes => { :class => /line-code/},
+                               :content => /Here's the code/
+    end
+    
     def test_entry_not_found
       get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
       assert_tag :tag => 'div', :attributes => { :class => /error/ },