##// END OF EJS Templates
Gemfile: update rbpdf version to 1.18.4 (#18629)...
Gemfile: update rbpdf version to 1.18.4 (#18629) git-svn-id: http://svn.redmine.org/redmine/trunk@13870 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r13100:2d1866d966d9
r13488:34b3376b812c
Show More
bazaar_adapter.rb
338 lines | 11.4 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
scm: bazaar: remove trailing white-spaces from adapter source....
r5548 # Redmine - project management software
Toshi MARUYAMA
update copyright year (#15977)...
r12461 # Copyright (C) 2006-2014 Jean-Philippe Lang
Jean-Philippe Lang
Added Bazaar adapter....
r937 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
scm: bazaar: remove trailing white-spaces from adapter source....
r5548 #
Jean-Philippe Lang
Added Bazaar adapter....
r937 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
scm: bazaar: remove trailing white-spaces from adapter source....
r5548 #
Jean-Philippe Lang
Added Bazaar adapter....
r937 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Toshi MARUYAMA
change requirement in bazaar lib as same with other scm libs (#15756)...
r12181 require 'redmine/scm/adapters/abstract_adapter'
Jean-Philippe Lang
Added Bazaar adapter....
r937
module Redmine
module Scm
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701 module Adapters
Jean-Philippe Lang
Added Bazaar adapter....
r937 class BazaarAdapter < AbstractAdapter
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
Jean-Philippe Lang
Added Bazaar adapter....
r937 # Bazaar executable name
Toshi MARUYAMA
scm: change key name of configurable command name (#7517, #6159, #7047)....
r4677 BZR_BIN = Redmine::Configuration['scm_bazaar_command'] || "bzr"
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
class << self
def client_command
@@bin ||= BZR_BIN
end
def sq_bin
Toshi MARUYAMA
scm: bazaar: use "shell_quote_command" method at adapter for JRuby + Windows command name (#8825)....
r6162 @@sq_bin ||= shell_quote_command
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701 end
Toshi MARUYAMA
scm: bazaar: add methods of getting bazaar version and add unit lib test (#4273)....
r4711
def client_version
@@client_version ||= (scm_command_version || [])
end
def client_available
!client_version.empty?
end
def scm_command_version
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
Toshi MARUYAMA
scm: bazaar: add methods of getting bazaar version and add unit lib test (#4273)....
r4711 if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
end
def scm_version_from_command_line
shellout("#{sq_bin} --version") { |io| io.read }.to_s
end
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701 end
Toshi MARUYAMA
scm: bazaar: add @path_encoding instance value and set it UTF-8 at adapter initialize method (#11834)...
r10232 def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil)
Toshi MARUYAMA
scm: bazaar: do not call super initialize method at adapter (#11834)...
r10239 @url = url
@root_url = url
Toshi MARUYAMA
scm: bazaar: add @path_encoding instance value and set it UTF-8 at adapter initialize method (#11834)...
r10232 @path_encoding = 'UTF-8'
Toshi MARUYAMA
scm: bazaar: do not call super initialize method at adapter (#11834)...
r10239 # do not call *super* for non ASCII repository path
Toshi MARUYAMA
scm: bazaar: add @path_encoding instance value and set it UTF-8 at adapter initialize method (#11834)...
r10232 end
Toshi MARUYAMA
scm: bazaar: use log encoding as path encoding (#11834)...
r10237 def bzr_path_encodig=(encoding)
@path_encoding = encoding
end
Jean-Philippe Lang
Added Bazaar adapter....
r937 # Get info about the repository
def info
Toshi MARUYAMA
scm: bazaar: refactor adapter info() to use scm_cmd()....
r5788 cmd_args = %w|revno|
cmd_args << bzr_target('')
Jean-Philippe Lang
Added Bazaar adapter....
r937 info = nil
Toshi MARUYAMA
scm: bazaar: refactor adapter info() to use scm_cmd()....
r5788 scm_cmd(*cmd_args) do |io|
Jean-Philippe Lang
Fixes Bazaar adapter for JRuby/Win32 (#5404)....
r3609 if io.read =~ %r{^(\d+)\r?$}
Jean-Philippe Lang
Added Bazaar adapter....
r937 info = Info.new({:root_url => url,
:lastrev => Revision.new({
:identifier => $1
})
})
end
end
info
Toshi MARUYAMA
scm: bazaar: refactor adapter info() to use scm_cmd()....
r5788 rescue ScmCommandAborted
Jean-Philippe Lang
Added Bazaar adapter....
r937 return nil
end
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
Jean-Philippe Lang
Added Bazaar adapter....
r937 # Returns an Entries collection
# or nil if the given path doesn't exist in the repository
Toshi MARUYAMA
scm: add "options" parameter in adapter entries()....
r5518 def entries(path=nil, identifier=nil, options={})
Jean-Philippe Lang
Added Bazaar adapter....
r937 path ||= ''
entries = Entries.new
Toshi MARUYAMA
scm: bazaar: code clean up adapter....
r5425 identifier = -1 unless identifier && identifier.to_i > 0
Toshi MARUYAMA
scm: bazaar: refactor adapter entries to use scm_cmd()....
r5806 cmd_args = %w|ls -v --show-ids|
cmd_args << "-r#{identifier.to_i}"
cmd_args << bzr_target(path)
scm_cmd(*cmd_args) do |io|
Toshi MARUYAMA
scm: bazaar: convert path encoding from @path_encoding to UTF-8 at adapter entries method (#11834)...
r10235 prefix_utf8 = "#{url}/#{path}".gsub('\\', '/')
logger.debug "PREFIX: #{prefix_utf8}"
prefix = scm_iconv(@path_encoding, 'UTF-8', prefix_utf8)
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 prefix.force_encoding('ASCII-8BIT')
Jean-Philippe Lang
Fixes Bazaar adapter for JRuby/Win32 (#5404)....
r3609 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$}
Jean-Philippe Lang
Added Bazaar adapter....
r937 io.each_line do |line|
next unless line =~ re
Jean-Philippe Lang
undefined method `strip' for nil:NilClass error with JRuby 1.7.2 (#12228)....
r11048 name_locale, slash, revision = $3.strip, $4, $5.strip
Toshi MARUYAMA
scm: bazaar: convert path encoding from @path_encoding to UTF-8 at adapter entries method (#11834)...
r10235 name = scm_iconv('UTF-8', @path_encoding, name_locale)
entries << Entry.new({:name => name,
:path => ((path.empty? ? "" : "#{path}/") + name),
Jean-Philippe Lang
undefined method `strip' for nil:NilClass error with JRuby 1.7.2 (#12228)....
r11048 :kind => (slash.blank? ? 'file' : 'dir'),
Jean-Philippe Lang
Added Bazaar adapter....
r937 :size => nil,
Jean-Philippe Lang
undefined method `strip' for nil:NilClass error with JRuby 1.7.2 (#12228)....
r11048 :lastrev => Revision.new(:revision => revision)
Jean-Philippe Lang
Added Bazaar adapter....
r937 })
end
end
Toshi MARUYAMA
scm: bazaar: refactor adapter entries to use scm_cmd()....
r5806 if logger && logger.debug?
logger.debug("Found #{entries.size} entries in the repository for #{target(path)}")
end
Jean-Philippe Lang
Added Bazaar adapter....
r937 entries.sort_by_name
Toshi MARUYAMA
scm: bazaar: refactor adapter entries to use scm_cmd()....
r5806 rescue ScmCommandAborted
return nil
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
Jean-Philippe Lang
Added Bazaar adapter....
r937 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
path ||= ''
Jean-Philippe Lang
Fixed that some arguments where not properly escaped in scm adapters....
r4425 identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : 'last:1'
identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1
Jean-Philippe Lang
Added Bazaar adapter....
r937 revisions = Revisions.new
Toshi MARUYAMA
scm: bazaar: refactor adapter revisions to use scm_cmd()....
r5809 cmd_args = %w|log -v --show-ids|
cmd_args << "-r#{identifier_to}..#{identifier_from}"
cmd_args << bzr_target(path)
scm_cmd(*cmd_args) do |io|
Jean-Philippe Lang
Added Bazaar adapter....
r937 revision = nil
Toshi MARUYAMA
scm: bazaar: refactor adapter revisions to use scm_cmd()....
r5809 parsing = nil
Jean-Philippe Lang
Added Bazaar adapter....
r937 io.each_line do |line|
if line =~ /^----/
revisions << revision if revision
revision = Revision.new(:paths => [], :message => '')
parsing = nil
else
next unless revision
Jean-Philippe Lang
Fixed: Bazaar "[merge]" tags parsing fails (#3445)....
r2680 if line =~ /^revno: (\d+)($|\s\[merge\]$)/
Jean-Philippe Lang
Added Bazaar adapter....
r937 revision.identifier = $1.to_i
elsif line =~ /^committer: (.+)$/
revision.author = $1.strip
elsif line =~ /^revision-id:(.+)$/
revision.scmid = $1.strip
elsif line =~ /^timestamp: (.+)$/
revision.time = Time.parse($1).localtime
Jean-Philippe Lang
Bazaar adapter: fixed log with partial revisions parsing....
r949 elsif line =~ /^ -----/
# partial revisions
parsing = nil unless parsing == 'message'
Jean-Philippe Lang
Added Bazaar adapter....
r937 elsif line =~ /^(message|added|modified|removed|renamed):/
parsing = $1
Jean-Philippe Lang
Bazaar adapter: fixed log with partial revisions parsing....
r949 elsif line =~ /^ (.*)$/
Jean-Philippe Lang
Added Bazaar adapter....
r937 if parsing == 'message'
revision.message << "#{$1}\n"
else
if $1 =~ /^(.*)\s+(\S+)$/
Toshi MARUYAMA
scm: bazaar: convert path encoding from @path_encoding to UTF-8 at adapter revisions method (#11834)...
r10234 path_locale = $1.strip
path = scm_iconv('UTF-8', @path_encoding, path_locale)
Jean-Philippe Lang
Added Bazaar adapter....
r937 revid = $2
case parsing
when 'added'
revision.paths << {:action => 'A', :path => "/#{path}", :revision => revid}
when 'modified'
revision.paths << {:action => 'M', :path => "/#{path}", :revision => revid}
when 'removed'
revision.paths << {:action => 'D', :path => "/#{path}", :revision => revid}
when 'renamed'
new_path = path.split('=>').last
Toshi MARUYAMA
scm: bazaar: code layout cleanup adapter revisions method...
r10226 if new_path
revision.paths << {:action => 'M', :path => "/#{new_path.strip}",
:revision => revid}
end
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
end
end
else
parsing = nil
end
end
end
revisions << revision if revision
end
revisions
Toshi MARUYAMA
scm: bazaar: refactor adapter revisions to use scm_cmd()....
r5809 rescue ScmCommandAborted
return nil
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
Jean-Philippe Lang
Move unified diff parser out of the scm abstract adapter so it can be reused for viewing attached diffs (#1403)....
r1499 def diff(path, identifier_from, identifier_to=nil)
Jean-Philippe Lang
Added Bazaar adapter....
r937 path ||= ''
if identifier_to
Toshi MARUYAMA
scm: bazaar: code clean up adapter....
r5425 identifier_to = identifier_to.to_i
Jean-Philippe Lang
Added Bazaar adapter....
r937 else
identifier_to = identifier_from.to_i - 1
end
Jean-Philippe Lang
Fixed that some arguments where not properly escaped in scm adapters....
r4425 if identifier_from
identifier_from = identifier_from.to_i
end
Jean-Philippe Lang
Added Bazaar adapter....
r937 diff = []
Toshi MARUYAMA
scm: bazaar: refactor adapter diff to use scm_cmd_no_raise()....
r5803 cmd_args = %w|diff|
cmd_args << "-r#{identifier_to}..#{identifier_from}"
cmd_args << bzr_target(path)
scm_cmd_no_raise(*cmd_args) do |io|
Jean-Philippe Lang
Added Bazaar adapter....
r937 io.each_line do |line|
diff << line
end
end
Jean-Philippe Lang
Move unified diff parser out of the scm abstract adapter so it can be reused for viewing attached diffs (#1403)....
r1499 diff
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
Jean-Philippe Lang
Added Bazaar adapter....
r937 def cat(path, identifier=nil)
cat = nil
Toshi MARUYAMA
scm: bazaar: refactor adapter cat to use scm_cmd()....
r5799 cmd_args = %w|cat|
cmd_args << "-r#{identifier.to_i}" if identifier && identifier.to_i > 0
cmd_args << bzr_target(path)
scm_cmd(*cmd_args) do |io|
Jean-Philippe Lang
Added Bazaar adapter....
r937 io.binmode
cat = io.read
end
cat
Toshi MARUYAMA
scm: bazaar: refactor adapter cat to use scm_cmd()....
r5799 rescue ScmCommandAborted
return nil
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
Jean-Philippe Lang
Added Bazaar adapter....
r937 def annotate(path, identifier=nil)
blame = Annotate.new
Toshi MARUYAMA
scm: bazaar: add -q option in "bzr annotate"....
r5795 cmd_args = %w|annotate -q --all|
Toshi MARUYAMA
scm: bazaar: refactor adapter annotate to use scm_cmd()....
r5792 cmd_args << "-r#{identifier.to_i}" if identifier && identifier.to_i > 0
cmd_args << bzr_target(path)
scm_cmd(*cmd_args) do |io|
author = nil
Jean-Philippe Lang
Added Bazaar adapter....
r937 identifier = nil
io.each_line do |line|
next unless line =~ %r{^(\d+) ([^|]+)\| (.*)$}
Toshi MARUYAMA
scm: bazaar: use revision and identifier as string....
r5280 rev = $1
Toshi MARUYAMA
scm: bazaar: use identifier in blame....
r5272 blame.add_line($3.rstrip,
Revision.new(
:identifier => rev,
:revision => rev,
:author => $2.strip
))
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
end
blame
Toshi MARUYAMA
scm: bazaar: refactor adapter annotate to use scm_cmd()....
r5792 rescue ScmCommandAborted
return nil
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
Toshi MARUYAMA
scm: bazaar: add adapter method to get .bzr/branch/branch.conf path from specified path (#2799, #4741, #8030)....
r5770
def self.branch_conf_path(path)
bcp = nil
m = path.match(%r{^(.*[/\\])\.bzr.*$})
if m
bcp = m[1]
else
bcp = path
end
Toshi MARUYAMA
scm: bazaar: use regexp %r{} instead of // in adapter branch_conf_path()....
r5780 bcp.gsub!(%r{[\/\\]$}, "")
Toshi MARUYAMA
scm: bazaar: add adapter method to get .bzr/branch/branch.conf path from specified path (#2799, #4741, #8030)....
r5770 if bcp
bcp = File.join(bcp, ".bzr", "branch", "branch.conf")
end
Toshi MARUYAMA
scm: bazaar: use explicit return value in adapter branch_conf_path() (#2799, #4741, #8030)....
r5774 bcp
Toshi MARUYAMA
scm: bazaar: add adapter method to get .bzr/branch/branch.conf path from specified path (#2799, #4741, #8030)....
r5770 end
Toshi MARUYAMA
scm: bazaar: add adapter method to get "append_revisions_only" value from .bzr/branch/branch.conf (#2799, #4741, #8030)....
r5772
def append_revisions_only
return @aro if ! @aro.nil?
@aro = false
bcp = self.class.branch_conf_path(url)
Toshi MARUYAMA
scm: bazaar: check not nil in adapter append_revisions_only() (#2799, #4741, #8030)....
r5775 if bcp && File.exist?(bcp)
Toshi MARUYAMA
scm: bazaar: add adapter method to get "append_revisions_only" value from .bzr/branch/branch.conf (#2799, #4741, #8030)....
r5772 begin
f = File::open(bcp, "r")
cnt = 0
f.each_line do |line|
l = line.chomp.to_s
if l =~ /^\s*append_revisions_only\s*=\s*(\w+)\s*$/
str_aro = $1
if str_aro.upcase == "TRUE"
@aro = true
cnt += 1
elsif str_aro.upcase == "FALSE"
@aro = false
cnt += 1
end
if cnt > 1
@aro = false
break
end
end
end
ensure
f.close
end
end
@aro
end
Toshi MARUYAMA
scm: bazaar: add adapter scm_cmd() to run "bzr" command....
r5785
def scm_cmd(*args, &block)
Toshi MARUYAMA
scm: bazaar: use self.class.sq_bin for command name at adpter scm_cmd() (#8825)....
r6163 full_args = []
Toshi MARUYAMA
scm: bazaar: add adapter scm_cmd() to run "bzr" command....
r5785 full_args += args
Toshi MARUYAMA
scm: bazaar: convert command line character encoding to @path_encoding (#11834)...
r10233 full_args_locale = []
full_args.map do |e|
full_args_locale << scm_iconv(@path_encoding, 'UTF-8', e)
end
Toshi MARUYAMA
scm: bazaar: use self.class.sq_bin for command name at adpter scm_cmd() (#8825)....
r6163 ret = shellout(
Toshi MARUYAMA
scm: bazaar: convert command line character encoding to @path_encoding (#11834)...
r10233 self.class.sq_bin + ' ' +
full_args_locale.map { |e| shell_quote e.to_s }.join(' '),
Toshi MARUYAMA
scm: bazaar: use self.class.sq_bin for command name at adpter scm_cmd() (#8825)....
r6163 &block
)
Toshi MARUYAMA
scm: bazaar: add adapter scm_cmd() to run "bzr" command....
r5785 if $? && $?.exitstatus != 0
raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}"
end
ret
end
private :scm_cmd
Toshi MARUYAMA
scm: bazaar: add adapter "bzr_target()" method to common use....
r5787
Toshi MARUYAMA
scm: bazaar: add "scm_cmd_no_raise" method for "bzr diff"....
r5800 def scm_cmd_no_raise(*args, &block)
Toshi MARUYAMA
scm: bazaar: use self.class.sq_bin for command name at adpter scm_cmd_no_raise() (#8825)....
r6164 full_args = []
Toshi MARUYAMA
scm: bazaar: add "scm_cmd_no_raise" method for "bzr diff"....
r5800 full_args += args
Toshi MARUYAMA
scm: bazaar: convert command line character encoding to @path_encoding (#11834)...
r10233 full_args_locale = []
full_args.map do |e|
full_args_locale << scm_iconv(@path_encoding, 'UTF-8', e)
end
Toshi MARUYAMA
scm: bazaar: use self.class.sq_bin for command name at adpter scm_cmd_no_raise() (#8825)....
r6164 ret = shellout(
Toshi MARUYAMA
scm: bazaar: convert command line character encoding to @path_encoding (#11834)...
r10233 self.class.sq_bin + ' ' +
full_args_locale.map { |e| shell_quote e.to_s }.join(' '),
Toshi MARUYAMA
scm: bazaar: use self.class.sq_bin for command name at adpter scm_cmd_no_raise() (#8825)....
r6164 &block
)
Toshi MARUYAMA
scm: bazaar: add "scm_cmd_no_raise" method for "bzr diff"....
r5800 ret
end
private :scm_cmd_no_raise
Toshi MARUYAMA
scm: bazaar: add adapter "bzr_target()" method to common use....
r5787 def bzr_target(path)
target(path, false)
end
private :bzr_target
Jean-Philippe Lang
Added Bazaar adapter....
r937 end
end
end
end