scm: cvs: code clean up adapter.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5386 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-04-10 12:27:53 +00:00
parent 3be326f0a4
commit d5bb4b349a
1 changed files with 34 additions and 37 deletions

View File

@ -61,18 +61,18 @@ module Redmine
end end
# Guidelines for the input: # Guidelines for the input:
# url -> the project-path, relative to the cvsroot (eg. module name) # url -> the project-path, relative to the cvsroot (eg. module name)
# root_url -> the good old, sometimes damned, CVSROOT # root_url -> the good old, sometimes damned, CVSROOT
# login -> unnecessary # login -> unnecessary
# password -> unnecessary too # password -> unnecessary too
def initialize(url, root_url=nil, login=nil, password=nil, def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil) path_encoding=nil)
@url = url @url = url
@login = login if login && !login.empty? @login = login if login && !login.empty?
@password = (password || "") if @login @password = (password || "") if @login
# TODO: better Exception here (IllegalArgumentException) # TODO: better Exception here (IllegalArgumentException)
raise CommandFailed if root_url.blank? raise CommandFailed if root_url.blank?
@root_url = root_url @root_url = root_url
end end
def root_url def root_url
@ -135,10 +135,10 @@ module Redmine
else else
entries << Entry.new( entries << Entry.new(
{ {
:name => fields[1], :name => fields[1],
:path => "#{path}/#{fields[1]}", :path => "#{path}/#{fields[1]}",
:kind => 'dir', :kind => 'dir',
:size => nil, :size => nil,
:lastrev => nil :lastrev => nil
}) })
end end
@ -156,9 +156,10 @@ module Redmine
# in the repository. both identifier have to be dates or nil. # in the repository. both identifier have to be dates or nil.
# these method returns nothing but yield every result in block # these method returns nothing but yield every result in block
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block) def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block)
logger.debug "<cvs> revisions path:'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}" logger.debug "<cvs> revisions path:" +
"'#{path}',identifier_from #{identifier_from}, identifier_to #{identifier_to}"
path_with_project="#{url}#{with_leading_slash(path)}" path_with_project = "#{url}#{with_leading_slash(path)}"
cmd_args = %w|rlog| cmd_args = %w|rlog|
cmd_args << "-d" << ">#{time_to_cvstime_rlog(identifier_from)}" if identifier_from cmd_args << "-d" << ">#{time_to_cvstime_rlog(identifier_from)}" if identifier_from
cmd_args << path_with_project cmd_args << path_with_project
@ -187,10 +188,10 @@ module Redmine
elsif /^head: (.+)$/ =~ line elsif /^head: (.+)$/ =~ line
entry_headRev = $1 #unless entry.nil? entry_headRev = $1 #unless entry.nil?
elsif /^symbolic names:/ =~ line elsif /^symbolic names:/ =~ line
state="symbolic" #unless entry.nil? state = "symbolic" #unless entry.nil?
elsif /^#{STARTLOG}/ =~ line elsif /^#{STARTLOG}/ =~ line
commit_log=String.new commit_log = String.new
state="revision" state = "revision"
end end
next next
elsif state=="symbolic" elsif state=="symbolic"
@ -211,36 +212,30 @@ module Redmine
elsif state=="revision" elsif state=="revision"
if /^#{ENDLOG}/ =~ line || /^#{STARTLOG}/ =~ line if /^#{ENDLOG}/ =~ line || /^#{STARTLOG}/ =~ line
if revision if revision
revHelper=CvsRevisionHelper.new(revision) revHelper=CvsRevisionHelper.new(revision)
revBranch="HEAD" revBranch="HEAD"
branch_map.each() do |branch_name, branch_point|
branch_map.each() do |branch_name,branch_point|
if revHelper.is_in_branch_with_symbol(branch_point) if revHelper.is_in_branch_with_symbol(branch_point)
revBranch=branch_name revBranch=branch_name
end end
end end
logger.debug("********** YIELD Revision #{revision}::#{revBranch}") logger.debug("********** YIELD Revision #{revision}::#{revBranch}")
yield Revision.new({ yield Revision.new({
:time => date, :time => date,
:author => author, :author => author,
:message=>commit_log.chomp, :message => commit_log.chomp,
:paths => [{ :paths => [{
:revision => revision, :revision => revision,
:branch=> revBranch, :branch => revBranch,
:path=>entry_path, :path => entry_path,
:name=>entry_name, :name => entry_name,
:kind=>'file', :kind => 'file',
:action=>file_state :action => file_state
}] }]
}) })
end end
commit_log = String.new
commit_log=String.new revision = nil
revision=nil
if /^#{ENDLOG}/ =~ line if /^#{ENDLOG}/ =~ line
state="entry_start" state="entry_start"
end end
@ -255,8 +250,10 @@ module Redmine
date = Time.parse($1) date = Time.parse($1)
author = /author: ([^;]+)/.match(line)[1] author = /author: ([^;]+)/.match(line)[1]
file_state = /state: ([^;]+)/.match(line)[1] file_state = /state: ([^;]+)/.match(line)[1]
#TODO: linechanges only available in CVS.... maybe a feature our SVN implementation. i'm sure, they are # TODO:
# useful for stats or something else # linechanges only available in CVS....
# maybe a feature our SVN implementation.
# I'm sure, they are useful for stats or something else
# linechanges =/lines: \+(\d+) -(\d+)/.match(line) # linechanges =/lines: \+(\d+) -(\d+)/.match(line)
# unless linechanges.nil? # unless linechanges.nil?
# version.line_plus = linechanges[1] # version.line_plus = linechanges[1]
@ -405,16 +402,16 @@ module Redmine
private private
def buildRevision(rev) def buildRevision(rev)
if rev== 0 if rev == 0
if @branchid.nil? if @branchid.nil?
@base+".0" @base + ".0"
else else
@base @base
end end
elsif @branchid.nil? elsif @branchid.nil?
@base+"."+rev.to_s @base + "." + rev.to_s
else else
@base+"."+@branchid+"."+rev.to_s @base + "." + @branchid + "." + rev.to_s
end end
end end