summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-27 08:42:26 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-27 08:42:26 -0800
commit6bbead02aa2a60e7d50e68f3b2c98a14c26b2d81 (patch)
tree6233897a4ff9b1eec589d47a5a4a5eee458fa19f
parentb7a7d204bad7de8696ac800c3d1e608bdc344a38 (diff)
downloadthird_party-ruby-git-6bbead02aa2a60e7d50e68f3b2c98a14c26b2d81.zip
third_party-ruby-git-6bbead02aa2a60e7d50e68f3b2c98a14c26b2d81.tar.gz
third_party-ruby-git-6bbead02aa2a60e7d50e68f3b2c98a14c26b2d81.tar.xz
added ls-tree to gitr
-rwxr-xr-xbin/gitr31
-rw-r--r--lib/git/base.rb6
-rw-r--r--lib/git/object.rb10
3 files changed, 30 insertions, 17 deletions
diff --git a/bin/gitr b/bin/gitr
index 53c8055..bf1e192 100755
--- a/bin/gitr
+++ b/bin/gitr
@@ -12,9 +12,9 @@
# add --log-file
# add --help
-#require 'lib/git'
-require 'rubygems'
-require 'git'
+require 'lib/git'
+#require 'rubygems'
+#require 'git'
require 'logger'
command = ARGV[0]
@@ -25,15 +25,17 @@ if !command
puts
puts 'commands: log'
puts ' log-shas'
- puts ' cat-file'
- puts ' rev-parse'
+ puts ' cat-file (treeish)'
+ puts ' rev-parse (treeish)'
puts ' branches'
puts ' config'
+ puts ' ls-tree (tree)'
exit
end
git_dir = ENV['GIT_DIR'] || '.git'
-@git = Git.bare(git_dir, :log => Logger.new(STDOUT))
+#@git = Git.bare(git_dir, :log => Logger.new(STDOUT))
+@git = Git.bare(git_dir)
case command
when 'log'
@@ -60,10 +62,17 @@ when 'config'
@git.config.sort.each do |k,v|
puts "#{k} : #{v}"
end
+when 'ls-tree'
+ # gitr ls-tree
+ tree = @git.gtree(ARGV[1])
+ tree.blobs.sort.each do |name, c|
+ puts [[c.mode, c.type, c.sha].join(" "), name].join("\t")
+ end
+ tree.trees.sort.each do |name, c|
+ puts [[c.mode, c.type, c.sha].join(" "), name].join("\t")
+ end
end
-# gitr ls-tree
-# gitr pack-browse
-
-# gitr diff / stats ?
-# output in yaml? \ No newline at end of file
+# todo:
+# gitr pack-browse
+# gitr diff / stats ?
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 31ba9ff..e9ffc61 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -428,7 +428,11 @@ module Git
def revparse(objectish)
self.lib.revparse(objectish)
end
-
+
+ def ls_tree(objectish)
+ self.lib.ls_tree(objectish)
+ end
+
def cat_file(objectish)
self.lib.object_contents(objectish)
end
diff --git a/lib/git/object.rb b/lib/git/object.rb
index 97a1a17..04102bc 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -136,8 +136,8 @@ module Git
@trees = {}
@blobs = {}
data = @base.lib.ls_tree(@objectish)
- data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) }
- data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) }
+ data['tree'].each { |k, d| @trees[k] = Git::Object::Tree.new(@base, d[:sha], d[:mode]) }
+ data['blob'].each { |k, d| @blobs[k] = Git::Object::Blob.new(@base, d[:sha], d[:mode]) }
end
end
@@ -213,8 +213,8 @@ module Git
end
@committer = Git::Author.new(data['committer'])
@author = Git::Author.new(data['author'])
- @tree = Tree.new(@base, data['tree'])
- @parents = data['parent'].map{ |sha| Commit.new(@base, sha) }
+ @tree = Git::Object::Tree.new(@base, data['tree'])
+ @parents = data['parent'].map{ |sha| Git::Object::Commit.new(@base, sha) }
@message = data['message'].chomp
end
@@ -259,7 +259,7 @@ module Git
if sha == ''
raise Git::GitTagNameDoesNotExist.new(objectish)
end
- return Tag.new(base, sha, objectish)
+ return Git::Object::Tag.new(base, sha, objectish)
else
if !type
type = base.lib.object_type(objectish)