@@ -117,53 +117,45 module Redmine | |||||
117 | entries.sort_by_name |
|
117 | entries.sort_by_name | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | # Fetch the revisions by using a template file that |
|
120 | def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) | |
|
121 | revs = Revisions.new | |||
|
122 | each_revision(path, identifier_from, identifier_to, options) { |e| revs << e } | |||
|
123 | revs | |||
|
124 | end | |||
|
125 | ||||
|
126 | # Iterates the revisions by using a template file that | |||
121 | # makes Mercurial produce a xml output. |
|
127 | # makes Mercurial produce a xml output. | |
122 |
def revision |
|
128 | def each_revision(path=nil, identifier_from=nil, identifier_to=nil, options={}) | |
123 | revisions = Revisions.new |
|
129 | hg_args = ['log', '--debug', '-C', '--style', self.class.template_path] | |
124 | cmd = "#{self.class.sq_bin} --debug --encoding utf8 -R #{target('')} log -C --style #{shell_quote self.class.template_path}" |
|
130 | hg_args << '-r' << "#{hgrev(identifier_from)}:#{hgrev(identifier_to)}" | |
125 | if identifier_from && identifier_to |
|
131 | hg_args << '--limit' << options[:limit] if options[:limit] | |
126 | cmd << " -r #{hgrev(identifier_from, true)}:#{hgrev(identifier_to, true)}" |
|
132 | hg_args << hgtarget(path) unless path.blank? | |
127 | elsif identifier_from |
|
133 | log = hg(*hg_args) do |io| | |
128 | cmd << " -r #{hgrev(identifier_from, true)}:" |
|
134 | # Mercurial < 1.5 does not support footer template for '</log>' | |
129 | end |
|
135 | ActiveSupport::XmlMini.parse("#{io.read}</log>")['log'] | |
130 | cmd << " --limit #{options[:limit].to_i}" if options[:limit] |
|
136 | end | |
131 | cmd << " #{shell_quote path}" unless path.blank? |
|
137 | ||
132 | shellout(cmd) do |io| |
|
138 | as_ary(log['logentry']).each do |le| | |
133 | begin |
|
139 | cpalist = as_ary(le['paths']['path-copied']).map do |e| | |
134 | # HG doesn't close the XML Document... |
|
140 | [e['__content__'], e['copyfrom-path']].map { |s| CGI.unescape(s) } | |
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($!) |
|
|||
163 | end |
|
141 | end | |
164 | end |
|
142 | cpmap = Hash[*cpalist.flatten] | |
165 | return nil if $? && $?.exitstatus != 0 |
|
143 | ||
166 | revisions |
|
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 | end |
|
159 | end | |
168 |
|
160 | |||
169 | def diff(path, identifier_from, identifier_to=nil) |
|
161 | def diff(path, identifier_from, identifier_to=nil) | |
@@ -249,6 +241,12 module Redmine | |||||
249 | root_url + '/' + without_leading_slash(path) |
|
241 | root_url + '/' + without_leading_slash(path) | |
250 | end |
|
242 | end | |
251 | private :hgtarget |
|
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 | end |
|
250 | end | |
253 | end |
|
251 | end | |
254 | end |
|
252 | end |
General Comments 0
You need to be logged in to leave comments.
Login now