summaryrefslogtreecommitdiffstats
path: root/lib/git/lib.rb
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-27 08:21:48 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-27 08:21:48 -0800
commit779f21b307e7c119a56700fb14f88ba63a2cccc2 (patch)
treef3f03821dbe66f581ae2707e6e872395adc7afbe /lib/git/lib.rb
parent55c3c134c5c19103ed52fbd615d5af351fa9bb34 (diff)
parent6a9db968e8563bc27b8f56f9d413159a2e14cf67 (diff)
downloadthird_party-ruby-git-779f21b307e7c119a56700fb14f88ba63a2cccc2.tar.gz
third_party-ruby-git-779f21b307e7c119a56700fb14f88ba63a2cccc2.tar.xz
third_party-ruby-git-779f21b307e7c119a56700fb14f88ba63a2cccc2.zip
Merge branches 'master' and 'internals'
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r--lib/git/lib.rb46
1 files changed, 37 insertions, 9 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index eb06875..cd24fca 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,17 @@ 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
+
+ if /\w{40}/.match(sha) # valid sha
+ repo = get_raw_repo
+ return process_commit_data(repo.log(sha, count))
+ end
+ 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 +104,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 +126,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 +149,7 @@ module Git
end
data.each do |line|
+ line = line.chomp
if in_message && line != ''
hsh['message'] += line + "\n"
end
@@ -163,16 +184,23 @@ module Git
end
def object_contents(sha)
- command('cat-file', ['-p', sha])
+ #command('cat-file', ['-p', sha])
+ get_raw_repo.cat_file(revparse(sha)).chomp
end
def ls_tree(sha)
data = {'blob' => {}, 'tree' => {}}
- command_lines('ls-tree', sha.to_s).each do |line|
- (info, filenm) = line.split("\t")
- (mode, type, sha) = info.split
- data[type][filenm] = {:mode => mode, :sha => sha}
+
+ get_raw_repo.object(revparse(sha)).entry.each do |e|
+ data[e.format_type][e.name] = {:mode => e.format_mode, :sha => e.sha1}
end
+
+ #command_lines('ls-tree', sha.to_s).each do |line|
+ # (info, filenm) = line.split("\t")
+ # (mode, type, sha) = info.split
+ # data[type][filenm] = {:mode => mode, :sha => sha}
+ #end
+
data
end