]> source.dussan.org Git - redmine.git/commitdiff
Reduces memory usage when importing large git repositories (#1482).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 29 Jun 2008 09:41:42 +0000 (09:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 29 Jun 2008 09:41:42 +0000 (09:41 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1599 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/git.rb
lib/redmine/scm/adapters/git_adapter.rb

index 7213588ac35381283916c461cccd89c7bcfc0631..2f440fe29b805ee64e4d3423da8ab47dc9fd035a 100644 (file)
@@ -44,10 +44,8 @@ class Repository::Git < Repository
       scm_revision = scm_info.lastrev.scmid
 
       unless changesets.find_by_scmid(scm_revision)
-
-        revisions = scm.revisions('', db_revision, nil)
-        transaction do
-          revisions.reverse_each do |revision|
+        scm.revisions('', db_revision, nil, :reverse => true) do |revision|
+          transaction do
             changeset = Changeset.create(:repository => self,
                                          :revision => revision.identifier,
                                          :scmid => revision.scmid,
index d05b4fb38b3a6b106423d9186a718c029c5240e3..30d6240017abbb1af71f876cd85fee38b5b08136 100644 (file)
@@ -139,10 +139,10 @@ module Redmine
         def revisions(path, identifier_from, identifier_to, options={})
           revisions = Revisions.new
           cmd = "#{GIT_BIN} --git-dir #{target('')} log --raw "
+          cmd << " --reverse" if options[:reverse]
           cmd << " -n #{options[:limit].to_i} " if (!options.nil?) && options[:limit]
           cmd << " #{shell_quote(identifier_from + '..')} " if identifier_from
           cmd << " #{shell_quote identifier_to} " if identifier_to
-          #cmd << " HEAD " if !identifier_to
           shellout(cmd) do |io|
             files=[]
             changeset = {}
@@ -155,13 +155,18 @@ module Redmine
                 value = $1
                 if (parsing_descr == 1 || parsing_descr == 2)
                   parsing_descr = 0
-                  revisions << Revision.new({:identifier => changeset[:commit],
-                                             :scmid => changeset[:commit],
-                                             :author => changeset[:author],
-                                             :time => Time.parse(changeset[:date]),
-                                             :message => changeset[:description],
-                                             :paths => files
-                                            })
+                  revision = Revision.new({:identifier => changeset[:commit],
+                                           :scmid => changeset[:commit],
+                                           :author => changeset[:author],
+                                           :time => Time.parse(changeset[:date]),
+                                           :message => changeset[:description],
+                                           :paths => files
+                                          })
+                  if block_given?
+                    yield revision
+                  else
+                    revisions << revision
+                  end
                   changeset = {}
                   files = []
                   revno = revno + 1
@@ -190,14 +195,20 @@ module Redmine
               end
             end        
 
-            revisions << Revision.new({:identifier => changeset[:commit],
+            if changeset[:commit]
+              revision = Revision.new({:identifier => changeset[:commit],
                                        :scmid => changeset[:commit],
                                        :author => changeset[:author],
                                        :time => Time.parse(changeset[:date]),
                                        :message => changeset[:description],
                                        :paths => files
-                                      }) if changeset[:commit]
-
+                                      })
+              if block_given?
+                yield revision
+              else
+                revisions << revision
+              end
+            end
           end
 
           return nil if $? && $?.exitstatus != 0