@@ -117,53 +117,45 module Redmine | |||
|
117 | 117 | entries.sort_by_name |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | # Fetch the revisions by using a template file that | |
|
121 | # makes Mercurial produce a xml output. | |
|
122 | 120 |
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) |
|
123 |
rev |
|
|
124 | cmd = "#{self.class.sq_bin} --debug --encoding utf8 -R #{target('')} log -C --style #{shell_quote self.class.template_path}" | |
|
125 | if identifier_from && identifier_to | |
|
126 | cmd << " -r #{hgrev(identifier_from, true)}:#{hgrev(identifier_to, true)}" | |
|
127 | elsif identifier_from | |
|
128 | cmd << " -r #{hgrev(identifier_from, true)}:" | |
|
129 | end | |
|
130 | cmd << " --limit #{options[:limit].to_i}" if options[:limit] | |
|
131 | cmd << " #{shell_quote path}" unless path.blank? | |
|
132 | shellout(cmd) do |io| | |
|
133 | begin | |
|
134 | # HG doesn't close the XML Document... | |
|
135 | doc = REXML::Document.new(io.read << "</log>") | |
|
136 | doc.elements.each("log/logentry") do |logentry| | |
|
137 | paths = [] | |
|
138 | copies = logentry.get_elements('paths/path-copied') | |
|
139 | logentry.elements.each("paths/path") do |path| | |
|
140 | # Detect if the added file is a copy | |
|
141 | if path.attributes['action'] == 'A' and c = copies.find{ |e| e.text == path.text } | |
|
142 | from_path = c.attributes['copyfrom-path'] | |
|
143 | from_rev = logentry.attributes['revision'] | |
|
144 | end | |
|
145 | paths << {:action => path.attributes['action'], | |
|
146 | :path => "/#{CGI.unescape(path.text)}", | |
|
147 | :from_path => from_path ? "/#{CGI.unescape(from_path)}" : nil, | |
|
148 | :from_revision => from_rev ? from_rev : nil | |
|
149 | } | |
|
150 | end | |
|
151 | paths.sort! { |x,y| x[:path] <=> y[:path] } | |
|
152 | ||
|
153 | revisions << Revision.new({:revision => logentry.attributes['revision'], | |
|
154 | :scmid => logentry.attributes['node'], | |
|
155 | :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""), | |
|
156 | :time => Time.parse(logentry.elements['date'].text).localtime, | |
|
157 | :message => logentry.elements['msg'].text, | |
|
158 | :paths => paths, | |
|
159 | }) | |
|
160 | end | |
|
161 | rescue | |
|
162 | logger.debug($!) | |
|
121 | revs = Revisions.new | |
|
122 | each_revision(path, identifier_from, identifier_to, options) { |e| revs << e } | |
|
123 | revs | |
|
163 | 124 |
|
|
125 | ||
|
126 | # Iterates the revisions by using a template file that | |
|
127 | # makes Mercurial produce a xml output. | |
|
128 | def each_revision(path=nil, identifier_from=nil, identifier_to=nil, options={}) | |
|
129 | hg_args = ['log', '--debug', '-C', '--style', self.class.template_path] | |
|
130 | hg_args << '-r' << "#{hgrev(identifier_from)}:#{hgrev(identifier_to)}" | |
|
131 | hg_args << '--limit' << options[:limit] if options[:limit] | |
|
132 | hg_args << hgtarget(path) unless path.blank? | |
|
133 | log = hg(*hg_args) do |io| | |
|
134 | # Mercurial < 1.5 does not support footer template for '</log>' | |
|
135 | ActiveSupport::XmlMini.parse("#{io.read}</log>")['log'] | |
|
164 | 136 | end |
|
165 | return nil if $? && $?.exitstatus != 0 | |
|
166 | revisions | |
|
137 | ||
|
138 | as_ary(log['logentry']).each do |le| | |
|
139 | cpalist = as_ary(le['paths']['path-copied']).map do |e| | |
|
140 | [e['__content__'], e['copyfrom-path']].map { |s| CGI.unescape(s) } | |
|
141 | end | |
|
142 | cpmap = Hash[*cpalist.flatten] | |
|
143 | ||
|
144 | paths = as_ary(le['paths']['path']).map do |e| | |
|
145 | p = CGI.unescape(e['__content__']) | |
|
146 | {:action => e['action'], :path => with_leading_slash(p), | |
|
147 | :from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil), | |
|
148 | :from_revision => (cpmap.member?(p) ? le['revision'] : nil)} | |
|
149 | end.sort { |a, b| a[:path] <=> b[:path] } | |
|
150 | ||
|
151 | yield Revision.new(:revision => le['revision'], | |
|
152 | :scmid => le['node'], | |
|
153 | :author => (le['author']['__content__'] rescue ''), | |
|
154 | :time => Time.parse(le['date']['__content__']).localtime, | |
|
155 | :message => le['msg']['__content__'], | |
|
156 | :paths => paths) | |
|
157 | end | |
|
158 | self | |
|
167 | 159 | end |
|
168 | 160 | |
|
169 | 161 | def diff(path, identifier_from, identifier_to=nil) |
@@ -249,6 +241,12 module Redmine | |||
|
249 | 241 | root_url + '/' + without_leading_slash(path) |
|
250 | 242 | end |
|
251 | 243 | private :hgtarget |
|
244 | ||
|
245 | def as_ary(o) | |
|
246 | return [] unless o | |
|
247 | o.is_a?(Array) ? o : Array[o] | |
|
248 | end | |
|
249 | private :as_ary | |
|
252 | 250 | end |
|
253 | 251 | end |
|
254 | 252 | end |
General Comments 0
You need to be logged in to leave comments.
Login now