@@ -1,173 +1,173 | |||||
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 | require 'rexml/document' |
|
19 | require 'rexml/document' | |
20 |
|
20 | |||
21 | module Redmine |
|
21 | module Redmine | |
22 | module Scm |
|
22 | module Scm | |
23 | module Adapters |
|
23 | module Adapters | |
24 | class SubversionAdapter < AbstractAdapter |
|
24 | class SubversionAdapter < AbstractAdapter | |
25 |
|
25 | |||
26 | # SVN executable name |
|
26 | # SVN executable name | |
27 | SVN_BIN = "svn" |
|
27 | SVN_BIN = "svn" | |
28 |
|
28 | |||
29 | # Get info about the svn repository |
|
29 | # Get info about the svn repository | |
30 | def info |
|
30 | def info | |
31 | cmd = "#{SVN_BIN} info --xml #{target('')}" |
|
31 | cmd = "#{SVN_BIN} info --xml #{target('')}" | |
32 | cmd << " --username #{@login} --password #{@password}" if @login |
|
32 | cmd << " --username #{@login} --password #{@password}" if @login | |
33 | info = nil |
|
33 | info = nil | |
34 | shellout(cmd) do |io| |
|
34 | shellout(cmd) do |io| | |
35 | begin |
|
35 | begin | |
36 | doc = REXML::Document.new(io) |
|
36 | doc = REXML::Document.new(io) | |
37 | #root_url = doc.elements["info/entry/repository/root"].text |
|
37 | #root_url = doc.elements["info/entry/repository/root"].text | |
38 | info = Info.new({:root_url => doc.elements["info/entry/repository/root"].text, |
|
38 | info = Info.new({:root_url => doc.elements["info/entry/repository/root"].text, | |
39 | :lastrev => Revision.new({ |
|
39 | :lastrev => Revision.new({ | |
40 | :identifier => doc.elements["info/entry/commit"].attributes['revision'], |
|
40 | :identifier => doc.elements["info/entry/commit"].attributes['revision'], | |
41 | :time => Time.parse(doc.elements["info/entry/commit/date"].text), |
|
41 | :time => Time.parse(doc.elements["info/entry/commit/date"].text).localtime, | |
42 | :author => (doc.elements["info/entry/commit/author"] ? doc.elements["info/entry/commit/author"].text : "") |
|
42 | :author => (doc.elements["info/entry/commit/author"] ? doc.elements["info/entry/commit/author"].text : "") | |
43 | }) |
|
43 | }) | |
44 | }) |
|
44 | }) | |
45 | rescue |
|
45 | rescue | |
46 | end |
|
46 | end | |
47 | end |
|
47 | end | |
48 | return nil if $? && $?.exitstatus != 0 |
|
48 | return nil if $? && $?.exitstatus != 0 | |
49 | info |
|
49 | info | |
50 | rescue Errno::ENOENT => e |
|
50 | rescue Errno::ENOENT => e | |
51 | return nil |
|
51 | return nil | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | # Returns the entry identified by path and revision identifier |
|
54 | # Returns the entry identified by path and revision identifier | |
55 | # or nil if entry doesn't exist in the repository |
|
55 | # or nil if entry doesn't exist in the repository | |
56 | def entry(path=nil, identifier=nil) |
|
56 | def entry(path=nil, identifier=nil) | |
57 | e = entries(path, identifier) |
|
57 | e = entries(path, identifier) | |
58 | e ? e.first : nil |
|
58 | e ? e.first : nil | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | # Returns an Entries collection |
|
61 | # Returns an Entries collection | |
62 | # or nil if the given path doesn't exist in the repository |
|
62 | # or nil if the given path doesn't exist in the repository | |
63 | def entries(path=nil, identifier=nil) |
|
63 | def entries(path=nil, identifier=nil) | |
64 | path ||= '' |
|
64 | path ||= '' | |
65 | identifier = 'HEAD' unless identifier and identifier > 0 |
|
65 | identifier = 'HEAD' unless identifier and identifier > 0 | |
66 | entries = Entries.new |
|
66 | entries = Entries.new | |
67 | cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}" |
|
67 | cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}" | |
68 | cmd << " --username #{@login} --password #{@password}" if @login |
|
68 | cmd << " --username #{@login} --password #{@password}" if @login | |
69 | shellout(cmd) do |io| |
|
69 | shellout(cmd) do |io| | |
70 | begin |
|
70 | begin | |
71 | doc = REXML::Document.new(io) |
|
71 | doc = REXML::Document.new(io) | |
72 | doc.elements.each("lists/list/entry") do |entry| |
|
72 | doc.elements.each("lists/list/entry") do |entry| | |
73 | entries << Entry.new({:name => entry.elements['name'].text, |
|
73 | entries << Entry.new({:name => entry.elements['name'].text, | |
74 | :path => ((path.empty? ? "" : "#{path}/") + entry.elements['name'].text), |
|
74 | :path => ((path.empty? ? "" : "#{path}/") + entry.elements['name'].text), | |
75 | :kind => entry.attributes['kind'], |
|
75 | :kind => entry.attributes['kind'], | |
76 | :size => (entry.elements['size'] and entry.elements['size'].text).to_i, |
|
76 | :size => (entry.elements['size'] and entry.elements['size'].text).to_i, | |
77 | :lastrev => Revision.new({ |
|
77 | :lastrev => Revision.new({ | |
78 | :identifier => entry.elements['commit'].attributes['revision'], |
|
78 | :identifier => entry.elements['commit'].attributes['revision'], | |
79 | :time => Time.parse(entry.elements['commit'].elements['date'].text), |
|
79 | :time => Time.parse(entry.elements['commit'].elements['date'].text).localtime, | |
80 | :author => (entry.elements['commit'].elements['author'] ? entry.elements['commit'].elements['author'].text : "") |
|
80 | :author => (entry.elements['commit'].elements['author'] ? entry.elements['commit'].elements['author'].text : "") | |
81 | }) |
|
81 | }) | |
82 | }) |
|
82 | }) | |
83 | end |
|
83 | end | |
84 | rescue |
|
84 | rescue | |
85 | end |
|
85 | end | |
86 | end |
|
86 | end | |
87 | return nil if $? && $?.exitstatus != 0 |
|
87 | return nil if $? && $?.exitstatus != 0 | |
88 | entries.sort_by_name |
|
88 | entries.sort_by_name | |
89 | rescue Errno::ENOENT => e |
|
89 | rescue Errno::ENOENT => e | |
90 | raise CommandFailed |
|
90 | raise CommandFailed | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) |
|
93 | def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) | |
94 | path ||= '' |
|
94 | path ||= '' | |
95 | identifier_from = 'HEAD' unless identifier_from and identifier_from.to_i > 0 |
|
95 | identifier_from = 'HEAD' unless identifier_from and identifier_from.to_i > 0 | |
96 | identifier_to = 1 unless identifier_to and identifier_to.to_i > 0 |
|
96 | identifier_to = 1 unless identifier_to and identifier_to.to_i > 0 | |
97 | revisions = Revisions.new |
|
97 | revisions = Revisions.new | |
98 | cmd = "#{SVN_BIN} log --xml -r #{identifier_from}:#{identifier_to}" |
|
98 | cmd = "#{SVN_BIN} log --xml -r #{identifier_from}:#{identifier_to}" | |
99 | cmd << " --username #{@login} --password #{@password}" if @login |
|
99 | cmd << " --username #{@login} --password #{@password}" if @login | |
100 | cmd << " --verbose " if options[:with_paths] |
|
100 | cmd << " --verbose " if options[:with_paths] | |
101 | cmd << target(path) |
|
101 | cmd << target(path) | |
102 | shellout(cmd) do |io| |
|
102 | shellout(cmd) do |io| | |
103 | begin |
|
103 | begin | |
104 | doc = REXML::Document.new(io) |
|
104 | doc = REXML::Document.new(io) | |
105 | doc.elements.each("log/logentry") do |logentry| |
|
105 | doc.elements.each("log/logentry") do |logentry| | |
106 | paths = [] |
|
106 | paths = [] | |
107 | logentry.elements.each("paths/path") do |path| |
|
107 | logentry.elements.each("paths/path") do |path| | |
108 | paths << {:action => path.attributes['action'], |
|
108 | paths << {:action => path.attributes['action'], | |
109 | :path => path.text, |
|
109 | :path => path.text, | |
110 | :from_path => path.attributes['copyfrom-path'], |
|
110 | :from_path => path.attributes['copyfrom-path'], | |
111 | :from_revision => path.attributes['copyfrom-rev'] |
|
111 | :from_revision => path.attributes['copyfrom-rev'] | |
112 | } |
|
112 | } | |
113 | end |
|
113 | end | |
114 | paths.sort! { |x,y| x[:path] <=> y[:path] } |
|
114 | paths.sort! { |x,y| x[:path] <=> y[:path] } | |
115 |
|
115 | |||
116 | revisions << Revision.new({:identifier => logentry.attributes['revision'], |
|
116 | revisions << Revision.new({:identifier => logentry.attributes['revision'], | |
117 | :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""), |
|
117 | :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""), | |
118 | :time => Time.parse(logentry.elements['date'].text), |
|
118 | :time => Time.parse(logentry.elements['date'].text).localtime, | |
119 | :message => logentry.elements['msg'].text, |
|
119 | :message => logentry.elements['msg'].text, | |
120 | :paths => paths |
|
120 | :paths => paths | |
121 | }) |
|
121 | }) | |
122 | end |
|
122 | end | |
123 | rescue |
|
123 | rescue | |
124 | end |
|
124 | end | |
125 | end |
|
125 | end | |
126 | return nil if $? && $?.exitstatus != 0 |
|
126 | return nil if $? && $?.exitstatus != 0 | |
127 | revisions |
|
127 | revisions | |
128 | rescue Errno::ENOENT => e |
|
128 | rescue Errno::ENOENT => e | |
129 | raise CommandFailed |
|
129 | raise CommandFailed | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def diff(path, identifier_from, identifier_to=nil, type="inline") |
|
132 | def diff(path, identifier_from, identifier_to=nil, type="inline") | |
133 | path ||= '' |
|
133 | path ||= '' | |
134 | if identifier_to and identifier_to.to_i > 0 |
|
134 | if identifier_to and identifier_to.to_i > 0 | |
135 | identifier_to = identifier_to.to_i |
|
135 | identifier_to = identifier_to.to_i | |
136 | else |
|
136 | else | |
137 | identifier_to = identifier_from.to_i - 1 |
|
137 | identifier_to = identifier_from.to_i - 1 | |
138 | end |
|
138 | end | |
139 | cmd = "#{SVN_BIN} diff -r " |
|
139 | cmd = "#{SVN_BIN} diff -r " | |
140 | cmd << "#{identifier_to}:" |
|
140 | cmd << "#{identifier_to}:" | |
141 | cmd << "#{identifier_from}" |
|
141 | cmd << "#{identifier_from}" | |
142 | cmd << "#{target(path)}@#{identifier_from}" |
|
142 | cmd << "#{target(path)}@#{identifier_from}" | |
143 | cmd << " --username #{@login} --password #{@password}" if @login |
|
143 | cmd << " --username #{@login} --password #{@password}" if @login | |
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 | DiffTableList.new diff, type |
|
151 | DiffTableList.new diff, type | |
152 | rescue Errno::ENOENT => e |
|
152 | rescue Errno::ENOENT => e | |
153 | raise CommandFailed |
|
153 | raise CommandFailed | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def cat(path, identifier=nil) |
|
156 | def cat(path, identifier=nil) | |
157 | identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" |
|
157 | identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" | |
158 | cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}" |
|
158 | cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}" | |
159 | cmd << " --username #{@login} --password #{@password}" if @login |
|
159 | cmd << " --username #{@login} --password #{@password}" if @login | |
160 | cat = nil |
|
160 | cat = nil | |
161 | shellout(cmd) do |io| |
|
161 | shellout(cmd) do |io| | |
162 | io.binmode |
|
162 | io.binmode | |
163 | cat = io.read |
|
163 | cat = io.read | |
164 | end |
|
164 | end | |
165 | return nil if $? && $?.exitstatus != 0 |
|
165 | return nil if $? && $?.exitstatus != 0 | |
166 | cat |
|
166 | cat | |
167 | rescue Errno::ENOENT => e |
|
167 | rescue Errno::ENOENT => e | |
168 | raise CommandFailed |
|
168 | raise CommandFailed | |
169 | end |
|
169 | end | |
170 | end |
|
170 | end | |
171 | end |
|
171 | end | |
172 | end |
|
172 | end | |
173 | end |
|
173 | end |
General Comments 0
You need to be logged in to leave comments.
Login now