diff options
author | Michael Siebert <siebertm85@googlemail.com> | 2008-05-09 17:22:31 +0200 |
---|---|---|
committer | Scott Chacon <schacon@gmail.com> | 2008-05-12 17:30:13 -0700 |
commit | 7df710fdb2e9b6376b3201ac6dee9ea6524f6e5f (patch) | |
tree | fc170fe0e81f1ca4e3ca3056544429b30de28af9 /lib/git/lib.rb | |
parent | ae106e2a3569e5ea874852c613ed060d8e232109 (diff) | |
download | third_party-ruby-git-7df710fdb2e9b6376b3201ac6dee9ea6524f6e5f.tar.gz third_party-ruby-git-7df710fdb2e9b6376b3201ac6dee9ea6524f6e5f.tar.xz third_party-ruby-git-7df710fdb2e9b6376b3201ac6dee9ea6524f6e5f.zip |
Add the possibility to read blob contents in chunks via IO#popen
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r-- | lib/git/lib.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 55191fe..033df12 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -166,8 +166,8 @@ module Git end end - def object_contents(sha) - command('cat-file', ['-p', sha]) + def object_contents(sha, &block) + command('cat-file', ['-p', sha], &block) end def ls_tree(sha) @@ -596,20 +596,20 @@ module Git command(cmd, opts, chdir).split("\n") end - def command(cmd, opts = [], chdir = true) + def command(cmd, opts = [], chdir = true, &block) ENV['GIT_DIR'] = @git_dir if (@git_dir != ENV['GIT_DIR']) ENV['GIT_INDEX_FILE'] = @git_index_file if (@git_index_file != ENV['GIT_INDEX_FILE']) ENV['GIT_WORK_TREE'] = @git_work_dir if (@git_work_dir != ENV['GIT_WORK_TREE']) path = @git_work_dir || @git_dir || @path opts = opts.to_a.join(' ') - git_cmd = "git #{cmd} #{opts}" + git_cmd = "git #{cmd} #{opts} 2>&1" out = nil if chdir && (Dir.getwd != path) - Dir.chdir(path) { out = `#{git_cmd} 2>&1`.chomp } + Dir.chdir(path) { out = run_command(git_cmd, &block) } else - out = `#{git_cmd} 2>&1`.chomp + out = run_command(git_cmd, &block) end if @logger @@ -626,5 +626,13 @@ module Git out end + def run_command(git_cmd, &block) + if block_given? + IO.popen(git_cmd, &block) + else + `#{git_cmd}`.chomp + end + end + end end |