Skip to content

Commit 09bae2d

Browse files
committed
Update from GitHub.
1 parent 288b2d7 commit 09bae2d

File tree

6 files changed

+62
-23
lines changed

6 files changed

+62
-23
lines changed

examples/ex_index.rb

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
i.add(fname, 'hello ' + fname)
1010
count += 1
1111
end
12+
count = 5
13+
while(count < 10) do
14+
puts "HELLO"
15+
fname = Time.now.to_i.to_s + count.to_s
16+
i.add('test/' + fname, 'hello ' + fname)
17+
count += 1
18+
end
1219
puts i.commit('my commit')
1320
puts i.inspect
1421
end

lib/grit/errors.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class NoSuchPathError < StandardError
77

88
class InvalidObjectType < StandardError
99
end
10-
end
10+
end

lib/grit/git-ruby/git_object.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ def initialize(object, type, tag, tagger, message, repository=nil)
337337
end
338338

339339
def raw_content
340-
"object %s\ntype %s\ntag %s\ntagger %s\n\n" % \
341-
[@object, @type, @tag, @tagger] + @message
340+
("object %s\ntype %s\ntag %s\ntagger %s\n\n" % \
341+
[@object, @type, @tag, @tagger]) + @message.to_s
342342
end
343343

344344
def type

lib/grit/tag.rb

+38-12
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,51 @@ def self.find_all(repo, options = {})
1616
end
1717
end
1818

19+
# Parses the results from `cat-file -p`
20+
#
21+
# data - String tag object data. Example:
22+
# object 7bcc0ee821cdd133d8a53e8e7173a334fef448aa
23+
# type commit
24+
# tag v0.7.0
25+
# tagger USER <EMAIL> DATE
26+
#
27+
# v0.7.0
28+
#
29+
# Returns parsed Hash. Example:
30+
# {:message => "...", :tagger => "bob", :tag_date => ...}
31+
def self.parse_tag_data(data)
32+
return unless data =~ /^object/
33+
parsed = {}
34+
lines = data.split("\n")
35+
lines.shift # type commit
36+
lines.shift # tag name
37+
lines.shift
38+
author_line = lines.shift
39+
parsed[:tagger], parsed[:tag_date] = Commit.actor(author_line)
40+
if !parsed[:tagger] || !parsed[:tagger].name
41+
parsed[:tag_date] ||= Time.utc(1970)
42+
parsed[:tagger] = Actor.from_string(author_line.sub(/^tagger /, ''))
43+
end
44+
lines.shift # blank line
45+
parsed[:message] = []
46+
while lines.first && lines.first !~ /-----BEGIN PGP SIGNATURE-----/
47+
parsed[:message] << lines.shift
48+
end
49+
parsed[:message] = parsed[:message] * "\n"
50+
parsed
51+
end
52+
1953
def lazy_source
2054
data = commit.repo.git.cat_ref({:p => true}, name)
2155
@message = commit.short_message
2256
@tagger = commit.author
2357
@tag_date = commit.authored_date
2458
return self if data.empty?
2559

26-
if data =~ /^object/
27-
@message = ''
28-
lines = data.split("\n")
29-
lines.shift # type commit
30-
lines.shift # tag name
31-
lines.shift
32-
@tagger, @tag_date = Commit.actor(lines.shift)
33-
lines.shift # blank line
34-
while lines.first && lines.first !~ /-----BEGIN PGP SIGNATURE-----/
35-
@message << lines.shift << "\n"
36-
end
37-
@message.strip!
60+
if parsed = self.class.parse_tag_data(data)
61+
@message = parsed[:message]
62+
@tagger = parsed[:tagger]
63+
@tag_date = parsed[:tag_date]
3864
end
3965
self
4066
end

test/helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
gem "mocha", ">=0"
66
require 'mocha'
77

8-
GRIT_REPO = ENV["GRIT_REPO"] || File.join(File.dirname(__FILE__), '..')
8+
GRIT_REPO = ENV["GRIT_REPO"] || "/Users/schacon/projects/grit"
99

1010
include Grit
1111

test/test_tag.rb

+13-7
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ def test_reads_light_tag_contents
8686
assert_equal Time.utc(2008, 4, 18, 23, 27, 8), tag.tag_date.utc
8787
end
8888

89-
# attempts_to_read_bad_tag_message
90-
91-
def test_attempts_to_read_bad_tag_message
92-
tag = Grit::Tag.new('abc', @r.tags[0].commit)
93-
assert_equal tag.commit.message, tag.message
94-
end
95-
9689
# reads_annotated_tag_contents
9790

9891
def test_reads_annotated_tag_contents
@@ -104,6 +97,19 @@ def test_reads_annotated_tag_contents
10497
assert_equal Time.utc(2009, 2, 13, 22, 22, 16), tag.tag_date.utc
10598
end
10699

100+
def test_parses_tag_object_without_message
101+
parsed = Grit::Tag.parse_tag_data(<<-TAG)
102+
object 2695effb5807a22ff3d138d593fd856244e155e7
103+
type commit
104+
tag rel-0-1-0
105+
tagger bob <bob>
106+
Thu Jan 1 00:00:00 1970 +0000
107+
TAG
108+
assert_equal 'bob', parsed[:tagger].name
109+
assert_equal Time.utc(1970), parsed[:tag_date]
110+
assert_equal '', parsed[:message]
111+
end
112+
107113
# reads_annotated_and_packed_tag_contents
108114

109115
def test_reads_annotated_and_packed_tag_contents

0 commit comments

Comments
 (0)