Class: VCLog::Adapters::Git
- Defined in:
- lib/vclog/adapters/git.rb
Overview
GIT Adapter.
Constant Summary collapse
- GIT_COMMIT_MARKER =
'=====%n'
- GIT_FIELD_MARKER =
'-----%n'
- RUBY_COMMIT_MARKER =
"=====\n"
- RUBY_FIELD_MARKER =
"-----\n"
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#email ⇒ Object
Email address of developer.
-
#extract_changes ⇒ Object
Collect changes, i.e.
-
#extract_tags ⇒ Object
Collect tags.
- #git_show(ref) ⇒ Object private
- #repository ⇒ Object
-
#tag(ref, label, date, message) ⇒ Object
Create a tag for the given commit reference.
-
#user ⇒ Object
User name of developer.
Methods inherited from Abstract
#change_by_date, #change_points, #changes, #initialize, #initialize_framework, #tag?, #tags, #tempfile, #uuid, #version, #version_tag?
Constructor Details
This class inherits a constructor from VCLog::Adapters::Abstract
Instance Method Details
#email ⇒ Object
Email address of developer.
135 136 137 |
# File 'lib/vclog/adapters/git.rb', line 135 def email @email ||= `git config user.email`.strip end |
#extract_changes ⇒ Object
Collect changes, i.e. commits.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vclog/adapters/git.rb', line 18 def extract_changes list = [] command = 'git log --name-only --pretty=format:"' + GIT_COMMIT_MARKER + '%ci' + GIT_FIELD_MARKER + '%aN' + GIT_FIELD_MARKER + '%H' + GIT_FIELD_MARKER + '%s%n%n%b' + GIT_FIELD_MARKER + '"' changes = `#{command}`.split(RUBY_COMMIT_MARKER) changes.shift # throw the first (empty) entry away changes.each do |entry| date, who, id, msg, files = entry.split(RUBY_FIELD_MARKER) date = Time.parse(date) files = files.split("\n") list << Change.new(:id=>id, :date=>date, :who=>who, :msg=>msg, :files=>files) end return list end |
#extract_tags ⇒ Object
TODO:
This code is pretty poor, but it suffices for now. And we need not worry about it the future b/c eventually we will replace it by using the ‘amp` or `scm` gem.
Collect tags.
‘git show 1.0` produces:
tag 1.0
Tagger: 7rans <[email protected]>
Date: Sun Oct 25 09:27:58 2009 -0400
version 1.0
commit
...
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vclog/adapters/git.rb', line 71 def list = [] = `git tag -l` .split(/\s+/).each do |tag| next unless version_tag?(tag) # only version tags id, who, date, rev, msg = nil, nil, nil, nil, nil info = `git show #{tag}` info, *_ = info.split(/^(commit|diff|----)/) if /\Atag/ =~ info msg = '' info.lines.to_a[1..-1].each do |line| case line when /^Tagger:/ who = $'.strip when /^Date:/ date = $'.strip when /^\s*[a-f0-9]+/ id = $0.strip else msg << line end end msg = msg.strip #info = `git show #{tag}^ --pretty=format:"%ci|~|%H|~|"` #cdate, id, *_ = *info.split('|~|') info = git_show("#{tag}") change = Change.new(info) list << Tag.new(:id=>change.id, :name=>tag, :date=>date, :who=>who, :msg=>msg, :commit=>change) else #info = `git show #{tag} --pretty=format:"%cn|~|%ce|~|%ci|~|%H|~|%s|~|"` info = git_show(tag) change = Change.new(info) tag_info = { :name => tag, :who => info[:who], :date => info[:date], :msg => info[:message], :commit => change } list << Tag.new(tag_info) end #if $DEBUG # p who, date, rev, msg # puts #end #list << tag end return list end |
#git_show(ref) ⇒ Object (private)
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/vclog/adapters/git.rb', line 161 def git_show(ref) command = 'git show ' + ref.to_s + ' --name-only --pretty=format:"' + '%ci' + GIT_FIELD_MARKER + '%cn' + GIT_FIELD_MARKER + '%ce' + GIT_FIELD_MARKER + '%H' + GIT_FIELD_MARKER + '%s%n%n%b' + GIT_FIELD_MARKER + '"' entry = `#{command}` date, who, email, id, msg, files = entry.split(RUBY_FIELD_MARKER) who = who + ' ' + email date = Time.parse(date) files = files.split("\n") return { :date=>date, :who=>who, :id=>id, :message=>msg, :files=>files } end |
#repository ⇒ Object
140 141 142 |
# File 'lib/vclog/adapters/git.rb', line 140 def repository @repository ||= `git config remote.origin.url`.strip end |
#tag(ref, label, date, message) ⇒ Object
Create a tag for the given commit reference.
147 148 149 150 151 152 153 154 |
# File 'lib/vclog/adapters/git.rb', line 147 def tag(ref, label, date, ) file = tempfile("message", ) date = date.strftime('%Y-%m-%d 23:59') unless String===date cmd = %[GIT_AUTHOR_DATE='#{date}' GIT_COMMITTER_DATE='#{date}' git tag -a -F '#{file}' #{label} #{ref}] puts cmd if $DEBUG `#{cmd}` unless $DRYRUN end |
#user ⇒ Object
User name of developer.
130 131 132 |
# File 'lib/vclog/adapters/git.rb', line 130 def user @user ||= `git config user.name`.strip end |