git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5788 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b0f5d3cd88
commit
7ca5a4939e
@ -103,39 +103,26 @@ class Repository::Git < Repository
|
|||||||
#
|
#
|
||||||
# But, Git 1.7.3.4 does not support --reverse with -n or --skip.
|
# But, Git 1.7.3.4 does not support --reverse with -n or --skip.
|
||||||
#
|
#
|
||||||
# With SCM's that have a sequential commit numbering, redmine is able to be
|
|
||||||
# clever and only fetch changesets going forward from the most recent one
|
|
||||||
# it knows about.
|
|
||||||
# However, with git, you never know if people have merged
|
|
||||||
# commits into the middle of the repository history, so we should parse
|
|
||||||
# the entire log.
|
|
||||||
#
|
|
||||||
# Since it's way too slow for large repositories,
|
|
||||||
# we only parse 1 week before the last known commit.
|
|
||||||
#
|
|
||||||
# The repository can still be fully reloaded by calling #clear_changesets
|
# The repository can still be fully reloaded by calling #clear_changesets
|
||||||
# before fetching changesets (eg. for offline resync)
|
# before fetching changesets (eg. for offline resync)
|
||||||
def fetch_changesets
|
def fetch_changesets
|
||||||
c = changesets.find(:first, :order => 'committed_on DESC')
|
scm_brs = branches
|
||||||
since = (c ? c.committed_on - 7.days : nil)
|
return if scm_brs.nil? || scm_brs.empty?
|
||||||
|
h = extra_info || {}
|
||||||
revisions = scm.revisions('', nil, nil, {:all => true, :since => since, :reverse => true})
|
h["branches"] ||= {}
|
||||||
return if revisions.nil? || revisions.empty?
|
scm_brs.each do |br|
|
||||||
|
from_scmid = nil
|
||||||
recent_changesets = changesets.find(:all, :conditions => ['committed_on >= ?', since])
|
from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br]
|
||||||
|
h["branches"][br] ||= {}
|
||||||
# Clean out revisions that are no longer in git
|
scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
|
||||||
recent_changesets.each {|c| c.destroy unless revisions.detect {|r| r.scmid.to_s == c.scmid.to_s }}
|
db_rev = find_changeset_by_name(rev.revision)
|
||||||
|
|
||||||
# Subtract revisions that redmine already knows about
|
|
||||||
recent_revisions = recent_changesets.map{|c| c.scmid}
|
|
||||||
revisions.reject!{|r| recent_revisions.include?(r.scmid)}
|
|
||||||
|
|
||||||
# Save the remaining ones to the database
|
|
||||||
unless revisions.nil?
|
|
||||||
revisions.each do |rev|
|
|
||||||
transaction do
|
transaction do
|
||||||
save_revision(rev)
|
if db_rev.nil?
|
||||||
|
save_revision(rev)
|
||||||
|
end
|
||||||
|
h["branches"][br]["last_scmid"] = rev.scmid
|
||||||
|
merge_extra_info(h)
|
||||||
|
self.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -55,6 +55,8 @@ class RepositoryGitTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_fetch_changesets_from_scratch
|
def test_fetch_changesets_from_scratch
|
||||||
|
assert_nil @repository.extra_info
|
||||||
|
|
||||||
@repository.fetch_changesets
|
@repository.fetch_changesets
|
||||||
@repository.reload
|
@repository.reload
|
||||||
|
|
||||||
@ -74,30 +76,45 @@ class RepositoryGitTest < ActiveSupport::TestCase
|
|||||||
change = commit.changes.sort_by(&:path).first
|
change = commit.changes.sort_by(&:path).first
|
||||||
assert_equal "README", change.path
|
assert_equal "README", change.path
|
||||||
assert_equal "A", change.action
|
assert_equal "A", change.action
|
||||||
|
|
||||||
|
assert_equal 4, @repository.extra_info["branches"].size
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fetch_changesets_incremental
|
def test_fetch_changesets_incremental
|
||||||
@repository.fetch_changesets
|
@repository.fetch_changesets
|
||||||
|
@repository.reload
|
||||||
|
assert_equal 21, @repository.changesets.count
|
||||||
|
assert_equal 33, @repository.changes.count
|
||||||
|
extra_info_db = @repository.extra_info["branches"]
|
||||||
|
assert_equal 4, extra_info_db.size
|
||||||
|
assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
|
||||||
|
extra_info_db["latin-1-path-encoding"]["last_scmid"]
|
||||||
|
assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
|
||||||
|
extra_info_db["master"]["last_scmid"]
|
||||||
|
|
||||||
# Remove the latest changesets
|
del_revs = [
|
||||||
@repository.changesets.find(
|
"83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
|
||||||
:all,
|
"ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
|
||||||
:order => 'committed_on DESC',
|
"4f26664364207fa8b1af9f8722647ab2d4ac5d43",
|
||||||
:limit => 8).each(&:destroy)
|
"deff712f05a90d96edbd70facc47d944be5897e3",
|
||||||
|
"32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
|
||||||
|
"7e61ac704deecde634b51e59daa8110435dcb3da",
|
||||||
|
]
|
||||||
|
@repository.changesets.each do |rev|
|
||||||
|
rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
|
||||||
|
end
|
||||||
@repository.reload
|
@repository.reload
|
||||||
cs1 = @repository.changesets
|
cs1 = @repository.changesets
|
||||||
assert_equal 13, cs1.count
|
assert_equal 15, cs1.count
|
||||||
|
h = @repository.extra_info.dup
|
||||||
rev_a_commit = @repository.changesets.find(
|
h["branches"]["master"]["last_scmid"] =
|
||||||
:first,
|
"4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
|
||||||
:order => 'committed_on DESC')
|
@repository.merge_extra_info(h)
|
||||||
assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
|
@repository.save
|
||||||
# Mon Jul 5 22:34:26 2010 +0200
|
@repository.reload
|
||||||
rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
|
extra_info_db_1 = @repository.extra_info["branches"]
|
||||||
assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
|
assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
|
||||||
assert_equal rev_a_committed_on, rev_a_commit.committed_on
|
extra_info_db_1["master"]["last_scmid"]
|
||||||
latest_rev = @repository.latest_changeset
|
|
||||||
assert_equal rev_a_committed_on, latest_rev.committed_on
|
|
||||||
|
|
||||||
@repository.fetch_changesets
|
@repository.fetch_changesets
|
||||||
assert_equal 21, @repository.changesets.count
|
assert_equal 21, @repository.changesets.count
|
||||||
@ -318,7 +335,7 @@ class RepositoryGitTest < ActiveSupport::TestCase
|
|||||||
def test_next_nil
|
def test_next_nil
|
||||||
@repository.fetch_changesets
|
@repository.fetch_changesets
|
||||||
@repository.reload
|
@repository.reload
|
||||||
%w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
|
%w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1|
|
||||||
changeset = @repository.find_changeset_by_name(r1)
|
changeset = @repository.find_changeset_by_name(r1)
|
||||||
assert_nil changeset.next
|
assert_nil changeset.next
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user