Permalink
Browse files

convert check_for_keymap_helper to gitrepo api

  • Loading branch information...
1 parent 25523a0 commit e4253cc5c1622a70ef259032fd90524acb702494 @bronson bronson committed Nov 2, 2011
Showing with 28 additions and 8 deletions.
  1. +10 −0 lib/gitrepo.rb
  2. +8 −8 scraper
  3. +10 −0 spec/gitrepo_spec.rb
View
@@ -48,6 +48,7 @@ def git_exec *args
options = { :before_exec => lambda { } }
options.merge! args.pop if args[-1].is_a? Hash
args = args.map { |a| a.to_s }
+
out = IO.popen('-', 'r') do |io|
if io # parent
block_given? ? yield(io) : io.read
@@ -135,6 +136,15 @@ def add name, contents
def entries
@repo.root.to_a.map { |name,value| name }
end
+
+ # If the entry is a tree, returns an array of the names in the tree.
+ # If a blob, returns the blob data. Othewise returns nil.
+ def entry name, type=nil
+ data = @repo.root[name]
+ raise GitError.new "type was #{data.type} not #{type}" if type && type != data.type
+ return data.map { |n,v| n } if data && data.type == :tree
+ return data.dump if data && data.type == :blob
+ end
end
View
16 scraper
@@ -1212,19 +1212,19 @@ def check_for_readme_file commit
end
-def check_for_keymap_helper repo, script
+def check_for_keymap_helper commit, script
# It's easy to autodetect keymap files (see is_keymap_file above)
# but some keymaps come with additional scripts that are not so common
- return unless repo.root['keymap'] && repo.root['plugin']
- names = repo.root['keymap'].map { |n,v| n }
+ return unless commit.entry('keymap') && commit.entry('plugin')
+ names = commit.entry('keymap', :tree)
namesre = Regexp.union names
- repo.root['plugin'].each do |name, node|
- contents = node.data.dup
+ commit.entry('plugin', :tree).each do |name|
+ contents = commit.entry("plugin/#{name}").dup
contents.force_encoding "ASCII-8BIT"
if contents.lines.find { |line| line =~ /^\s*source\s+<sfile>:p:h\/#{namesre}/ }
# yep, it's a keymap helper.
- blob = repo.root['plugin'].delete(name)
- copy_file repo, "keymap/#{name}", blob.data
+ data = commit.remove "plugin/#{name}"
+ copy_file commit, "keymap/#{name}", data
end
end
end
@@ -1258,7 +1258,7 @@ def store_versions_in_repo repo, script
repo.commit(fix_release_notes(version), author, committer) do |commit|
commit.empty_index
add_version commit, version, script
- check_for_keymap_helper repo, script
+ check_for_keymap_helper commit, script
check_for_readme_file commit
copy_file(commit, 'README', "This is a mirror of #{script_id_to_url(script['script_id'])}\n\n" + script['description'] + "\n") unless repo.root['README']
end
View
@@ -211,6 +211,16 @@ def git_tree repo, spec
commit.add 'a/b/c dir/d/e.txt', "e text file contents\n"
commit.add 'a/b/c dir/d/f.txt', "f text file contents\n"
commit.entries.sort.should == ['README', 'a']
+ # exercise the entry function
+ commit.entry('a', :tree).should == ['b']
+ commit.entry('a/b/c dir/d').sort.should == ['e.txt', 'f.txt']
+ commit.entry('a/b/c dir/d/e.txt', :blob).should == "e text file contents\n"
+ lambda {
+ commit.entry('a', :blob)
+ }.should raise_error(GitRepo::GitError, /type was tree not blob/)
+ lambda {
+ commit.entry('a/b/c dir/d/e.txt', :tree)
+ }.should raise_error(GitRepo::GitError, /type was blob not tree/)
end
repo.git('log', '--pretty=oneline').split("\n").length.should == 2
git_tree(repo, 'HEAD').should == ['blob README', 'tree a']

0 comments on commit e4253cc

Please sign in to comment.