diff options
author | scott Chacon <schacon@agadorsparticus.(none)> | 2007-11-23 11:16:46 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.(none)> | 2007-11-23 11:16:46 -0800 |
commit | f1366b39891402b0db9de661ad181089bfd79053 (patch) | |
tree | d6ef49a6bda5b7327d6d6a66edfb9c8bdb5a97cc /lib/git/lib.rb | |
parent | 90dea6d415bfc5734bc87c2797b26cca311246bc (diff) | |
download | third_party-ruby-git-f1366b39891402b0db9de661ad181089bfd79053.tar.gz third_party-ruby-git-f1366b39891402b0db9de661ad181089bfd79053.tar.xz third_party-ruby-git-f1366b39891402b0db9de661ad181089bfd79053.zip |
got log and cat-file moved to pure ruby
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r-- | lib/git/lib.rb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb index eb06875..9c6a041 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -13,6 +13,7 @@ module Git @path = nil @logger = nil + @raw_repo = nil def initialize(base = nil, logger = nil) if base.is_a?(Git::Base) @@ -75,6 +76,15 @@ module Git end def full_log_commits(opts = {}) + if !(opts[:since] || opts[:between] || opts[:path_limiter]) + # can do this in pure ruby + sha = revparse(opts[:object] || branch_current || 'master') + count = opts[:count] || 30 + + repo = Git::Raw::Repository.new(@git_dir) + return process_commit_data(repo.log(sha, count)) + end + arr_opts = ['--pretty=raw'] arr_opts << "-#{opts[:count]}" if opts[:count] arr_opts << "--since=\"#{opts[:since]}\"" if opts[:since].is_a? String @@ -92,10 +102,13 @@ module Git end head = File.join(@git_dir, 'refs', 'heads', string) - return File.read(head) if File.file?(head) + return File.read(head).chomp if File.file?(head) head = File.join(@git_dir, 'refs', 'remotes', string) - return File.read(head) if File.file?(head) + return File.read(head).chomp if File.file?(head) + + head = File.join(@git_dir, 'refs', 'tags', string) + return File.read(head).chomp if File.file?(head) command('rev-parse', string) end @@ -111,17 +124,22 @@ module Git def object_size(sha) command('cat-file', ['-s', sha]).to_i end + + def get_raw_repo + @raw_repo ||= Git::Raw::Repository.new(@git_dir) + end # returns useful array of raw commit object data def commit_data(sha) sha = sha.to_s - cdata = command_lines('cat-file', ['commit', sha]) + cdata = get_raw_repo.cat_file(revparse(sha)) + #cdata = command_lines('cat-file', ['commit', sha]) process_commit_data(cdata, sha) end def process_commit_data(data, sha = nil) in_message = false - + if sha hsh = {'sha' => sha, 'message' => '', 'parent' => []} else @@ -129,6 +147,7 @@ module Git end data.each do |line| + line = line.chomp if in_message && line != '' hsh['message'] += line + "\n" end |