Skip to content

Commit

Permalink
Refactored code to use multi_git and recent ridley
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Georg committed Jun 23, 2013
1 parent ef9dba5 commit 6aa647a
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 224 deletions.
118 changes: 77 additions & 41 deletions Gemfile.lock
Expand Up @@ -3,88 +3,124 @@ PATH
specs:
ridley-git (0.0.1.alpha1)
borx (>= 0.0.1.beta1)
ridley (~> 0.8.0, >= 0.8.4)
rugged (>= 0.17.0b1)
multi_git (>= 0.0.1.beta1)
ridley (>= 0.10.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.3)
addressable (2.3.4)
akami (1.2.0)
gyoku (>= 0.4.0)
nokogiri (>= 1.4.0)
borx (0.0.1.beta1)
sorcerer (~> 0.3.10)
celluloid (0.12.4)
facter (>= 1.6.12)
buff-extensions (0.5.0)
buff-ruby_engine (0.1.0)
buff-shell_out (0.1.0)
buff-ruby_engine (~> 0.1.0)
builder (3.2.2)
celluloid (0.14.1)
timers (>= 1.0.0)
chozo (0.6.1)
activesupport (>= 3.2.0)
hashie (>= 2.0.2)
multi_json (>= 1.3.0)
celluloid-io (0.14.1)
celluloid (>= 0.14.1)
nio4r (>= 0.4.5)
colorize (0.5.8)
coveralls (0.6.2)
coveralls (0.6.7)
colorize
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
thor
diff-lcs (1.2.1)
diff-lcs (1.2.4)
erubis (2.7.0)
facter (1.6.18)
faraday (0.8.6)
faraday (0.8.7)
multipart-post (~> 1.1)
hashie (2.0.2)
i18n (0.6.4)
json (1.7.7)
mime-types (1.21)
ffi (1.9.0)
gssapi (1.0.3)
ffi (>= 1.0.1)
gyoku (1.0.0)
builder (>= 2.1.2)
hashie (2.0.5)
httpclient (2.2.0.2)
httpi (0.9.7)
rack
json (1.8.0)
little-plugger (1.1.3)
logging (1.6.2)
little-plugger (>= 1.1.3)
mime-types (1.23)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-config (1.1.2)
mixlib-log (1.4.1)
mixlib-shellout (1.1.0)
multi_json (1.6.1)
mixlib-log (1.6.0)
multi_git (0.0.1.beta1)
multi_json (1.7.7)
multipart-post (1.2.0)
net-http-persistent (2.8)
net-ssh (2.6.6)
net-ssh (2.6.7)
nio4r (0.4.6)
nokogiri (1.5.10)
nori (1.1.5)
rack (1.5.2)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.2)
ridley (0.8.5)
activesupport (>= 3.2.0)
retryable (1.3.3)
ridley (1.2.3)
addressable
celluloid
chozo (>= 0.6.0)
buff-extensions (~> 0.3)
buff-shell_out (~> 0.1)
celluloid (~> 0.14.0)
celluloid-io (~> 0.14.0)
erubis
faraday (>= 0.8.4)
json (>= 1.5.0)
hashie (>= 2.0.2)
json (>= 1.7.7)
mixlib-authentication (>= 1.3.0)
mixlib-config (>= 1.1.0)
mixlib-log (>= 1.3.0)
mixlib-shellout (>= 1.1.0)
multi_json (>= 1.0.4)
net-http-persistent (>= 2.8)
net-ssh
retryable
solve (>= 0.4.1)
solve (>= 0.4.4)
varia_model (~> 0.1)
winrm (~> 1.1.0)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.0)
rugged (0.17.0.b7)
rspec-mocks (2.13.1)
rubyntlm (0.1.1)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
solve (0.4.2)
json
solve (0.5.0)
sorcerer (0.3.10)
thor (0.17.0)
thor (0.18.1)
timers (1.1.0)
uuidtools (2.1.4)
varia_model (0.1.0)
buff-extensions (~> 0.1)
hashie (>= 2.0.2)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
winrm (1.1.2)
gssapi (~> 1.0.0)
httpclient (~> 2.2.0.2)
logging (~> 1.6.1)
nokogiri (~> 1.5.0)
rubyntlm (~> 0.1.1)
savon (= 0.9.5)
uuidtools (~> 2.1.2)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 92.31
"covered_percent": 92.47
}
}
86 changes: 13 additions & 73 deletions lib/ridley/git.rb
@@ -1,50 +1,15 @@
require 'ridley'
require 'ridley/chef/cookbook'
require 'ridley/chef/digester'
require 'rugged'
require 'multi_git'

module Ridley::Git

module Utils

def traverse(git, tree, path)
path.split('/').inject(tree) do |tree, elem|
case(elem)
when '', '.' then tree
else
entry = tree[elem]
raise "Missing path #{elem}" unless entry
git.lookup(entry[:oid])
end
end
end

def rev_to_oid(git, rev)
Rugged::Reference.lookup(git, rev).resolve.target
end


extend self

end

class Cache < Hash

def initialize(git)
@git = git
super(){|hsh,key| hsh[key] = Digest::MD5.hexdigest(git.lookup(key).content) }
end

end

class BlobIO < IO

def initialize(git_blob)
@blob = git_blob
end

def read
@blob.content
super(){|hsh,key| hsh[key] = Digest::MD5.hexdigest(git.read(key).content) }
end

end
Expand All @@ -57,8 +22,8 @@ class Repository

def initialize(git_repository, options = {})
if git_repository.kind_of? String
@git = Rugged::Repository.discover(git_repository)
elsif git_repository.kind_of? Rugged::Repository
@git = MultiGit.open(git_repository)
elsif git_repository.kind_of? MultiGit::Repository
@git = git_repository
else
raise ArgumentException, "Cannot convert #{git_repository.inspect} into a Rugged::Repository"
Expand All @@ -67,43 +32,18 @@ def initialize(git_repository, options = {})
@cache = Cache.new(@git)
end

def each( refs, path = '/' )
walker = Rugged::Walker.new(@git)
case(refs)
when String then
walker.push(Utils.rev_to_oid(git, refs))
when Array then
refs.each do |r|
walker.push(Utils.rev_to_oid(git, r))
end
when Range then
walker.push( Utils.rev_to_oid(git, refs.end) )
walker.hide( Utils.rev_to_oid(git, refs.begin) )
end
seen = Set.new
walker.each do |commit|
tree = Utils.traverse(@git, commit.tree, path)
unless seen.include? tree
yield self[tree]
seen << tree
end
end
return self
def []( name, path = '/' )
rev = git.read(name)
Cookbook.new(git, rev, path , :cache => cache)
end

def []( name, path = '/' )
base = nil
case name
when String then
return self[ git.lookup(Rugged::Reference.lookup(git, name).resolve.target), path ]
when Rugged::Commit then
base = name.tree
when Rugged::Tree then
base = name
else
raise "Unknown arg #{name}"
def each(from, path = '/' )
commit = git.read(from)
loop do
yield Cookbook.new(git, commit, path, :cache => cache )
commit = commit.parents[0]
return if commit.nil?
end
Cookbook.new(git, Utils.traverse(git, base, path) , :cache => cache)
end

private
Expand Down

0 comments on commit 6aa647a

Please sign in to comment.