diff --git a/examples/ex_index.rb b/examples/ex_index.rb index 90e34f28..386b181a 100644 --- a/examples/ex_index.rb +++ b/examples/ex_index.rb @@ -9,6 +9,13 @@ i.add(fname, 'hello ' + fname) count += 1 end + count = 5 + while(count < 10) do + puts "HELLO" + fname = Time.now.to_i.to_s + count.to_s + i.add('test/' + fname, 'hello ' + fname) + count += 1 + end puts i.commit('my commit') puts i.inspect end \ No newline at end of file diff --git a/lib/grit/errors.rb b/lib/grit/errors.rb index 96f14d68..36bb8f60 100644 --- a/lib/grit/errors.rb +++ b/lib/grit/errors.rb @@ -7,4 +7,4 @@ class NoSuchPathError < StandardError class InvalidObjectType < StandardError end -end \ No newline at end of file +end diff --git a/lib/grit/git-ruby/git_object.rb b/lib/grit/git-ruby/git_object.rb index 833b0356..49fa3dd5 100644 --- a/lib/grit/git-ruby/git_object.rb +++ b/lib/grit/git-ruby/git_object.rb @@ -337,8 +337,8 @@ def initialize(object, type, tag, tagger, message, repository=nil) end def raw_content - "object %s\ntype %s\ntag %s\ntagger %s\n\n" % \ - [@object, @type, @tag, @tagger] + @message + ("object %s\ntype %s\ntag %s\ntagger %s\n\n" % \ + [@object, @type, @tag, @tagger]) + @message.to_s end def type diff --git a/lib/grit/tag.rb b/lib/grit/tag.rb index 45999f83..6817c68a 100644 --- a/lib/grit/tag.rb +++ b/lib/grit/tag.rb @@ -16,6 +16,40 @@ def self.find_all(repo, options = {}) end end + # Parses the results from `cat-file -p` + # + # data - String tag object data. Example: + # object 7bcc0ee821cdd133d8a53e8e7173a334fef448aa + # type commit + # tag v0.7.0 + # tagger USER DATE + # + # v0.7.0 + # + # Returns parsed Hash. Example: + # {:message => "...", :tagger => "bob", :tag_date => ...} + def self.parse_tag_data(data) + return unless data =~ /^object/ + parsed = {} + lines = data.split("\n") + lines.shift # type commit + lines.shift # tag name + lines.shift + author_line = lines.shift + parsed[:tagger], parsed[:tag_date] = Commit.actor(author_line) + if !parsed[:tagger] || !parsed[:tagger].name + parsed[:tag_date] ||= Time.utc(1970) + parsed[:tagger] = Actor.from_string(author_line.sub(/^tagger /, '')) + end + lines.shift # blank line + parsed[:message] = [] + while lines.first && lines.first !~ /-----BEGIN PGP SIGNATURE-----/ + parsed[:message] << lines.shift + end + parsed[:message] = parsed[:message] * "\n" + parsed + end + def lazy_source data = commit.repo.git.cat_ref({:p => true}, name) @message = commit.short_message @@ -23,18 +57,10 @@ def lazy_source @tag_date = commit.authored_date return self if data.empty? - if data =~ /^object/ - @message = '' - lines = data.split("\n") - lines.shift # type commit - lines.shift # tag name - lines.shift - @tagger, @tag_date = Commit.actor(lines.shift) - lines.shift # blank line - while lines.first && lines.first !~ /-----BEGIN PGP SIGNATURE-----/ - @message << lines.shift << "\n" - end - @message.strip! + if parsed = self.class.parse_tag_data(data) + @message = parsed[:message] + @tagger = parsed[:tagger] + @tag_date = parsed[:tag_date] end self end diff --git a/test/helper.rb b/test/helper.rb index 9f47f958..6811983d 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -5,7 +5,7 @@ gem "mocha", ">=0" require 'mocha' -GRIT_REPO = ENV["GRIT_REPO"] || File.join(File.dirname(__FILE__), '..') +GRIT_REPO = ENV["GRIT_REPO"] || "/Users/schacon/projects/grit" include Grit diff --git a/test/test_tag.rb b/test/test_tag.rb index 107700e4..f81ed667 100644 --- a/test/test_tag.rb +++ b/test/test_tag.rb @@ -86,13 +86,6 @@ def test_reads_light_tag_contents assert_equal Time.utc(2008, 4, 18, 23, 27, 8), tag.tag_date.utc end - # attempts_to_read_bad_tag_message - - def test_attempts_to_read_bad_tag_message - tag = Grit::Tag.new('abc', @r.tags[0].commit) - assert_equal tag.commit.message, tag.message - end - # reads_annotated_tag_contents def test_reads_annotated_tag_contents @@ -104,6 +97,19 @@ def test_reads_annotated_tag_contents assert_equal Time.utc(2009, 2, 13, 22, 22, 16), tag.tag_date.utc end + def test_parses_tag_object_without_message + parsed = Grit::Tag.parse_tag_data(<<-TAG) +object 2695effb5807a22ff3d138d593fd856244e155e7 +type commit +tag rel-0-1-0 +tagger bob +Thu Jan 1 00:00:00 1970 +0000 +TAG + assert_equal 'bob', parsed[:tagger].name + assert_equal Time.utc(1970), parsed[:tag_date] + assert_equal '', parsed[:message] + end + # reads_annotated_and_packed_tag_contents def test_reads_annotated_and_packed_tag_contents