Mercurial > hg > soundsoftware-site
comparison lib/redmine/scm/adapters/bazaar_adapter.rb @ 245:051f544170fe
* Update to SVN trunk revision 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 11:42:28 +0000 |
parents | 0579821a129a |
children | cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
244:8972b600f4fb | 245:051f544170fe |
---|---|
17 | 17 |
18 require 'redmine/scm/adapters/abstract_adapter' | 18 require 'redmine/scm/adapters/abstract_adapter' |
19 | 19 |
20 module Redmine | 20 module Redmine |
21 module Scm | 21 module Scm |
22 module Adapters | 22 module Adapters |
23 class BazaarAdapter < AbstractAdapter | 23 class BazaarAdapter < AbstractAdapter |
24 | 24 |
25 # Bazaar executable name | 25 # Bazaar executable name |
26 BZR_BIN = Redmine::Configuration['scm_bazaar_command'] || "bzr" | 26 BZR_BIN = Redmine::Configuration['scm_bazaar_command'] || "bzr" |
27 | 27 |
28 class << self | |
29 def client_command | |
30 @@bin ||= BZR_BIN | |
31 end | |
32 | |
33 def sq_bin | |
34 @@sq_bin ||= shell_quote(BZR_BIN) | |
35 end | |
36 | |
37 def client_version | |
38 @@client_version ||= (scm_command_version || []) | |
39 end | |
40 | |
41 def client_available | |
42 !client_version.empty? | |
43 end | |
44 | |
45 def scm_command_version | |
46 scm_version = scm_version_from_command_line.dup | |
47 if scm_version.respond_to?(:force_encoding) | |
48 scm_version.force_encoding('ASCII-8BIT') | |
49 end | |
50 if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)}) | |
51 m[2].scan(%r{\d+}).collect(&:to_i) | |
52 end | |
53 end | |
54 | |
55 def scm_version_from_command_line | |
56 shellout("#{sq_bin} --version") { |io| io.read }.to_s | |
57 end | |
58 end | |
59 | |
28 # Get info about the repository | 60 # Get info about the repository |
29 def info | 61 def info |
30 cmd = "#{BZR_BIN} revno #{target('')}" | 62 cmd = "#{self.class.sq_bin} revno #{target('')}" |
31 info = nil | 63 info = nil |
32 shellout(cmd) do |io| | 64 shellout(cmd) do |io| |
33 if io.read =~ %r{^(\d+)\r?$} | 65 if io.read =~ %r{^(\d+)\r?$} |
34 info = Info.new({:root_url => url, | 66 info = Info.new({:root_url => url, |
35 :lastrev => Revision.new({ | 67 :lastrev => Revision.new({ |
41 return nil if $? && $?.exitstatus != 0 | 73 return nil if $? && $?.exitstatus != 0 |
42 info | 74 info |
43 rescue CommandFailed | 75 rescue CommandFailed |
44 return nil | 76 return nil |
45 end | 77 end |
46 | 78 |
47 # Returns an Entries collection | 79 # Returns an Entries collection |
48 # or nil if the given path doesn't exist in the repository | 80 # or nil if the given path doesn't exist in the repository |
49 def entries(path=nil, identifier=nil) | 81 def entries(path=nil, identifier=nil) |
50 path ||= '' | 82 path ||= '' |
51 entries = Entries.new | 83 entries = Entries.new |
52 cmd = "#{BZR_BIN} ls -v --show-ids" | 84 cmd = "#{self.class.sq_bin} ls -v --show-ids" |
53 identifier = -1 unless identifier && identifier.to_i > 0 | 85 identifier = -1 unless identifier && identifier.to_i > 0 |
54 cmd << " -r#{identifier.to_i}" | 86 cmd << " -r#{identifier.to_i}" |
55 cmd << " #{target(path)}" | 87 cmd << " #{target(path)}" |
56 shellout(cmd) do |io| | 88 shellout(cmd) do |io| |
57 prefix = "#{url}/#{path}".gsub('\\', '/') | 89 prefix = "#{url}/#{path}".gsub('\\', '/') |
69 end | 101 end |
70 return nil if $? && $?.exitstatus != 0 | 102 return nil if $? && $?.exitstatus != 0 |
71 logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug? | 103 logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug? |
72 entries.sort_by_name | 104 entries.sort_by_name |
73 end | 105 end |
74 | 106 |
75 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) | 107 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) |
76 path ||= '' | 108 path ||= '' |
77 identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : 'last:1' | 109 identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : 'last:1' |
78 identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1 | 110 identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1 |
79 revisions = Revisions.new | 111 revisions = Revisions.new |
80 cmd = "#{BZR_BIN} log -v --show-ids -r#{identifier_to}..#{identifier_from} #{target(path)}" | 112 cmd = "#{self.class.sq_bin} log -v --show-ids -r#{identifier_to}..#{identifier_from} #{target(path)}" |
81 shellout(cmd) do |io| | 113 shellout(cmd) do |io| |
82 revision = nil | 114 revision = nil |
83 parsing = nil | 115 parsing = nil |
84 io.each_line do |line| | 116 io.each_line do |line| |
85 if line =~ /^----/ | 117 if line =~ /^----/ |
130 revisions << revision if revision | 162 revisions << revision if revision |
131 end | 163 end |
132 return nil if $? && $?.exitstatus != 0 | 164 return nil if $? && $?.exitstatus != 0 |
133 revisions | 165 revisions |
134 end | 166 end |
135 | 167 |
136 def diff(path, identifier_from, identifier_to=nil) | 168 def diff(path, identifier_from, identifier_to=nil) |
137 path ||= '' | 169 path ||= '' |
138 if identifier_to | 170 if identifier_to |
139 identifier_to = identifier_to.to_i | 171 identifier_to = identifier_to.to_i |
140 else | 172 else |
141 identifier_to = identifier_from.to_i - 1 | 173 identifier_to = identifier_from.to_i - 1 |
142 end | 174 end |
143 if identifier_from | 175 if identifier_from |
144 identifier_from = identifier_from.to_i | 176 identifier_from = identifier_from.to_i |
145 end | 177 end |
146 cmd = "#{BZR_BIN} diff -r#{identifier_to}..#{identifier_from} #{target(path)}" | 178 cmd = "#{self.class.sq_bin} diff -r#{identifier_to}..#{identifier_from} #{target(path)}" |
147 diff = [] | 179 diff = [] |
148 shellout(cmd) do |io| | 180 shellout(cmd) do |io| |
149 io.each_line do |line| | 181 io.each_line do |line| |
150 diff << line | 182 diff << line |
151 end | 183 end |
152 end | 184 end |
153 #return nil if $? && $?.exitstatus != 0 | 185 #return nil if $? && $?.exitstatus != 0 |
154 diff | 186 diff |
155 end | 187 end |
156 | 188 |
157 def cat(path, identifier=nil) | 189 def cat(path, identifier=nil) |
158 cmd = "#{BZR_BIN} cat" | 190 cmd = "#{self.class.sq_bin} cat" |
159 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0 | 191 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0 |
160 cmd << " #{target(path)}" | 192 cmd << " #{target(path)}" |
161 cat = nil | 193 cat = nil |
162 shellout(cmd) do |io| | 194 shellout(cmd) do |io| |
163 io.binmode | 195 io.binmode |
164 cat = io.read | 196 cat = io.read |
165 end | 197 end |
166 return nil if $? && $?.exitstatus != 0 | 198 return nil if $? && $?.exitstatus != 0 |
167 cat | 199 cat |
168 end | 200 end |
169 | 201 |
170 def annotate(path, identifier=nil) | 202 def annotate(path, identifier=nil) |
171 cmd = "#{BZR_BIN} annotate --all" | 203 cmd = "#{self.class.sq_bin} annotate --all" |
172 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0 | 204 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0 |
173 cmd << " #{target(path)}" | 205 cmd << " #{target(path)}" |
174 blame = Annotate.new | 206 blame = Annotate.new |
175 shellout(cmd) do |io| | 207 shellout(cmd) do |io| |
176 author = nil | 208 author = nil |