diff app/models/repository/git.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 0c939c159af4
children 5e80956cc792 433d4f72a19b
line wrap: on
line diff
--- a/app/models/repository/git.rb	Fri Feb 24 18:36:29 2012 +0000
+++ b/app/models/repository/git.rb	Fri Feb 24 19:09:32 2012 +0000
@@ -53,6 +53,10 @@
     true
   end
 
+  def supports_revision_graph?
+    true
+  end
+
   def repo_log_encoding
     'UTF-8'
   end
@@ -77,6 +81,9 @@
 
   def default_branch
     scm.default_branch
+  rescue Exception => e
+    logger.error "git: error during get default branch: #{e.message}"
+    nil
   end
 
   def find_changeset_by_name(name)
@@ -92,6 +99,17 @@
                 options = {:report_last_commit => extra_report_last_commit})
   end
 
+  # With SCMs that have a sequential commit numbering,
+  # such as Subversion and Mercurial,
+  # Redmine is able to be clever and only fetch changesets
+  # going forward from the most recent one it knows about.
+  # 
+  # However, Git does not have a sequential commit numbering.
+  #
+  # In order to fetch only new adding revisions,
+  # 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.
   #    * Redmine Takes Too Long On Large Mercurial Repository
@@ -126,7 +144,8 @@
       merge_extra_info(h)
       self.save
     end
-    scm_brs.each do |br|
+    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] ||= {}
@@ -134,7 +153,12 @@
         db_rev = find_changeset_by_name(rev.revision)
         transaction do
           if db_rev.nil?
-            save_revision(rev)
+            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)
@@ -161,6 +185,7 @@
                   :path      => file[:path])
       end
     end
+    changeset
   end
   private :save_revision