From ca6e69ec247e10c521f22fba542404720cc2ebff Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 15 Jun 2008 15:47:28 +0000 Subject: [PATCH] Fixed: view file at given revision with CVS. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1553 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/repositories_controller.rb | 6 +++--- app/models/repository.rb | 8 ++++++++ app/models/repository/cvs.rb | 11 ++++++++--- lib/redmine/scm/adapters/cvs_adapter.rb | 4 +++- test/functional/repositories_cvs_controller_test.rb | 13 +++++++++++++ .../repositories_subversion_controller_test.rb | 9 +++++++++ 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ef49cf248..c14449290 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/models/repository.rb b/app/models/repository.rb index 1cf61393f..c7bf0dbf4 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index 5ff7af999..dd9d35c8f 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -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=[] diff --git a/lib/redmine/scm/adapters/cvs_adapter.rb b/lib/redmine/scm/adapters/cvs_adapter.rb index 18f26b9c8..089a6b153 100644 --- a/lib/redmine/scm/adapters/cvs_adapter.rb +++ b/lib/redmine/scm/adapters/cvs_adapter.rb @@ -245,7 +245,9 @@ module Redmine identifier = (identifier) ? identifier : "HEAD" logger.debug " 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 diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index e12bb53ac..254fbc69c 100644 --- a/test/functional/repositories_cvs_controller_test.rb +++ b/test/functional/repositories_cvs_controller_test.rb @@ -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 diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index efb824992..6af5cd5dd 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -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/ },