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