Class Grit::Tag
In: lib/grit/tag.rb
Parent: Ref

Methods

Public Class methods

[Source]

    # File lib/grit/tag.rb, line 52
52:     def self.commit_from_sha(repo, id)
53:       git_ruby_repo = GitRuby::Repository.new(repo.path)
54:       object = git_ruby_repo.get_object_by_sha1(id)
55: 
56:       if object.type == :commit
57:         Commit.create(repo, :id => id)
58:       elsif object.type == :tag
59:         Commit.create(repo, :id => object.object)
60:       else
61:         raise "Unknown object type."
62:       end
63:     end

[Source]

    # File lib/grit/tag.rb, line 4
 4:     def self.find_all(repo, options = {})
 5:       refs = []
 6:       already = {}
 7: 
 8:       Dir.chdir(repo.path) do
 9:         files = Dir.glob(prefix + '/**/*')
10: 
11:         files.each do |ref|
12:           next if !File.file?(ref)
13: 
14:           id = File.read(ref).chomp
15:           name = ref.sub("#{prefix}/", '')
16:           commit = commit_from_sha(repo, id)
17: 
18:           if !already[name]
19:             refs << self.new(name, commit)
20:             already[name] = true
21:           end
22:         end
23: 
24:         if File.file?('packed-refs')
25:           lines = File.readlines('packed-refs')
26:           lines.each_with_index do |line, i|
27:             if m = /^(\w{40}) (.*?)$/.match(line)
28:               next if !Regexp.new('^' + prefix).match(m[2])
29:               name = m[2].sub("#{prefix}/", '')
30: 
31:               # Annotated tags in packed-refs include a reference
32:               # to the commit object on the following line.
33:               next_line = lines[i+1]
34:               if next_line && next_line[0] == ?^
35:                 commit = Commit.create(repo, :id => next_line[1..-1].chomp)
36:               else
37:                 commit = commit_from_sha(repo, m[1])
38:               end
39: 
40:               if !already[name]
41:                 refs << self.new(name, commit)
42:                 already[name] = true
43:               end
44:             end
45:           end
46:         end
47:       end
48: 
49:       refs
50:     end

[Validate]