added ls-tree to gitr
authorscott Chacon <schacon@agadorsparticus.(none)>
Tue, 27 Nov 2007 16:42:26 +0000 (27 08:42 -0800)
committerscott Chacon <schacon@agadorsparticus.(none)>
Tue, 27 Nov 2007 16:42:26 +0000 (27 08:42 -0800)
bin/gitr
lib/git/base.rb
lib/git/object.rb

index 53c8055..bf1e192 100755 (executable)
--- 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 ?
index 31ba9ff..e9ffc61 100644 (file)
@@ -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
index 97a1a17..04102bc 100644 (file)
@@ -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)