scm: git: add model method to get heads from extra_info branches hash (#8857)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8816 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-02-09 00:11:03 +00:00
parent 34b3a9851f
commit 693191e8bf
2 changed files with 23 additions and 0 deletions

View File

@ -194,6 +194,13 @@ class Repository::Git < Repository
end
private :save_revision
def heads_from_branches_hash
h1 = extra_info || {}
h = h1.dup
h["branches"] ||= {}
h['branches'].map{|br, hs| hs['last_scmid']}
end
def latest_changesets(path,rev,limit=10)
revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
return [] if revisions.nil? || revisions.empty?

View File

@ -244,6 +244,22 @@ class RepositoryGitTest < ActiveSupport::TestCase
assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
end
def test_heads_from_branches_hash
assert_nil @repository.extra_info
assert_equal 0, @repository.changesets.count
assert_equal [], @repository.heads_from_branches_hash
h = {}
h["branches"] = {}
h["branches"]["test1"] = {}
h["branches"]["test1"]["last_scmid"] = "1234abcd"
h["branches"]["test2"] = {}
h["branches"]["test2"]["last_scmid"] = "abcd1234"
@repository.merge_extra_info(h)
@repository.save
@project.reload
assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
end
def test_latest_changesets
assert_equal 0, @repository.changesets.count
@repository.fetch_changesets