Permalink
Browse files

Update from GitHub.

  • Loading branch information...
1 parent 288b2d7 commit 09bae2d065e8b813797b8c182310f7f2e549514b @mojombo mojombo committed Aug 3, 2010
Showing with 62 additions and 23 deletions.
  1. +7 −0 examples/ex_index.rb
  2. +1 −1 lib/grit/errors.rb
  3. +2 −2 lib/grit/git-ruby/git_object.rb
  4. +38 −12 lib/grit/tag.rb
  5. +1 −1 test/helper.rb
  6. +13 −7 test/test_tag.rb
View
7 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
View
2 lib/grit/errors.rb
@@ -7,4 +7,4 @@ class NoSuchPathError < StandardError
class InvalidObjectType < StandardError
end
-end
+end
View
4 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
View
50 lib/grit/tag.rb
@@ -16,25 +16,51 @@ 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 <EMAIL> 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
@tagger = commit.author
@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
View
2 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
View
20 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 <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

0 comments on commit 09bae2d

Please sign in to comment.