@@ -1,5 +1,5 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-200 |
|
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 |
|
58 | info = Info.new({:root_url => doc['info']['entry']['repository']['root']['__content__'], | |
59 | :lastrev => Revision.new({ |
|
59 | :lastrev => Revision.new({ | |
60 |
:identifier => doc |
|
60 | :identifier => doc['info']['entry']['commit']['revision'], | |
61 |
:time => Time.parse(doc |
|
61 | :time => Time.parse(doc['info']['entry']['commit']['date']['__content__']).localtime, | |
62 |
:author => (doc |
|
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 = |
|
85 | doc = ActiveSupport::XmlMini.parse(output) | |
86 |
doc |
|
86 | each_xml_element(doc['lists']['list'], 'entry') do |entry| | |
87 |
commit = entry |
|
87 | commit = entry['commit'] | |
88 |
commit_date = commit |
|
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 |
|
91 | next if entry['kind'] == 'dir' && commit_date.nil? | |
92 |
name = entry |
|
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 |
|
95 | :kind => entry['kind'], | |
96 |
:size => ((s = entry |
|
96 | :size => ((s = entry['size']) ? s['__content__'].to_i : nil), | |
97 | :lastrev => Revision.new({ |
|
97 | :lastrev => Revision.new({ | |
98 |
:identifier => commit |
|
98 | :identifier => commit['revision'], | |
99 |
:time => Time.parse(commit_date.t |
|
99 | :time => Time.parse(commit_date['__content__'].to_s).localtime, | |
100 |
:author => ((a = commit |
|
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 = |
|
125 | doc = ActiveSupport::XmlMini.parse(output) | |
126 |
doc |
|
126 | each_xml_element(doc['properties']['target'], 'property') do |property| | |
127 |
properties[ property |
|
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 |
|
150 | each_xml_element(doc['log'], 'logentry') do |logentry| | |
150 | paths = [] |
|
151 | paths = [] | |
151 |
logentry |
|
152 | each_xml_element(logentry['paths'], 'path') do |path| | |
152 |
paths << {:action => path |
|
153 | paths << {:action => path['action'], | |
153 |
:path => path |
|
154 | :path => path['__content__'], | |
154 |
:from_path => path |
|
155 | :from_path => path['copyfrom-path'], | |
155 |
:from_revision => path |
|
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 |
|
161 | revisions << Revision.new({:identifier => logentry['revision'], | |
161 |
:author => (logentry |
|
162 | :author => (logentry['author'] ? logentry['author']['__content__'] : ""), | |
162 |
:time => Time.parse(logentry |
|
163 | :time => Time.parse(logentry['date']['__content__'].to_s).localtime, | |
163 |
:message => logentry |
|
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