scm: mercurial: fix diff and test for accept both of revision number and changeset id (#3724).
Diff of changeset can be wrong if the previous changeset isn't the parent. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4662 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0743ba89d4
commit
5207211b6d
|
@ -153,15 +153,13 @@ module Redmine
|
||||||
|
|
||||||
def diff(path, identifier_from, identifier_to=nil)
|
def diff(path, identifier_from, identifier_to=nil)
|
||||||
path ||= ''
|
path ||= ''
|
||||||
|
diff_args = ''
|
||||||
if identifier_to
|
if identifier_to
|
||||||
identifier_to = identifier_to.to_i
|
diff_args = "-r #{hgrev(identifier_to)} -r #{hgrev(identifier_from)}"
|
||||||
else
|
else
|
||||||
identifier_to = identifier_from.to_i - 1
|
diff_args = "-c #{hgrev(identifier_from)}"
|
||||||
end
|
end
|
||||||
if identifier_from
|
cmd = "#{HG_BIN} -R #{target('')} diff --nodates #{diff_args}"
|
||||||
identifier_from = identifier_from.to_i
|
|
||||||
end
|
|
||||||
cmd = "#{HG_BIN} -R #{target('')} diff -r #{identifier_to} -r #{identifier_from} --nodates"
|
|
||||||
cmd << " -I #{target(path)}" unless path.empty?
|
cmd << " -I #{target(path)}" unless path.empty?
|
||||||
diff = []
|
diff = []
|
||||||
shellout(cmd) do |io|
|
shellout(cmd) do |io|
|
||||||
|
@ -203,6 +201,12 @@ module Redmine
|
||||||
return nil if $? && $?.exitstatus != 0
|
return nil if $? && $?.exitstatus != 0
|
||||||
blame
|
blame
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns correct revision identifier
|
||||||
|
def hgrev(identifier)
|
||||||
|
identifier.blank? ? 'tip' : identifier.to_s
|
||||||
|
end
|
||||||
|
private :hgrev
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,24 @@ begin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_diff
|
||||||
|
assert_nil @adapter.diff(nil, '100000')
|
||||||
|
assert_nil @adapter.diff(nil, '100000', '200000')
|
||||||
|
[2, '400bb8672109', '400', 400].each do |r1|
|
||||||
|
diff1 = @adapter.diff(nil, r1)
|
||||||
|
assert_equal 28, diff1.size
|
||||||
|
assert_equal "+ return true unless klass.respond_to?('watched_by')\r\n", diff1[24]
|
||||||
|
[4, 'def6d2f1254a'].each do |r2|
|
||||||
|
diff2 = @adapter.diff(nil,r1,r2)
|
||||||
|
assert_equal 50, diff2.size
|
||||||
|
assert_equal "+class WelcomeController < ApplicationController\r\n", diff2[42]
|
||||||
|
diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
|
||||||
|
assert_equal 20, diff3.size
|
||||||
|
assert_equal "+ @watched.remove_watcher(user)\r\n", diff3[12]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_cat
|
def test_cat
|
||||||
[2, '400bb8672109', '400', 400].each do |r|
|
[2, '400bb8672109', '400', 400].each do |r|
|
||||||
buf = @adapter.cat('sources/welcome_controller.rb', r)
|
buf = @adapter.cat('sources/welcome_controller.rb', r)
|
||||||
|
|
Loading…
Reference in New Issue