From 1f63953f05a4afe74f881d54f69f77da513939d5 Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Thu, 8 Nov 2007 17:07:04 -0800 Subject: moved the git objects into the object.rb file --- lib/git/lib.rb | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'lib/git/lib.rb') diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 3df049c..595f294 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -1,21 +1,57 @@ module Git + + class GitExecuteError < StandardError + end + class Lib - + @base = nil def initialize(base) @base = base end - def log_shas(count) - command('log', "-#{count} --pretty=oneline").split("\n").map { |l| Git::Commit.new(l.split.first) } + def log_commits(opts) + arr_opts = ['--pretty=oneline'] + arr_opts << "-#{opts[:count]}" if opts[:count] + arr_opts << "--since=\"#{opts[:since]}\"" if opts[:since].is_a? String + arr_opts << "#{opts[:between][0]}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2) + arr_opts << opts[:file] if opts[:file].is_a? String + + command('log', arr_opts).split("\n").map { |l| Git::Commit.new(l.split.first) } + end + + def revparse(string) + command('rev-parse', string) + end + + def object_type(sha) + command('cat-file', ['-t', sha]) + end + + def object_size(sha) + command('cat-file', ['-s', sha]) + end + + def object_contents(sha) + command('cat-file', ['-p', sha]) end private def command(cmd, opts) - ENV['GIT_DIR'] = @base.repo.path - `git #{cmd} #{opts}` + ENV['GIT_DIR'] = @base.repo.path + ENV['GIT_INDEX_FILE'] = @base.index.path + ENV['GIT_WORK_DIR'] = @base.dir.path + Dir.chdir(@base.dir.path) do + opts = opts.to_a.join(' ') + #puts "git #{cmd} #{opts}" + out = `git #{cmd} #{opts} 2>&1`.chomp + if $?.exitstatus != 0 + raise Git::GitExecuteError.new(out) + end + out + end end end -- cgit