scm: mercurial: rewrite MercurialAdapter#diff by using helper extension (#4455, #7518).

fix incompatibility of diff with Mercurial < 1.1.

Contributed by Yuya Nishihara.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4854 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-02-16 11:17:58 +00:00
parent 671b16f898
commit 4b1e16e13b
1 changed files with 9 additions and 17 deletions

View File

@ -159,27 +159,19 @@ module Redmine
end
def diff(path, identifier_from, identifier_to=nil)
path ||= ''
diff_args = ''
diff = []
hg_args = %w|rhdiff|
if identifier_to
diff_args = "-r #{hgrev(identifier_to, true)} -r #{hgrev(identifier_from, true)}"
hg_args << '-r' << hgrev(identifier_to) << '-r' << hgrev(identifier_from)
else
if self.class.client_version_above?([1, 2])
diff_args = "-c #{hgrev(identifier_from, true)}"
else
return []
end
hg_args << '-c' << hgrev(identifier_from)
end
cmd = "#{self.class.sq_bin} -R #{target('')} --config diff.git=false diff --nodates #{diff_args}"
cmd << " -I #{target(path)}" unless path.empty?
shellout(cmd) do |io|
io.each_line do |line|
diff << line
end
hg_args << CGI.escape(hgtarget(path)) unless path.blank?
hg *hg_args do |io|
io.collect
end
return nil if $? && $?.exitstatus != 0
diff
rescue HgCommandAborted
nil # means not found
end
def cat(path, identifier=nil)