Skip to content

Commit

Permalink
write_tree can take a sha for a tree and can return the last tree siz…
Browse files Browse the repository at this point in the history
…e via an instance var
  • Loading branch information
schacon authored and rtomayko committed Jun 8, 2011
1 parent 7fbeffc commit 2bedb05
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/grit/index.rb
Expand Up @@ -12,6 +12,9 @@ class Index
# which the next commit will be based.
attr_accessor :current_tree

# Public: if a tree is written, this stores the size of that tree
attr_reader :last_tree_size

# Initialize a new Index object.
#
# repo - The Grit::Repo to which the index belongs.
Expand Down Expand Up @@ -154,6 +157,7 @@ def write_tree(tree, now_tree = nil)
tree_contents = {}

# fill in original tree
now_tree = read_tree(now_tree) if(now_tree && now_tree.is_a?(String))
now_tree.contents.each do |obj|
sha = [obj.id].pack("H*")
k = obj.name
Expand Down Expand Up @@ -182,6 +186,7 @@ def write_tree(tree, now_tree = nil)
end

tr = tree_contents.sort.map { |k, v| v }.join('')
@last_tree_size = tr.size
self.repo.git.put_raw_object(tr, 'tree')
end

Expand Down

0 comments on commit 2bedb05

Please sign in to comment.