Sha256: 756a85514843d8f976ff85450233e8780967ece5191a0cffafa37fed0ad4a6a0
Contents?: true
Size: 1.6 KB
Versions: 6
Compression:
Stored size: 1.6 KB
Contents
require "open3" module Obst class GitLog def initialize(**opts) path = opts[:C] || '.' @cmd = ['git', '-C', path, 'log', '--name-status', '--pretty=format:%ad', "--date=format:'%Y-%m-%dT%H:%M:%S'"] @cmd << '--after' << opts[:after] if opts[:after] @cmd << '--before' << opts[:before] if opts[:before] end def to_s `#{@cmd.join(' ')}` end class Commit SPACE = "\s" attr_reader :file_statuses, :committed_at def initialize(lines) @committed_at = lines.shift @file_statuses = lines.map{ |l| FileStatus.new(l) } end # https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 class FileStatus TAB = /\t/ AMD = /^[AMD]/ RENAME = /^R/ attr_reader :status, :name, :old_name def initialize(line) if line =~ AMD @status, @name = line.split(TAB) @status = @status.downcase.to_sym elsif line =~ RENAME @score, @old_name, @name = line.split(TAB) @status = :r end @name.strip! if @name end end end EMPTY_LINE = "\n" def commits Enumerator.new do |y| batch = [] Open3.popen2(*@cmd) do |stdin, stdout, status_thread| stdout.each_line do |line| next batch << line unless line == EMPTY_LINE y << Commit.new(batch) batch.clear end raise 'fail to loop git log' unless status_thread.value.success? end y << Commit.new(batch) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
obst-0.1.7 | lib/obst/git_log.rb |
obst-0.1.6 | lib/obst/git_log.rb |
obst-0.1.5 | lib/obst/git_log.rb |
obst-0.1.4 | lib/obst/git_log.rb |
obst-0.1.3 | lib/obst/git_log.rb |
obst-0.1.2 | lib/obst/git_log.rb |