summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-15 16:37:22 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-15 16:37:22 -0800
commitde33ae22c4ee389afc4a9e15b3edab17d4528321 (patch)
tree6850d7877f4d892e0ae25e5b1c8fc636a6ac6b9e
parenta6e6c0552708166ea052a99bdd9420dcc33536e0 (diff)
downloadthird_party-ruby-git-de33ae22c4ee389afc4a9e15b3edab17d4528321.zip
third_party-ruby-git-de33ae22c4ee389afc4a9e15b3edab17d4528321.tar.gz
third_party-ruby-git-de33ae22c4ee389afc4a9e15b3edab17d4528321.tar.xz
added object content caching
-rw-r--r--lib/git/object.rb6
-rw-r--r--tests/units/test_index_ops.rb2
-rw-r--r--tests/units/test_object.rb1
3 files changed, 6 insertions, 3 deletions
diff --git a/lib/git/object.rb b/lib/git/object.rb
index 33c3e38..afda923 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -10,7 +10,8 @@ module Git
attr_accessor :sha, :size, :type, :mode
@base = nil
-
+ @contents = nil
+
def initialize(base, sha)
@base = base
@sha = sha.to_s
@@ -18,8 +19,9 @@ module Git
setup
end
+ # caches the contents of this call in memory
def contents
- @base.lib.object_contents(@sha)
+ @contents || @contents = @base.lib.object_contents(@sha)
end
def contents_array
diff --git a/tests/units/test_index_ops.rb b/tests/units/test_index_ops.rb
index de3a9c3..f92ae9e 100644
--- a/tests/units/test_index_ops.rb
+++ b/tests/units/test_index_ops.rb
@@ -23,7 +23,7 @@ class TestIndexOps < Test::Unit::TestCase
assert(!g.status.untracked.assoc('test-file'))
assert(!g.status.changed.assoc('example.txt'))
- append_file('example.txt', 'hahahaha')
+ new_file('example.txt', 'hahahaha')
assert(g.status.changed.assoc('example.txt'))
g.add
diff --git a/tests/units/test_object.rb b/tests/units/test_object.rb
index acc32b0..c6ee5ce 100644
--- a/tests/units/test_object.rb
+++ b/tests/units/test_object.rb
@@ -96,6 +96,7 @@ class TestObject < Test::Unit::TestCase
def test_blob_contents
o = @git.object('v2.6:example.txt')
assert_equal('replace with new text', o.contents)
+ assert_equal('replace with new text', o.contents) # this should be cached
end
def test_revparse