Mercurial adapter:

* fetch changesets by batches of 100 (rather than in a single transaction)
* fix: fetch_changesets tries to re-insert the last revision that exists in the db (#860)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1255 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-03-15 10:30:56 +00:00
parent a59e6bfb02
commit 01fdaf5977
2 changed files with 31 additions and 21 deletions

View File

@ -51,29 +51,35 @@ class Repository::Mercurial < Repository
scm_info = scm.info scm_info = scm.info
if scm_info if scm_info
# latest revision found in database # latest revision found in database
db_revision = latest_changeset ? latest_changeset.revision : nil db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
# latest revision in the repository # latest revision in the repository
scm_revision = scm_info.lastrev.identifier.to_i scm_revision = scm_info.lastrev.identifier.to_i
if db_revision < scm_revision
unless changesets.find_by_revision(scm_revision) logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
revisions = scm.revisions('', db_revision, nil) identifier_from = db_revision + 1
transaction do while (identifier_from <= scm_revision)
revisions.reverse_each do |revision| # loads changesets by batches of 100
changeset = Changeset.create(:repository => self, identifier_to = [identifier_from + 99, scm_revision].min
:revision => revision.identifier, revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
:scmid => revision.scmid, transaction do
:committer => revision.author, revisions.each do |revision|
:committed_on => revision.time, changeset = Changeset.create(:repository => self,
:comments => revision.message) :revision => revision.identifier,
:scmid => revision.scmid,
revision.paths.each do |change| :committer => revision.author,
Change.create(:changeset => changeset, :committed_on => revision.time,
:action => change[:action], :comments => revision.message)
:path => change[:path],
:from_path => change[:from_path], revision.paths.each do |change|
:from_revision => change[:from_revision]) Change.create(:changeset => changeset,
:action => change[:action],
:path => change[:path],
:from_path => change[:from_path],
:from_revision => change[:from_revision])
end
end end
end end unless revisions.nil?
identifier_from = identifier_to + 1
end end
end end
end end

View File

@ -71,7 +71,11 @@ module Redmine
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
revisions = Revisions.new revisions = Revisions.new
cmd = "#{HG_BIN} -v -R #{target('')} log" cmd = "#{HG_BIN} -v -R #{target('')} log"
cmd << " -r #{identifier_from.to_i}:" if identifier_from if identifier_from && identifier_to
cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
elsif identifier_from
cmd << " -r #{identifier_from.to_i}:"
end
cmd << " --limit #{options[:limit].to_i}" if options[:limit] cmd << " --limit #{options[:limit].to_i}" if options[:limit]
shellout(cmd) do |io| shellout(cmd) do |io|
changeset = {} changeset = {}