OSDN Git Service

Mercurial adapter:
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 15 Mar 2008 10:30:56 +0000 (10:30 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 15 Mar 2008 10:30:56 +0000 (10:30 +0000)
* 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

app/models/repository/mercurial.rb
lib/redmine/scm/adapters/mercurial_adapter.rb

index 5d9ea9c..27a8eae 100644 (file)
@@ -51,29 +51,35 @@ class Repository::Mercurial < Repository
     scm_info = scm.info
     if scm_info
       # 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
       scm_revision = scm_info.lastrev.identifier.to_i
-      
-      unless changesets.find_by_revision(scm_revision)
-        revisions = scm.revisions('', db_revision, nil)
-        transaction do
-          revisions.reverse_each do |revision|
-            changeset = Changeset.create(:repository => self,
-                                         :revision => revision.identifier,
-                                         :scmid => revision.scmid,
-                                         :committer => revision.author, 
-                                         :committed_on => revision.time,
-                                         :comments => revision.message)
-            
-            revision.paths.each do |change|
-              Change.create(:changeset => changeset,
-                            :action => change[:action],
-                            :path => change[:path],
-                            :from_path => change[:from_path],
-                            :from_revision => change[:from_revision])
+      if db_revision < scm_revision
+        logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
+        identifier_from = db_revision + 1
+        while (identifier_from <= scm_revision)
+          # loads changesets by batches of 100
+          identifier_to = [identifier_from + 99, scm_revision].min
+          revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
+          transaction do
+            revisions.each do |revision|
+              changeset = Changeset.create(:repository => self,
+                                           :revision => revision.identifier,
+                                           :scmid => revision.scmid,
+                                           :committer => revision.author, 
+                                           :committed_on => revision.time,
+                                           :comments => revision.message)
+              
+              revision.paths.each do |change|
+                Change.create(:changeset => changeset,
+                              :action => change[:action],
+                              :path => change[:path],
+                              :from_path => change[:from_path],
+                              :from_revision => change[:from_revision])
+              end
             end
-          end
+          end unless revisions.nil?
+          identifier_from = identifier_to + 1
         end
       end
     end
index 26bf011..f4dffd9 100644 (file)
@@ -71,7 +71,11 @@ module Redmine
         def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
           revisions = Revisions.new
           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]
           shellout(cmd) do |io|
             changeset = {}