Class: Grit::Tag

Inherits:
Ref
  • Object
show all
Extended by:
Lazy
Defined in:
lib/grit/tag.rb,
lib/grit_ext/tag.rb

Instance Attribute Summary

Attributes inherited from Ref

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lazy

extended, lazy_reader

Methods inherited from Ref

#commit, count_all, find_all, #initialize, #inspect

Constructor Details

This class inherits a constructor from Grit::Ref

Class Method Details

.create_tag_object(repo, hash, default_actor = nil) ⇒ Object

Writes a new tag object from a hash

+repo+ is a Grit repo
+hash+ is the hash of tag values

Returns a hash with sha and size of the created object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/grit/tag.rb', line 15

def self.create_tag_object(repo, hash, default_actor = nil)
  tagger = hash[:tagger]
  if !tagger
    tagger = default_actor ? default_actor : Actor.new("none", "none@none")
    tagger_date = Time.now
  else
    tagger_date = tagger[:date] ? Time.parse(tagger[:date]) : Time.now
    tagger = Actor.new(tagger[:name], tagger[:email])
  end
  data = []
  data << "object #{hash[:object]}"
  data << "type #{hash[:type]}"
  data << "tag #{hash[:tag]}"
  data << "tagger #{tagger.output(tagger_date)}"
  data << ""
  data << hash[:message]
  data = data.join("\n")
  sha = repo.git.put_raw_object(data, 'tag')
  { :sha => sha, :size => data.size }
end

.parse_tag_data(data) ⇒ Object

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 => ...}


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/grit/tag.rb', line 48

def self.parse_tag_data(data)
  return unless data =~ /^object/
  parsed = {}
  lines  = data.split("\n")
  parsed[:object] = lines.shift.sub(/^object /, '')
  parsed[:type] = lines.shift.sub(/^type /, '')
  parsed[:tag] = lines.shift.sub(/^tag /, '')
  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[:pgp] = []
  while lines.first
    parsed[:pgp] << lines.shift
  end
  parsed[:pgp] = parsed[:pgp] * "\n"
  parsed
end

Instance Method Details

#get_commitObject



90
91
92
93
94
# File 'lib/grit/tag.rb', line 90

def get_commit
  sha = @repo_ref.git.commit_from_sha(@commit_id)
  raise "Unknown object type." if sha == ''
  Commit.create(@repo_ref, :id => sha)
end

#lazy_sourceObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/grit/tag.rb', line 75

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 parsed = self.class.parse_tag_data(data)
    @message  = parsed[:message]
    @tagger   = parsed[:tagger]
    @tag_date = parsed[:tag_date]
  end
  self
end

#messageObject



6
7
8
# File 'lib/grit_ext/tag.rb', line 6

def message
  GritExt.encode! old_message
end

#old_messageObject



4
# File 'lib/grit_ext/tag.rb', line 4

alias_method :old_message, :message