Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

Commit

Permalink
Update from GitHub.
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Aug 3, 2010
1 parent 288b2d7 commit 09bae2d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
7 changes: 7 additions & 0 deletions examples/ex_index.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/grit/errors.rb
Expand Up @@ -7,4 +7,4 @@ class NoSuchPathError < StandardError

class InvalidObjectType < StandardError
end
end
end
4 changes: 2 additions & 2 deletions lib/grit/git-ruby/git_object.rb
Expand Up @@ -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
Expand Down
50 changes: 38 additions & 12 deletions lib/grit/tag.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Expand Up @@ -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

Expand Down
20 changes: 13 additions & 7 deletions test/test_tag.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 09bae2d

Please sign in to comment.