scm: mercurial: refactor Repository::Mercurial#fetch_changesets (#4455).
Contributed by Yuya Nishihara. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4849 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0f1c932f35
commit
de7f88c572
|
@ -24,6 +24,8 @@ class Repository::Mercurial < Repository
|
||||||
attr_protected :root_url
|
attr_protected :root_url
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
|
|
||||||
|
FETCH_AT_ONCE = 100 # number of changesets to fetch at once
|
||||||
|
|
||||||
def self.scm_adapter_class
|
def self.scm_adapter_class
|
||||||
Redmine::Scm::Adapters::MercurialAdapter
|
Redmine::Scm::Adapters::MercurialAdapter
|
||||||
end
|
end
|
||||||
|
@ -94,38 +96,24 @@ class Repository::Mercurial < Repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_changesets
|
def fetch_changesets
|
||||||
scm_info = scm.info
|
scm_rev = scm.info.lastrev.revision.to_i
|
||||||
if scm_info
|
db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
|
||||||
# latest revision found in database
|
return unless db_rev < scm_rev # already up-to-date
|
||||||
db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
|
|
||||||
# latest revision in the repository
|
logger.debug "Fetching changesets for repository #{url}" if logger
|
||||||
latest_revision = scm_info.lastrev
|
(db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
|
||||||
return if latest_revision.nil?
|
transaction do
|
||||||
scm_revision = latest_revision.identifier.to_i
|
scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
|
||||||
if db_revision < scm_revision
|
cs = Changeset.create(:repository => self,
|
||||||
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
|
:revision => re.revision,
|
||||||
identifier_from = db_revision + 1
|
:scmid => re.scmid,
|
||||||
while (identifier_from <= scm_revision)
|
:committer => re.author,
|
||||||
# loads changesets by batches of 100
|
:committed_on => re.time,
|
||||||
identifier_to = [identifier_from + 99, scm_revision].min
|
:comments => re.message)
|
||||||
revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
|
re.paths.each { |e| cs.create_change(e) }
|
||||||
transaction do
|
|
||||||
revisions.each do |revision|
|
|
||||||
changeset = Changeset.create(:repository => self,
|
|
||||||
:revision => revision.revision,
|
|
||||||
:scmid => revision.scmid,
|
|
||||||
:committer => revision.author,
|
|
||||||
:committed_on => revision.time,
|
|
||||||
:comments => revision.message)
|
|
||||||
|
|
||||||
revision.paths.each do |change|
|
|
||||||
changeset.create_change(change)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end unless revisions.nil?
|
|
||||||
identifier_from = identifier_to + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue