summaryrefslogtreecommitdiffstats
path: root/lib/git/object.rb
diff options
context:
space:
mode:
authorMichael Siebert <siebertm85@googlemail.com>2008-05-09 17:22:31 +0200
committerScott Chacon <schacon@gmail.com>2008-05-12 17:30:13 -0700
commit7df710fdb2e9b6376b3201ac6dee9ea6524f6e5f (patch)
treefc170fe0e81f1ca4e3ca3056544429b30de28af9 /lib/git/object.rb
parentae106e2a3569e5ea874852c613ed060d8e232109 (diff)
downloadthird_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/object.rb')
-rw-r--r--lib/git/object.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/git/object.rb b/lib/git/object.rb
index e35060c..5ec24e2 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -28,9 +28,17 @@ module Git
@size || @size = @base.lib.object_size(@objectish)
end
- # caches the contents of this call in memory
- def contents
- @contents || @contents = @base.lib.object_contents(@objectish)
+ # get the object's contents
+ # if no block is given, the contents are cached in memory and returned as a string
+ # if a block is given, it yields an IO object (via IO::popen) which could be used to
+ # read a large file in chunks. use this for large files so that they are not held
+ # in memory
+ def contents(&block)
+ if block_given?
+ @base.lib.object_contents(@objectish, &block)
+ else
+ @contents || @contents = @base.lib.object_contents(@objectish)
+ end
end
def contents_array