From 5207211b6d02dd36a8aa3e691d125a03137cdf2e Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 8 Jan 2011 13:51:43 +0000 Subject: [PATCH] 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 --- lib/redmine/scm/adapters/mercurial_adapter.rb | 16 ++++++++++------ .../scm/adapters/mercurial_adapter_test.rb | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb index be755419f..7607dd1ca 100644 --- a/lib/redmine/scm/adapters/mercurial_adapter.rb +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb @@ -153,15 +153,13 @@ module Redmine def diff(path, identifier_from, identifier_to=nil) path ||= '' + diff_args = '' if identifier_to - identifier_to = identifier_to.to_i + diff_args = "-r #{hgrev(identifier_to)} -r #{hgrev(identifier_from)}" else - identifier_to = identifier_from.to_i - 1 + diff_args = "-c #{hgrev(identifier_from)}" end - if identifier_from - identifier_from = identifier_from.to_i - end - cmd = "#{HG_BIN} -R #{target('')} diff -r #{identifier_to} -r #{identifier_from} --nodates" + cmd = "#{HG_BIN} -R #{target('')} diff --nodates #{diff_args}" cmd << " -I #{target(path)}" unless path.empty? diff = [] shellout(cmd) do |io| @@ -203,6 +201,12 @@ module Redmine return nil if $? && $?.exitstatus != 0 blame end + + # Returns correct revision identifier + def hgrev(identifier) + identifier.blank? ? 'tip' : identifier.to_s + end + private :hgrev end end end diff --git a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb index afd7b2700..088664bdd 100644 --- a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb @@ -42,6 +42,24 @@ begin 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 [2, '400bb8672109', '400', 400].each do |r| buf = @adapter.cat('sources/welcome_controller.rb', r)