]> source.dussan.org Git - redmine.git/commitdiff
Merged r3513 and r3531 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 11 Apr 2010 14:06:10 +0000 (14:06 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 11 Apr 2010 14:06:10 +0000 (14:06 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3638 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/git_adapter.rb
test/unit/git_adapter_test.rb

index 75a33a05499b2b5c20a42f2cfa431ed0501b71f5..d15bce1afd6d62cee38083478f320e78cd434496 100644 (file)
@@ -227,16 +227,26 @@ module Redmine
         
         def annotate(path, identifier=nil)
           identifier = 'HEAD' if identifier.blank?
-          cmd = "#{GIT_BIN} --git-dir #{target('')} blame -l #{shell_quote identifier} -- #{shell_quote path}"
+          cmd = "#{GIT_BIN} --git-dir #{target('')} blame -p #{shell_quote identifier} -- #{shell_quote path}"
           blame = Annotate.new
           content = nil
           shellout(cmd) { |io| io.binmode; content = io.read }
           return nil if $? && $?.exitstatus != 0
           # git annotates binary files
           return nil if content.is_binary_data?
+          identifier = ''
+          # git shows commit author on the first occurrence only
+          authors_by_commit = {}
           content.split("\n").each do |line|
-            next unless line =~ /([0-9a-f]{39,40})\s\((\w*)[^\)]*\)(.*)/
-            blame.add_line($3.rstrip, Revision.new(:identifier => $1, :author => $2.strip))
+            if line =~ /^([0-9a-f]{39,40})\s.*/
+              identifier = $1
+            elsif line =~ /^author (.+)/
+              authors_by_commit[identifier] = $1.strip
+            elsif line =~ /^\t(.*)/
+              blame.add_line($1, Revision.new(:identifier => identifier, :author => authors_by_commit[identifier]))
+              identifier = ''
+              author = ''
+            end
           end
           blame
         end
index 9ab25c1542efab437fc66409a8a69ff9107a22ab..8bc000c4c257d7224f762cd31be2c7af12c5d32f 100644 (file)
@@ -15,6 +15,21 @@ class GitAdapterTest < ActiveSupport::TestCase
     def test_getting_all_revisions
       assert_equal 12, @adapter.revisions('',nil,nil,:all => true).length
     end
+    
+    def test_annotate
+      annotate = @adapter.annotate('sources/watchers_controller.rb')
+      assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
+      assert_equal 41, annotate.lines.size
+      assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip
+      assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", annotate.revisions[4].identifier
+      assert_equal "jsmith", annotate.revisions[4].author
+    end
+    
+    def test_annotate_moved_file
+      annotate = @adapter.annotate('renamed_test.txt')
+      assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
+      assert_equal 2, annotate.lines.size
+    end
   else
     puts "Git test repository NOT FOUND. Skipping unit tests !!!"
     def test_fake; assert true end