Commit e2df831b authored by Toshi MARUYAMA's avatar Toshi MARUYAMA

scm: mercurial: accept both of revision and nodeid as changeset id (#3724).

Contributed by Yuya Nishihara.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4654 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 3ad213c2
......@@ -55,6 +55,17 @@ class Repository::Mercurial < Repository
entries
end
# Finds and returns a revision with a number or the beginning of a hash
def find_changeset_by_name(name)
if /[^\d]/ =~ name or name.to_s.size > 8
e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
else
e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
end
return e if e
changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch
end
# Returns the latest changesets for +path+; sorted by revision number
def latest_changesets(path, rev, limit=10)
if path.blank?
......
......@@ -47,6 +47,17 @@ begin
assert_nil @adapter.cat("sources/welcome_controller.rb")
end
def test_access_by_nodeid
path = 'sources/welcome_controller.rb'
assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
end
def test_access_by_fuzzy_nodeid
path = 'sources/welcome_controller.rb'
# falls back to nodeid
assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
end
private
def test_hgversion_for(hgversion, version)
......
......@@ -35,7 +35,8 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
assert_equal 17, @repository.changesets.count
assert_equal 25, @repository.changes.count
assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
assert_equal "Initial import.\nThe repository contains 3 files.",
@repository.changesets.find_by_revision('0').comments
end
def test_fetch_changesets_incremental
......@@ -51,7 +52,9 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
def test_entries
assert_equal 2, @repository.entries("sources", 2).size
assert_equal 2, @repository.entries("sources", '400bb8672109').size
assert_equal 1, @repository.entries("sources", 3).size
assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
end
def test_locate_on_outdated_repository
......@@ -122,6 +125,20 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
assert_equal '/README', c2[0].from_path
end
def test_find_changeset_by_name
@repository.fetch_changesets
@repository.reload
%w|2 400bb8672109 400|.each do |r|
assert_equal @repository.find_changeset_by_name(r).revision, '2'
end
end
def test_find_changeset_by_invalid_name
@repository.fetch_changesets
@repository.reload
assert_nil @repository.find_changeset_by_name('100000')
end
else
puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
def test_fake; assert true end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment