summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Chacon <schacon@gmail.com>2008-03-08 18:33:34 -0800
committerScott Chacon <schacon@gmail.com>2008-03-08 18:33:34 -0800
commit476d943baabc9852f1653088a58bdb2912bbd95a (patch)
tree8539fe944c25c5b52ad8fd46dce10cc35b6ae86f
parent099f60dd07aeefd31c94eae532db97e811562fb7 (diff)
downloadthird_party-ruby-git-476d943baabc9852f1653088a58bdb2912bbd95a.zip
third_party-ruby-git-476d943baabc9852f1653088a58bdb2912bbd95a.tar.gz
third_party-ruby-git-476d943baabc9852f1653088a58bdb2912bbd95a.tar.xz
added tree.depth and tree.full_tree
-rw-r--r--lib/git/lib.rb8
-rw-r--r--lib/git/object.rb8
-rw-r--r--tests/units/test_object.rb5
3 files changed, 21 insertions, 0 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 4352640..8003336 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -181,6 +181,14 @@ module Git
data
end
+
+ def full_tree(sha)
+ command_lines('ls-tree', ['-r', sha.to_s])
+ end
+
+ def tree_depth(sha)
+ full_tree(sha).size
+ end
def branches_all
head = File.read(File.join(@git_dir, 'HEAD'))
diff --git a/lib/git/object.rb b/lib/git/object.rb
index 04102bc..e35060c 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -124,6 +124,14 @@ module Git
alias_method :subtrees, :trees
alias_method :subdirectories, :trees
+ def full_tree
+ @base.lib.full_tree(@objectish)
+ end
+
+ def depth
+ @base.lib.tree_depth(@objectish)
+ end
+
private
def setup
diff --git a/tests/units/test_object.rb b/tests/units/test_object.rb
index a574919..543f021 100644
--- a/tests/units/test_object.rb
+++ b/tests/units/test_object.rb
@@ -72,6 +72,11 @@ class TestObject < Test::Unit::TestCase
assert_equal(1, o.blobs.size)
assert_equal(1, o.subtrees.size)
assert_equal(1, o.trees['ex_dir'].blobs.size)
+
+ assert_equal(2, o.full_tree.size)
+ assert_equal("100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\tex_dir/ex.txt", o.full_tree.first)
+
+ assert_equal(2, o.depth)
o = @git.gtree('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7')
assert(o.is_a?(Git::Object::Tree))