Class: Referral::GitStore
- Inherits:
-
Object
- Object
- Referral::GitStore
- Defined in:
- lib/referral/git_store.rb
Constant Summary collapse
- GROSS_BLAME_CACHE =
{}
Class Method Summary collapse
- .author(file, line) ⇒ Object
-
.blame(file) ⇒ Object
This format will look like: a50eb722 (<[email protected]> 1561643971 -0400 2) class FirstThing or a50eb722 old/file/path.rb (<[email protected]> 1561643971 -0400 2) class FirstThing.
- .blame_line(file, line) ⇒ Object
- .sha(file, line) ⇒ Object
- .time(file, line) ⇒ Object
Class Method Details
.author(file, line) ⇒ Object
14 15 16 17 18 |
# File 'lib/referral/git_store.rb', line 14 def self.(file, line) return unless (output = blame_line(file, line)) return unless (match = output.match(/\(<([^>]*?)>/)) match[1] end |
.blame(file) ⇒ Object
This format will look like: a50eb722 (<[email protected]> 1561643971 -0400 2) class FirstThing or a50eb722 old/file/path.rb (<[email protected]> 1561643971 -0400 2) class FirstThing
35 36 37 38 39 40 |
# File 'lib/referral/git_store.rb', line 35 def self.blame(file) GROSS_BLAME_CACHE[file] ||= begin out, _, status = Open3.capture3("git blame -e -t \"#{file}\"") status.success? ? out : "" end end |
.blame_line(file, line) ⇒ Object
26 27 28 29 |
# File 'lib/referral/git_store.rb', line 26 def self.blame_line(file, line) return unless (output = blame(file)) output.split("\n")[line - 1] end |
.sha(file, line) ⇒ Object
8 9 10 11 12 |
# File 'lib/referral/git_store.rb', line 8 def self.sha(file, line) return unless (output = blame_line(file, line)) return unless (match = output.match(/^(\w+)/)) match[1] end |
.time(file, line) ⇒ Object
20 21 22 23 24 |
# File 'lib/referral/git_store.rb', line 20 def self.time(file, line) return unless (output = blame_line(file, line)) return unless (match = output.match(/\(<.*?>\s+(\d+)\s+/)) Time.at(Integer(match[1])) end |