Class: GitHack::CommitFacade
- Inherits:
-
Object
- Object
- GitHack::CommitFacade
- Defined in:
- lib/git-hack/commit_facade.rb
Instance Method Summary collapse
- #current_commit ⇒ Object
- #data_from_file(path) ⇒ Object
-
#get_log_commits ⇒ Object
从log中取得当前commit之前的Commits.
- #get_next_commit ⇒ Object
-
#initialize(dir) ⇒ CommitFacade
constructor
A new instance of CommitFacade.
Constructor Details
#initialize(dir) ⇒ CommitFacade
Returns a new instance of CommitFacade.
8 9 10 11 |
# File 'lib/git-hack/commit_facade.rb', line 8 def initialize(dir) @dir = dir @commits = [] end |
Instance Method Details
#current_commit ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/git-hack/commit_facade.rb', line 33 def current_commit @current_commit if @current_commit data = data_from_file("#{@dir}/.git/HEAD") commit_file_data = SimpleLineBuilder.new(data,0).parse commit_file = commit_file_data.value @current_commit = data_from_file("#{@dir}/.git/#{commit_file}") @current_commit = @current_commit[0].chomp end |
#data_from_file(path) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/git-hack/commit_facade.rb', line 41 def data_from_file(path) file = File.open(path) data = [] file.each { |line| data << line } data end |
#get_log_commits ⇒ Object
从log中取得当前commit之前的Commits
14 15 16 17 18 19 20 |
# File 'lib/git-hack/commit_facade.rb', line 14 def get_log_commits git = Git.open(@dir ,:log => Logger.new(STDOUT)) l = Git::Lib.new(git) opts = ["--pretty=raw"] data = l.command_lines_patch('log',opts) return @commits = CommitLineBuilder.new(data,0).all_objects end |
#get_next_commit ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/git-hack/commit_facade.rb', line 21 def get_next_commit file = File.open("#{@dir}/.git/logs/HEAD") data = [] file.each { |line| data << line } commit_data = SimpleLineBuilder.new(data,0).find_all commit = commit_data.find do |c| c.object == current_commit end commit_sha = commit ? commit.value : nil end |