Class Grit::Ref
In: lib/grit/ref.rb
Parent: Object

Methods

find_all   inspect   new   prefix  

Attributes

commit  [R] 
name  [R] 

Public Class methods

Find all Refs

  +repo+ is the Repo
  +options+ is a Hash of options

Returns Grit::Ref[] (baked)

[Source]

    # File lib/grit/ref.rb, line 12
12:       def find_all(repo, options = {})
13:         refs = []
14:         already = {}
15:         Dir.chdir(repo.path) do
16:           files = Dir.glob(prefix + '/**/*')
17:           files.each do |ref|
18:             next if !File.file?(ref)
19:             id = File.read(ref).chomp
20:             name = ref.sub("#{prefix}/", '')
21:             commit = Commit.create(repo, :id => id)
22:             if !already[name]
23:               refs << self.new(name, commit)
24:               already[name] = true
25:             end
26:           end
27: 
28:           if File.file?('packed-refs')
29:             File.readlines('packed-refs').each do |line|
30:               if m = /^(\w{40}) (.*?)$/.match(line)
31:                 next if !Regexp.new('^' + prefix).match(m[2])
32:                 name = m[2].sub("#{prefix}/", '')
33:                 commit = Commit.create(repo, :id => m[1])
34:                 if !already[name]
35:                   refs << self.new(name, commit)
36:                   already[name] = true
37:                 end
38:               end
39:             end
40:           end
41:         end
42: 
43:         refs
44:       end

Instantiate a new Head

  +name+ is the name of the head
  +commit+ is the Commit that the head points to

Returns Grit::Head (baked)

[Source]

    # File lib/grit/ref.rb, line 62
62:     def initialize(name, commit)
63:       @name = name
64:       @commit = commit
65:     end

Protected Class methods

[Source]

    # File lib/grit/ref.rb, line 48
48:         def prefix
49:           "refs/#{name.to_s.gsub(/^.*::/, '').downcase}s"
50:         end

Public Instance methods

Pretty object inspection

[Source]

    # File lib/grit/ref.rb, line 68
68:     def inspect
69:       %Q{#<#{self.class.name} "#{@name}">}
70:     end

[Validate]