diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2012-03-07 05:57:44 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2012-03-07 05:57:44 +0000 |
commit | f0987e4b8f014bdb226a1eb1c67e78dcae1c8c49 (patch) | |
tree | 2231d23d12648107c24d99a21e0095214a4d867f /app/models/repository | |
parent | 374c2aa70500629a66a305afe08306c3bbb82c5c (diff) | |
download | redmine-f0987e4b8f014bdb226a1eb1c67e78dcae1c8c49.tar.gz redmine-f0987e4b8f014bdb226a1eb1c67e78dcae1c8c49.zip |
scm: git: backout r8839 (#8857)
call "git log" only once instead of per branch in fetching revisions.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9142 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/repository')
-rw-r--r-- | app/models/repository/git.rb | 67 |
1 files changed, 28 insertions, 39 deletions
diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index d777fe7c5..98c5788bf 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -107,7 +107,8 @@ class Repository::Git < Repository # However, Git does not have a sequential commit numbering. # # In order to fetch only new adding revisions, - # Redmine needs to save "heads". + # Redmine needs to parse revisions per branch. + # Branch "last_scmid" is for this requirement. # # In Git and Mercurial, revisions are not in date order. # Redmine Mercurial fixed issues. @@ -130,17 +131,9 @@ class Repository::Git < Repository def fetch_changesets scm_brs = branches return if scm_brs.nil? || scm_brs.empty? - h1 = extra_info || {} h = h1.dup - repo_heads = scm_brs.map{ |br| br.scmid } - h["heads"] ||= [] - prev_db_heads = h["heads"].dup - if prev_db_heads.empty? - prev_db_heads += heads_from_branches_hash - end - return if prev_db_heads.sort == repo_heads.sort - + h["branches"] ||= {} h["db_consistent"] ||= {} if changesets.count == 0 h["db_consistent"]["ordering"] = 1 @@ -151,39 +144,35 @@ class Repository::Git < Repository merge_extra_info(h) self.save end - - save_revisions(prev_db_heads, repo_heads) - end - - def save_revisions(prev_db_heads, repo_heads) - h = {} - opts = {} - opts[:reverse] = true - opts[:excludes] = prev_db_heads - opts[:includes] = repo_heads - begin - scm.revisions('', nil, nil, opts) do |rev| - db_rev = find_changeset_by_name(rev.scmid) - transaction do - if db_rev.nil? - db_saved_rev = save_revision(rev) - parents = {} - parents[db_saved_rev] = rev.parents unless rev.parents.nil? - parents.each do |ch, chparents| - ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact + save_revisions(h, scm_brs) + end + + def save_revisions(h, scm_brs) + scm_brs.each do |br1| + br = br1.to_s + from_scmid = nil + from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] + h["branches"][br] ||= {} + begin + scm.revisions('', from_scmid, br, {:reverse => true}) do |rev| + db_rev = find_changeset_by_name(rev.revision) + transaction do + if db_rev.nil? + db_saved_rev = save_revision(rev) + parents = {} + parents[db_saved_rev] = rev.parents unless rev.parents.nil? + parents.each do |ch, chparents| + ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact + end end + h["branches"][br]["last_scmid"] = rev.scmid + merge_extra_info(h) + self.save end - h["heads"] = prev_db_heads.dup - h["heads"] << rev.scmid - merge_extra_info(h) - self.save end + rescue Redmine::Scm::Adapters::CommandFailed => e + logger.error("save revisions error: #{e.message}") end - h["heads"] = repo_heads.dup - merge_extra_info(h) - self.save - rescue Redmine::Scm::Adapters::CommandFailed => e - logger.error("save revisions error: #{e.message}") end end private :save_revisions |