##// END OF EJS Templates
Changes SubversionAdapter to use ActiveSupport::XmlMini API for XML parsing....
Jean-Philippe Lang -
r3310:ea3e2b112180
parent child
Show More
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2010 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
@@ -16,7 +16,6
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 require 'rexml/document'
20 require 'uri'
19 require 'uri'
21
20
22 module Redmine
21 module Redmine
@@ -52,14 +51,15 module Redmine
52 cmd << credentials_string
51 cmd << credentials_string
53 info = nil
52 info = nil
54 shellout(cmd) do |io|
53 shellout(cmd) do |io|
54 output = io.read
55 begin
55 begin
56 doc = REXML::Document.new(io)
56 doc = ActiveSupport::XmlMini.parse(output)
57 #root_url = doc.elements["info/entry/repository/root"].text
57 #root_url = doc.elements["info/entry/repository/root"].text
58 info = Info.new({:root_url => doc.elements["info/entry/repository/root"].text,
58 info = Info.new({:root_url => doc['info']['entry']['repository']['root']['__content__'],
59 :lastrev => Revision.new({
59 :lastrev => Revision.new({
60 :identifier => doc.elements["info/entry/commit"].attributes['revision'],
60 :identifier => doc['info']['entry']['commit']['revision'],
61 :time => Time.parse(doc.elements["info/entry/commit/date"].text).localtime,
61 :time => Time.parse(doc['info']['entry']['commit']['date']['__content__']).localtime,
62 :author => (doc.elements["info/entry/commit/author"] ? doc.elements["info/entry/commit/author"].text : "")
62 :author => (doc['info']['entry']['commit']['author'] ? doc['info']['entry']['commit']['author']['__content__'] : "")
63 })
63 })
64 })
64 })
65 rescue
65 rescue
@@ -82,22 +82,22 module Redmine
82 shellout(cmd) do |io|
82 shellout(cmd) do |io|
83 output = io.read
83 output = io.read
84 begin
84 begin
85 doc = REXML::Document.new(output)
85 doc = ActiveSupport::XmlMini.parse(output)
86 doc.elements.each("lists/list/entry") do |entry|
86 each_xml_element(doc['lists']['list'], 'entry') do |entry|
87 commit = entry.elements['commit']
87 commit = entry['commit']
88 commit_date = commit.elements['date']
88 commit_date = commit['date']
89 # Skip directory if there is no commit date (usually that
89 # Skip directory if there is no commit date (usually that
90 # means that we don't have read access to it)
90 # means that we don't have read access to it)
91 next if entry.attributes['kind'] == 'dir' && commit_date.nil?
91 next if entry['kind'] == 'dir' && commit_date.nil?
92 name = entry.elements['name'].text
92 name = entry['name']['__content__']
93 entries << Entry.new({:name => URI.unescape(name),
93 entries << Entry.new({:name => URI.unescape(name),
94 :path => ((path.empty? ? "" : "#{path}/") + name),
94 :path => ((path.empty? ? "" : "#{path}/") + name),
95 :kind => entry.attributes['kind'],
95 :kind => entry['kind'],
96 :size => ((s = entry.elements['size']) ? s.text.to_i : nil),
96 :size => ((s = entry['size']) ? s['__content__'].to_i : nil),
97 :lastrev => Revision.new({
97 :lastrev => Revision.new({
98 :identifier => commit.attributes['revision'],
98 :identifier => commit['revision'],
99 :time => Time.parse(commit_date.text).localtime,
99 :time => Time.parse(commit_date['__content__'].to_s).localtime,
100 :author => ((a = commit.elements['author']) ? a.text : nil)
100 :author => ((a = commit['author']) ? a['__content__'] : nil)
101 })
101 })
102 })
102 })
103 end
103 end
@@ -122,9 +122,9 module Redmine
122 shellout(cmd) do |io|
122 shellout(cmd) do |io|
123 output = io.read
123 output = io.read
124 begin
124 begin
125 doc = REXML::Document.new(output)
125 doc = ActiveSupport::XmlMini.parse(output)
126 doc.elements.each("properties/target/property") do |property|
126 each_xml_element(doc['properties']['target'], 'property') do |property|
127 properties[ property.attributes['name'] ] = property.text
127 properties[ property['name'] ] = property['__content__'].to_s
128 end
128 end
129 rescue
129 rescue
130 end
130 end
@@ -144,23 +144,24 module Redmine
144 cmd << " --limit #{options[:limit].to_i}" if options[:limit]
144 cmd << " --limit #{options[:limit].to_i}" if options[:limit]
145 cmd << ' ' + target(URI.escape(path))
145 cmd << ' ' + target(URI.escape(path))
146 shellout(cmd) do |io|
146 shellout(cmd) do |io|
147 output = io.read
147 begin
148 begin
148 doc = REXML::Document.new(io)
149 doc = ActiveSupport::XmlMini.parse(output)
149 doc.elements.each("log/logentry") do |logentry|
150 each_xml_element(doc['log'], 'logentry') do |logentry|
150 paths = []
151 paths = []
151 logentry.elements.each("paths/path") do |path|
152 each_xml_element(logentry['paths'], 'path') do |path|
152 paths << {:action => path.attributes['action'],
153 paths << {:action => path['action'],
153 :path => path.text,
154 :path => path['__content__'],
154 :from_path => path.attributes['copyfrom-path'],
155 :from_path => path['copyfrom-path'],
155 :from_revision => path.attributes['copyfrom-rev']
156 :from_revision => path['copyfrom-rev']
156 }
157 }
157 end
158 end if logentry['paths'] && logentry['paths']['path']
158 paths.sort! { |x,y| x[:path] <=> y[:path] }
159 paths.sort! { |x,y| x[:path] <=> y[:path] }
159
160
160 revisions << Revision.new({:identifier => logentry.attributes['revision'],
161 revisions << Revision.new({:identifier => logentry['revision'],
161 :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
162 :author => (logentry['author'] ? logentry['author']['__content__'] : ""),
162 :time => Time.parse(logentry.elements['date'].text).localtime,
163 :time => Time.parse(logentry['date']['__content__'].to_s).localtime,
163 :message => logentry.elements['msg'].text,
164 :message => logentry['msg']['__content__'],
164 :paths => paths
165 :paths => paths
165 })
166 })
166 end
167 end
@@ -228,6 +229,20 module Redmine
228 str << " --no-auth-cache --non-interactive"
229 str << " --no-auth-cache --non-interactive"
229 str
230 str
230 end
231 end
232
233 # Helper that iterates over the child elements of a xml node
234 # MiniXml returns a hash when a single child is found or an array of hashes for multiple children
235 def each_xml_element(node, name)
236 if node && node[name]
237 if node[name].is_a?(Hash)
238 yield node[name]
239 else
240 node[name].each do |element|
241 yield element
242 end
243 end
244 end
245 end
231 end
246 end
232 end
247 end
233 end
248 end
General Comments 0
You need to be logged in to leave comments. Login now