scm: mercurial: annotate accepts both of revision number and changeset id (#3724).
Change annotate revision label to Mercurial style '4:def6d2f1254a' and use identifier. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4663 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
5207211b6d
commit
ef28bf6d88
|
@ -183,25 +183,33 @@ module Redmine
|
||||||
return nil if $? && $?.exitstatus != 0
|
return nil if $? && $?.exitstatus != 0
|
||||||
cat
|
cat
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotate(path, identifier=nil)
|
def annotate(path, identifier=nil)
|
||||||
path ||= ''
|
path ||= ''
|
||||||
cmd = "#{HG_BIN} -R #{target('')}"
|
cmd = "#{HG_BIN} -R #{target('')}"
|
||||||
cmd << " annotate -n -u"
|
cmd << " annotate -ncu"
|
||||||
cmd << " -r " + shell_quote(identifier ? identifier.to_s : "tip")
|
cmd << " -r #{hgrev(identifier)}"
|
||||||
cmd << " -r #{identifier.to_i}" if identifier
|
|
||||||
cmd << " #{target(path)}"
|
cmd << " #{target(path)}"
|
||||||
blame = Annotate.new
|
blame = Annotate.new
|
||||||
shellout(cmd) do |io|
|
shellout(cmd) do |io|
|
||||||
io.each_line do |line|
|
io.each_line do |line|
|
||||||
next unless line =~ %r{^([^:]+)\s(\d+):(.*)$}
|
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
|
||||||
blame.add_line($3.rstrip, Revision.new(:identifier => $2.to_i, :author => $1.strip))
|
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
|
||||||
|
:identifier => $3)
|
||||||
|
blame.add_line($4.rstrip, r)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil if $? && $?.exitstatus != 0
|
return nil if $? && $?.exitstatus != 0
|
||||||
blame
|
blame
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Revision < Redmine::Scm::Adapters::Revision
|
||||||
|
# Returns the readable identifier
|
||||||
|
def format_identifier
|
||||||
|
"#{revision}:#{scmid}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Returns correct revision identifier
|
# Returns correct revision identifier
|
||||||
def hgrev(identifier)
|
def hgrev(identifier)
|
||||||
identifier.blank? ? 'tip' : identifier.to_s
|
identifier.blank? ? 'tip' : identifier.to_s
|
||||||
|
|
|
@ -134,7 +134,7 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase
|
||||||
:attributes => { :class => /diff_out/ },
|
:attributes => { :class => /diff_out/ },
|
||||||
:content => /def remove/ }
|
:content => /def remove/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_annotate
|
def test_annotate
|
||||||
get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
@ -147,8 +147,7 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase
|
||||||
{
|
{
|
||||||
:tag => 'td',
|
:tag => 'td',
|
||||||
:attributes => { :class => 'revision' },
|
:attributes => { :class => 'revision' },
|
||||||
:child => { :tag => 'a', :content => '4' }
|
:child => { :tag => 'a', :content => '4:def6d2f1254a' }
|
||||||
# :child => { :tag => 'a', :content => /4:def6d2f1/ }
|
|
||||||
}
|
}
|
||||||
assert_tag :tag => 'th',
|
assert_tag :tag => 'th',
|
||||||
:content => '23',
|
:content => '23',
|
||||||
|
|
|
@ -71,6 +71,19 @@ begin
|
||||||
assert_nil @adapter.cat('sources/welcome_controller.rb')
|
assert_nil @adapter.cat('sources/welcome_controller.rb')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_annotate
|
||||||
|
assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
|
||||||
|
[2, '400bb8672109', '400', 400].each do |r|
|
||||||
|
ann = @adapter.annotate('sources/welcome_controller.rb', r)
|
||||||
|
assert ann
|
||||||
|
assert_equal '1', ann.revisions[17].revision
|
||||||
|
assert_equal '9d5b5b004199', ann.revisions[17].identifier
|
||||||
|
assert_equal 'jsmith', ann.revisions[0].author
|
||||||
|
assert_equal 25, ann.lines.length
|
||||||
|
assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_access_by_nodeid
|
def test_access_by_nodeid
|
||||||
path = 'sources/welcome_controller.rb'
|
path = 'sources/welcome_controller.rb'
|
||||||
assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
|
assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
|
||||||
|
|
Loading…
Reference in New Issue