Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update from GitHub.

  • Loading branch information...
commit 09bae2d065e8b813797b8c182310f7f2e549514b 1 parent 288b2d7
Tom Preston-Werner mojombo authored
7 examples/ex_index.rb
@@ -9,6 +9,13 @@
9 9 i.add(fname, 'hello ' + fname)
10 10 count += 1
11 11 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
12 19 puts i.commit('my commit')
13 20 puts i.inspect
14 21 end
2  lib/grit/errors.rb
@@ -7,4 +7,4 @@ class NoSuchPathError < StandardError
7 7
8 8 class InvalidObjectType < StandardError
9 9 end
10   -end
  10 +end
4 lib/grit/git-ruby/git_object.rb
@@ -337,8 +337,8 @@ def initialize(object, type, tag, tagger, message, repository=nil)
337 337 end
338 338
339 339 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
342 342 end
343 343
344 344 def type
50 lib/grit/tag.rb
@@ -16,6 +16,40 @@ def self.find_all(repo, options = {})
16 16 end
17 17 end
18 18
  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 +
19 53 def lazy_source
20 54 data = commit.repo.git.cat_ref({:p => true}, name)
21 55 @message = commit.short_message
@@ -23,18 +57,10 @@ def lazy_source
23 57 @tag_date = commit.authored_date
24 58 return self if data.empty?
25 59
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]
38 64 end
39 65 self
40 66 end
2  test/helper.rb
@@ -5,7 +5,7 @@
5 5 gem "mocha", ">=0"
6 6 require 'mocha'
7 7
8   -GRIT_REPO = ENV["GRIT_REPO"] || File.join(File.dirname(__FILE__), '..')
  8 +GRIT_REPO = ENV["GRIT_REPO"] || "/Users/schacon/projects/grit"
9 9
10 10 include Grit
11 11
20 test/test_tag.rb
@@ -86,13 +86,6 @@ def test_reads_light_tag_contents
86 86 assert_equal Time.utc(2008, 4, 18, 23, 27, 8), tag.tag_date.utc
87 87 end
88 88
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   -
96 89 # reads_annotated_tag_contents
97 90
98 91 def test_reads_annotated_tag_contents
@@ -104,6 +97,19 @@ def test_reads_annotated_tag_contents
104 97 assert_equal Time.utc(2009, 2, 13, 22, 22, 16), tag.tag_date.utc
105 98 end
106 99
  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 +
107 113 # reads_annotated_and_packed_tag_contents
108 114
109 115 def test_reads_annotated_and_packed_tag_contents

0 comments on commit 09bae2d

Please sign in to comment.
Something went wrong with that request. Please try again.