##// END OF EJS Templates
Fixes Bazaar adapter for JRuby/Win32 (#5404)....
Jean-Philippe Lang -
r3609:6a8dc735d30d
parent child
Show More
@@ -1,186 +1,186
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 = "bzr"
26 BZR_BIN = "bzr"
27
27
28 # Get info about the repository
28 # Get info about the repository
29 def info
29 def info
30 cmd = "#{BZR_BIN} revno #{target('')}"
30 cmd = "#{BZR_BIN} revno #{target('')}"
31 info = nil
31 info = nil
32 shellout(cmd) do |io|
32 shellout(cmd) do |io|
33 if io.read =~ %r{^(\d+)$}
33 if io.read =~ %r{^(\d+)\r?$}
34 info = Info.new({:root_url => url,
34 info = Info.new({:root_url => url,
35 :lastrev => Revision.new({
35 :lastrev => Revision.new({
36 :identifier => $1
36 :identifier => $1
37 })
37 })
38 })
38 })
39 end
39 end
40 end
40 end
41 return nil if $? && $?.exitstatus != 0
41 return nil if $? && $?.exitstatus != 0
42 info
42 info
43 rescue CommandFailed
43 rescue CommandFailed
44 return nil
44 return nil
45 end
45 end
46
46
47 # Returns an Entries collection
47 # Returns an Entries collection
48 # or nil if the given path doesn't exist in the repository
48 # or nil if the given path doesn't exist in the repository
49 def entries(path=nil, identifier=nil)
49 def entries(path=nil, identifier=nil)
50 path ||= ''
50 path ||= ''
51 entries = Entries.new
51 entries = Entries.new
52 cmd = "#{BZR_BIN} ls -v --show-ids"
52 cmd = "#{BZR_BIN} ls -v --show-ids"
53 identifier = -1 unless identifier && identifier.to_i > 0
53 identifier = -1 unless identifier && identifier.to_i > 0
54 cmd << " -r#{identifier.to_i}"
54 cmd << " -r#{identifier.to_i}"
55 cmd << " #{target(path)}"
55 cmd << " #{target(path)}"
56 shellout(cmd) do |io|
56 shellout(cmd) do |io|
57 prefix = "#{url}/#{path}".gsub('\\', '/')
57 prefix = "#{url}/#{path}".gsub('\\', '/')
58 logger.debug "PREFIX: #{prefix}"
58 logger.debug "PREFIX: #{prefix}"
59 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)$}
59 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$}
60 io.each_line do |line|
60 io.each_line do |line|
61 next unless line =~ re
61 next unless line =~ re
62 entries << Entry.new({:name => $3.strip,
62 entries << Entry.new({:name => $3.strip,
63 :path => ((path.empty? ? "" : "#{path}/") + $3.strip),
63 :path => ((path.empty? ? "" : "#{path}/") + $3.strip),
64 :kind => ($4.blank? ? 'file' : 'dir'),
64 :kind => ($4.blank? ? 'file' : 'dir'),
65 :size => nil,
65 :size => nil,
66 :lastrev => Revision.new(:revision => $5.strip)
66 :lastrev => Revision.new(:revision => $5.strip)
67 })
67 })
68 end
68 end
69 end
69 end
70 return nil if $? && $?.exitstatus != 0
70 return nil if $? && $?.exitstatus != 0
71 logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug?
71 logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug?
72 entries.sort_by_name
72 entries.sort_by_name
73 end
73 end
74
74
75 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
75 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
76 path ||= ''
76 path ||= ''
77 identifier_from = 'last:1' unless identifier_from and identifier_from.to_i > 0
77 identifier_from = 'last:1' unless identifier_from and identifier_from.to_i > 0
78 identifier_to = 1 unless identifier_to and identifier_to.to_i > 0
78 identifier_to = 1 unless identifier_to and identifier_to.to_i > 0
79 revisions = Revisions.new
79 revisions = Revisions.new
80 cmd = "#{BZR_BIN} log -v --show-ids -r#{identifier_to.to_i}..#{identifier_from} #{target(path)}"
80 cmd = "#{BZR_BIN} log -v --show-ids -r#{identifier_to.to_i}..#{identifier_from} #{target(path)}"
81 shellout(cmd) do |io|
81 shellout(cmd) do |io|
82 revision = nil
82 revision = nil
83 parsing = nil
83 parsing = nil
84 io.each_line do |line|
84 io.each_line do |line|
85 if line =~ /^----/
85 if line =~ /^----/
86 revisions << revision if revision
86 revisions << revision if revision
87 revision = Revision.new(:paths => [], :message => '')
87 revision = Revision.new(:paths => [], :message => '')
88 parsing = nil
88 parsing = nil
89 else
89 else
90 next unless revision
90 next unless revision
91
91
92 if line =~ /^revno: (\d+)($|\s\[merge\]$)/
92 if line =~ /^revno: (\d+)($|\s\[merge\]$)/
93 revision.identifier = $1.to_i
93 revision.identifier = $1.to_i
94 elsif line =~ /^committer: (.+)$/
94 elsif line =~ /^committer: (.+)$/
95 revision.author = $1.strip
95 revision.author = $1.strip
96 elsif line =~ /^revision-id:(.+)$/
96 elsif line =~ /^revision-id:(.+)$/
97 revision.scmid = $1.strip
97 revision.scmid = $1.strip
98 elsif line =~ /^timestamp: (.+)$/
98 elsif line =~ /^timestamp: (.+)$/
99 revision.time = Time.parse($1).localtime
99 revision.time = Time.parse($1).localtime
100 elsif line =~ /^ -----/
100 elsif line =~ /^ -----/
101 # partial revisions
101 # partial revisions
102 parsing = nil unless parsing == 'message'
102 parsing = nil unless parsing == 'message'
103 elsif line =~ /^(message|added|modified|removed|renamed):/
103 elsif line =~ /^(message|added|modified|removed|renamed):/
104 parsing = $1
104 parsing = $1
105 elsif line =~ /^ (.*)$/
105 elsif line =~ /^ (.*)$/
106 if parsing == 'message'
106 if parsing == 'message'
107 revision.message << "#{$1}\n"
107 revision.message << "#{$1}\n"
108 else
108 else
109 if $1 =~ /^(.*)\s+(\S+)$/
109 if $1 =~ /^(.*)\s+(\S+)$/
110 path = $1.strip
110 path = $1.strip
111 revid = $2
111 revid = $2
112 case parsing
112 case parsing
113 when 'added'
113 when 'added'
114 revision.paths << {:action => 'A', :path => "/#{path}", :revision => revid}
114 revision.paths << {:action => 'A', :path => "/#{path}", :revision => revid}
115 when 'modified'
115 when 'modified'
116 revision.paths << {:action => 'M', :path => "/#{path}", :revision => revid}
116 revision.paths << {:action => 'M', :path => "/#{path}", :revision => revid}
117 when 'removed'
117 when 'removed'
118 revision.paths << {:action => 'D', :path => "/#{path}", :revision => revid}
118 revision.paths << {:action => 'D', :path => "/#{path}", :revision => revid}
119 when 'renamed'
119 when 'renamed'
120 new_path = path.split('=>').last
120 new_path = path.split('=>').last
121 revision.paths << {:action => 'M', :path => "/#{new_path.strip}", :revision => revid} if new_path
121 revision.paths << {:action => 'M', :path => "/#{new_path.strip}", :revision => revid} if new_path
122 end
122 end
123 end
123 end
124 end
124 end
125 else
125 else
126 parsing = nil
126 parsing = nil
127 end
127 end
128 end
128 end
129 end
129 end
130 revisions << revision if revision
130 revisions << revision if revision
131 end
131 end
132 return nil if $? && $?.exitstatus != 0
132 return nil if $? && $?.exitstatus != 0
133 revisions
133 revisions
134 end
134 end
135
135
136 def diff(path, identifier_from, identifier_to=nil)
136 def diff(path, identifier_from, identifier_to=nil)
137 path ||= ''
137 path ||= ''
138 if identifier_to
138 if identifier_to
139 identifier_to = identifier_to.to_i
139 identifier_to = identifier_to.to_i
140 else
140 else
141 identifier_to = identifier_from.to_i - 1
141 identifier_to = identifier_from.to_i - 1
142 end
142 end
143 cmd = "#{BZR_BIN} diff -r#{identifier_to}..#{identifier_from} #{target(path)}"
143 cmd = "#{BZR_BIN} diff -r#{identifier_to}..#{identifier_from} #{target(path)}"
144 diff = []
144 diff = []
145 shellout(cmd) do |io|
145 shellout(cmd) do |io|
146 io.each_line do |line|
146 io.each_line do |line|
147 diff << line
147 diff << line
148 end
148 end
149 end
149 end
150 #return nil if $? && $?.exitstatus != 0
150 #return nil if $? && $?.exitstatus != 0
151 diff
151 diff
152 end
152 end
153
153
154 def cat(path, identifier=nil)
154 def cat(path, identifier=nil)
155 cmd = "#{BZR_BIN} cat"
155 cmd = "#{BZR_BIN} cat"
156 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0
156 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0
157 cmd << " #{target(path)}"
157 cmd << " #{target(path)}"
158 cat = nil
158 cat = nil
159 shellout(cmd) do |io|
159 shellout(cmd) do |io|
160 io.binmode
160 io.binmode
161 cat = io.read
161 cat = io.read
162 end
162 end
163 return nil if $? && $?.exitstatus != 0
163 return nil if $? && $?.exitstatus != 0
164 cat
164 cat
165 end
165 end
166
166
167 def annotate(path, identifier=nil)
167 def annotate(path, identifier=nil)
168 cmd = "#{BZR_BIN} annotate --all"
168 cmd = "#{BZR_BIN} annotate --all"
169 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0
169 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0
170 cmd << " #{target(path)}"
170 cmd << " #{target(path)}"
171 blame = Annotate.new
171 blame = Annotate.new
172 shellout(cmd) do |io|
172 shellout(cmd) do |io|
173 author = nil
173 author = nil
174 identifier = nil
174 identifier = nil
175 io.each_line do |line|
175 io.each_line do |line|
176 next unless line =~ %r{^(\d+) ([^|]+)\| (.*)$}
176 next unless line =~ %r{^(\d+) ([^|]+)\| (.*)$}
177 blame.add_line($3.rstrip, Revision.new(:identifier => $1.to_i, :author => $2.strip))
177 blame.add_line($3.rstrip, Revision.new(:identifier => $1.to_i, :author => $2.strip))
178 end
178 end
179 end
179 end
180 return nil if $? && $?.exitstatus != 0
180 return nil if $? && $?.exitstatus != 0
181 blame
181 blame
182 end
182 end
183 end
183 end
184 end
184 end
185 end
185 end
186 end
186 end
General Comments 0
You need to be logged in to leave comments. Login now