Permalink
Browse files

index multiple branches, index the colorized code. So we can still do…

… hightlighting of results later..
  • Loading branch information...
OriPekelman committed Nov 16, 2011
1 parent cc558d1 commit a69610e3a765f8fc382e45452577354bb530cc4a
Showing with 19 additions and 16 deletions.
  1. +19 −16 gitelasticsearch.rb
View
@@ -3,7 +3,8 @@
require 'tire'
class GitElasticSearch
- attr_reader :index_name
+ attr_reader :index_name
+
include Grit
Grit::Blob.class_eval { include Linguist::BlobHelper }
@@ -14,44 +15,46 @@ def initialize(git_path)
@index_name = "git_repo_#{File.basename(git_path, '.git')}"
@index = Tire::Index.new(@index_name)
-
@repo = Grit::Repo.new(git_path)
- @t = @repo.tree
end
def init!
@index.delete
@index.create
end
-
- def index!
- recurse(@t)
- @index.refresh
+
+ def index!
+ @repo.branches.map{|branch|recurse(@repo.tree(branch.name), branch.name)} # @fixme this woefully inefficient, we are repeating in the index each blob, even it it is the same in each branch; This also makes it hard to get the authored, date info. The whole thing should probably index through traversing commits and not the tree through branches. This shows just how awsome and efficient git is.
return @index
end
+
+ def refresh
+ @index.refresh
+ end
private
- def recurse(tree, path = "")
+ def recurse(tree, path = "", branch_name)
tree.contents.each do |c|
case c
when Tree
- traverse_dir c, path
+ traverse_dir c, path, branch_name
when Blob
- index_file(c, path)
+ index_file(c, path, branch_name)
end
end
end
- def traverse_dir (c, path)
- if DEBUG then puts "#{path}#{c.name} (#{c.id})" end
- recurse(c, path + "/" + c.name)
+ def traverse_dir (c, path, branch_name)
+ if DEBUG then puts "#{path}/#{c.name} (#{c.id}) @#{branch_name}" end
+ recurse(c, path + "/" + c.name, branch_name)
end
- def index_file (c, path)
- if DEBUG then puts "#{path}#{c.name} (#{c.id})" end
+ def index_file (c, path, branch_name)
+ if DEBUG then puts "#{path}/#{c.name} (#{c.id}) @#{branch_name} " end
if c.text? then
- @index.store :code=> c.data.force_encoding("UTF-8"), :_id=>c.id,:path => path, :name=>c.name
+ @index.store :code=> c.colorize, :_id=>"#{c.id}@#{branch_name}",:path => path, :name=>c.name, :branch => branch_name, :language =>c.language , :date=>@authored_date#, :author=>c.author_string, :date=>c.date
+ #puts c.methods.inspect
end
end

0 comments on commit a69610e

Please sign in to comment.