Permalink
Browse files

update silo, pull relative revision retrieval from silo

  • Loading branch information...
technoweenie committed Jan 28, 2008
1 parent 8f051b1 commit f02522cb3a96beccf64d2d17cd383e9aebf0ced7
Showing with 2,935 additions and 1,092 deletions.
  1. +2 −2 app/controllers/browser_controller.rb
  2. +21 −21 app/controllers/changesets_controller.rb
  3. +12 −2 app/helpers/changesets_helper.rb
  4. +8 −0 app/models/changeset.rb
  5. +16 −1 test/functional/changesets_helper_test.rb
  6. +199 −0 vendor/silo/lib/silo/adapters/git.rb
  7. +5 −7 vendor/silo/lib/silo/adapters/mock.rb
  8. +45 −55 vendor/silo/lib/silo/adapters/svn.rb
  9. +15 −8 vendor/silo/lib/silo/node.rb
  10. +8 −0 vendor/silo/lib/silo/repository.rb
  11. +0 −57 vendor/silo/spec/mock_adapter_spec.rb
  12. +0 −16 vendor/silo/spec/mock_repo/config.yml
  13. +0 −2 vendor/silo/spec/mock_repo/test.html
  14. +0 −142 vendor/silo/spec/node_spec.rb
  15. +0 −22 vendor/silo/spec/repository_spec.rb
  16. +0 −24 vendor/silo/spec/spec_helper.rb
  17. +0 −109 vendor/silo/spec/svn_adapter_spec.rb
  18. +0 −5 vendor/silo/spec/svn_repo/README.txt
  19. +0 −21 vendor/silo/spec/svn_repo/conf/authz
  20. +0 −8 vendor/silo/spec/svn_repo/conf/passwd
  21. +0 −30 vendor/silo/spec/svn_repo/conf/svnserve.conf
  22. +0 −1 vendor/silo/spec/svn_repo/db/current
  23. +0 −1 vendor/silo/spec/svn_repo/db/format
  24. +0 −1 vendor/silo/spec/svn_repo/db/fs-type
  25. +0 −5 vendor/silo/spec/svn_repo/db/revprops/0
  26. +0 −13 vendor/silo/spec/svn_repo/db/revprops/1
  27. +0 −13 vendor/silo/spec/svn_repo/db/revprops/2
  28. +0 −11 vendor/silo/spec/svn_repo/db/revs/0
  29. BIN vendor/silo/spec/svn_repo/db/revs/1
  30. BIN vendor/silo/spec/svn_repo/db/revs/2
  31. +0 −1 vendor/silo/spec/svn_repo/db/uuid
  32. 0 vendor/silo/spec/svn_repo/db/write-lock
  33. +0 −1 vendor/silo/spec/svn_repo/format
  34. +0 −51 vendor/silo/spec/svn_repo/hooks/post-commit.tmpl
  35. +0 −44 vendor/silo/spec/svn_repo/hooks/post-lock.tmpl
  36. +0 −56 vendor/silo/spec/svn_repo/hooks/post-revprop-change.tmpl
  37. +0 −42 vendor/silo/spec/svn_repo/hooks/post-unlock.tmpl
  38. +0 −70 vendor/silo/spec/svn_repo/hooks/pre-commit.tmpl
  39. +0 −64 vendor/silo/spec/svn_repo/hooks/pre-lock.tmpl
  40. +0 −66 vendor/silo/spec/svn_repo/hooks/pre-revprop-change.tmpl
  41. +0 −60 vendor/silo/spec/svn_repo/hooks/pre-unlock.tmpl
  42. +0 −54 vendor/silo/spec/svn_repo/hooks/start-commit.tmpl
  43. +0 −3 vendor/silo/spec/svn_repo/locks/db-logs.lock
  44. +0 −3 vendor/silo/spec/svn_repo/locks/db.lock
  45. +5 −0 vendor/silo/vendor/grit/History.txt
  46. +36 −0 vendor/silo/vendor/grit/Manifest.txt
  47. +211 −0 vendor/silo/vendor/grit/README.txt
  48. +29 −0 vendor/silo/vendor/grit/Rakefile
  49. +32 −0 vendor/silo/vendor/grit/lib/grit.rb
  50. +36 −0 vendor/silo/vendor/grit/lib/grit/actor.rb
  51. +117 −0 vendor/silo/vendor/grit/lib/grit/blob.rb
  52. +173 −0 vendor/silo/vendor/grit/lib/grit/commit.rb
  53. +57 −0 vendor/silo/vendor/grit/lib/grit/diff.rb
  54. +7 −0 vendor/silo/vendor/grit/lib/grit/errors.rb
  55. +66 −0 vendor/silo/vendor/grit/lib/grit/git.rb
  56. +79 −0 vendor/silo/vendor/grit/lib/grit/head.rb
  57. +53 −0 vendor/silo/vendor/grit/lib/grit/lazy.rb
  58. +246 −0 vendor/silo/vendor/grit/lib/grit/repo.rb
  59. +109 −0 vendor/silo/vendor/grit/lib/grit/tree.rb
  60. +131 −0 vendor/silo/vendor/grit/test/fixtures/blame
  61. +1 −0 vendor/silo/vendor/grit/test/fixtures/cat_file_blob
  62. +1 −0 vendor/silo/vendor/grit/test/fixtures/cat_file_blob_size
  63. +610 −0 vendor/silo/vendor/grit/test/fixtures/diff_p
  64. BIN vendor/silo/vendor/grit/test/fixtures/for_each_ref
  65. +7 −0 vendor/silo/vendor/grit/test/fixtures/ls_tree_a
  66. +2 −0 vendor/silo/vendor/grit/test/fixtures/ls_tree_b
  67. +24 −0 vendor/silo/vendor/grit/test/fixtures/rev_list
  68. +7 −0 vendor/silo/vendor/grit/test/fixtures/rev_list_single
  69. +1 −0 vendor/silo/vendor/grit/test/fixtures/rev_parse
  70. +13 −0 vendor/silo/vendor/grit/test/helper.rb
  71. +21 −0 vendor/silo/vendor/grit/test/profile.rb
  72. +6 −0 vendor/silo/vendor/grit/test/suite.rb
  73. +35 −0 vendor/silo/vendor/grit/test/test_actor.rb
  74. +74 −0 vendor/silo/vendor/grit/test/test_blob.rb
  75. +89 −0 vendor/silo/vendor/grit/test/test_commit.rb
  76. +21 −0 vendor/silo/vendor/grit/test/test_git.rb
  77. +17 −0 vendor/silo/vendor/grit/test/test_head.rb
  78. +17 −0 vendor/silo/vendor/grit/test/test_reality.rb
  79. +210 −0 vendor/silo/vendor/grit/test/test_repo.rb
  80. +61 −0 vendor/silo/vendor/grit/test/test_tree.rb
@@ -52,11 +52,11 @@ def retrieve_current_changeset
def retrieve_previous_changeset
return nil if current_changeset.nil?
- current_repository.changesets.find_by_path(@node.path, :conditions => ['changed_at < ?', current_changeset.changed_at], :order => 'changesets.changed_at desc')
+ current_repository.changesets.find_before([@node.path], current_changeset)
end
def retrieve_next_changeset
return nil if current_changeset.nil?
- current_repository.changesets.find_by_path(@node.path, :conditions => ['changed_at > ?', current_changeset.changed_at], :order => 'changesets.changed_at')
+ current_repository.changesets.find_after([@node.path], current_changeset)
end
end
@@ -3,12 +3,9 @@ class ChangesetsController < ApplicationController
before_filter :repository_subdomain_or_login_required, :only => :index
before_filter :repository_member_required, :except => [:index, :public]
before_filter :root_domain_required, :only => :public
- before_filter :find_node, :only => :diff
+ before_filter :find_changeset, :only => [:show, :diff]
caches_action_content :index, :show, :public
-
- helper_method :previous_changeset, :next_changeset
- expiring_attr_reader :changeset_paths, :find_changeset_paths
def index
return global_index if repository_subdomain.blank? && logged_in?
@@ -35,17 +32,25 @@ def global_index
end
def show
- @changeset = current_repository.changesets.find_by_paths(changeset_paths, :conditions => ['revision = ?', params[:id]])
- unless @changeset
- return status_message(:error, "You must be a member of this repository to visit this page.", "changesets/error")
- end
@changes = @changeset.changes.paginate(:page => params[:page])
respond_to do |format|
format.html
format.diff { render :action => 'show', :layout => false }
end
end
+ def diff
+ params[:r] =
+ case params[:r]
+ when 'rev' then params[:n]
+ when 'date' then Date.new(params[:date][:year].to_i, params[:date][:month].to_i, params[:date][:day].to_i)
+ when nil then 'head'
+ else params[:r]
+ end
+ @revision = params[:rev][1..-1].to_i if params[:rev]
+ @node = current_repository.node(params[:paths] * '/', @revision)
+ end
+
def action_url_to_id
super +
if (action_name == 'index' && repository_subdomain.blank? && logged_in?) || (action_name != 'public' && changeset_paths != :all)
@@ -60,14 +65,14 @@ def action_caching_layout
end
protected
- %w(previous_changeset next_changeset changeset_paths).each { |m| expiring_attr_reader m, "find_#{m}" }
+ %w(previous_changeset next_changeset changeset_paths).each { |m| expiring_attr_reader m, "find_#{m}" ; helper_method m }
def find_previous_changeset
- current_repository.changesets.find_by_paths(changeset_paths, :conditions => ['changed_at < ?', @changeset.changed_at], :order => 'changed_at desc')
+ current_repository.changesets.find_before(changeset_paths, @changeset.changed_at)
end
def find_next_changeset
- current_repository.changesets.find_by_paths(changeset_paths, :conditions => ['changed_at > ?', @changeset.changed_at], :order => 'changed_at')
+ current_repository.changesets.find_after(changeset_paths, @changeset.changed_at)
end
def find_changeset_paths
@@ -128,15 +133,10 @@ def check_for_changeset_rev
end
end
- def find_node
- params[:r] =
- case params[:r]
- when 'rev' then params[:n]
- when 'date' then Date.new(params[:date][:year].to_i, params[:date][:month].to_i, params[:date][:day].to_i)
- when nil then 'head'
- else params[:r]
- end
- @revision = params[:rev][1..-1].to_i if params[:rev]
- @node = current_repository.node(params[:paths] * '/', @revision)
+ def find_changeset
+ @changeset = current_repository.changesets.find_by_paths(changeset_paths, :conditions => ['revision = ?', params[:id]])
+ unless @changeset
+ status_message(:error, "You must be a member of this repository to visit this page.", "changesets/error")
+ end
end
end
@@ -97,8 +97,18 @@ def find_revision_for(node, other)
return changeset ? changeset.revision : nil
end
- node.repository.revision?(other) ||
- node.revision_relative_to(other) ||
+ node.repository.revision?(other) ||
+ relative_revision_for(node, other) ||
raise(Silo::Node::Error, "Invalid Revision: #{other.inspect}")
end
+
+ def relative_revision_for(node, other)
+ changeset = \
+ case other
+ when /^head/i then current_repository.changesets.find(:first)
+ when /^next/i then current_repository.changesets.find_after(changeset_paths, @changeset)
+ when /^prev/i then current_repository.changesets.find_before(changeset_paths, @changeset)
+ end
+ changeset ? changeset.revision : nil
+ end
end
View
@@ -52,6 +52,14 @@ def self.find_latest_changeset(path = nil, revision = nil)
latest_changeset = lambda { revision ? find_by_revision(revision) : find(:first, :order => 'changesets.changed_at desc') }
path.blank? ? latest_changeset.call : with_paths([path], &latest_changeset)
end
+
+ def self.find_before(paths, changeset)
+ find_by_paths(paths, :conditions => ['id != ? and changed_at <= ?', changeset.id, changeset.changed_at], :order => 'changed_at desc')
+ end
+
+ def self.find_after(paths, changeset)
+ find_by_paths(paths, :conditions => ['id != ? and changed_at >= ?', changeset.id, changeset.changed_at], :order => 'changed_at desc')
+ end
def to_param
revision.to_s
@@ -6,6 +6,7 @@
include ChangesetsHelper
setup do
+ @changeset = "CHANGESET"
@repo = Silo::Repository.new(:svn, :path => 'foo')
@repo.stubs(:changesets).returns([])
@node = @repo.node_at("/foo", 5)
@@ -30,10 +31,20 @@
end
it "finds relative revision from 'HEAD'" do
- @repo.expects(:latest_revision).returns(70)
+ @repo.changesets.expects(:find).with(:first).returns(stub(:revision => 70))
find_revision_for(@node, "HEAD").should == 70
end
+ it "finds relative revision from 'PREV'" do
+ @repo.changesets.expects(:find_before).with(changeset_paths, @changeset).returns(stub(:revision => 70))
+ find_revision_for(@node, "PREV").should == 70
+ end
+
+ it "finds relative revision from 'NEXT'" do
+ @repo.changesets.expects(:find_after).with(changeset_paths, @changeset).returns(stub(:revision => 70))
+ find_revision_for(@node, "NEXT").should == 70
+ end
+
it "raises Silo::Node::Error on invalid relative revision" do
assert_raises Silo::Node::Error do
find_revision_for(@node, "FOO")
@@ -43,4 +54,8 @@
def current_repository
@repo
end
+
+ def changeset_paths
+ []
+ end
end
@@ -0,0 +1,199 @@
+$LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..', '..', 'vendor', 'grit', 'lib')
+require 'grit'
+
+module Silo
+ module Adapters
+ module Git
+ module NodeMethods
+ def dir?
+ grit_object.is_a?(Grit::Tree)
+ end
+
+ def file?
+ grit_object.is_a?(Grit::Blob)
+ end
+
+ def exists?
+ !grit_object.nil?
+ end
+
+ def latest?
+ (@latest ||= commit.committed_date >= latest_commit.committed_date || :false) != :false
+ end
+
+ def author
+ if committer = commit && commit.committer
+ committer.name
+ else
+ ''
+ end
+ end
+
+ def message
+ commit ? commit.message : ''
+ end
+
+ def changed_at
+ commit ? commit.committed_date.utc : nil
+ end
+
+ def content(&block)
+ return nil unless file?
+ if block
+ block.call(git_object.data)
+ else
+ grit_object.data
+ end
+ end
+
+ def added_directories
+ end
+
+ def added_files
+ end
+
+ def updated_directories
+ end
+
+ def updated_files
+ end
+
+ def copied_directories
+ end
+
+ def copied_files
+ end
+
+ def deleted_directories
+ end
+
+ def deleted_files
+ end
+
+ def commit
+ @commit ||= begin
+ @revision ? @commit = @repository.find_commit(@revision) : revision
+ @commit
+ end
+ end
+
+ def revision
+ @revision ||= begin
+ @latest = true
+ @commit = @repository.latest_commit_for(self)
+ @latest_revision = @commit ? @commit.id : nil
+ end
+ end
+
+ def latest_commit
+ @latest_commit ||= @repository.latest_commit_for(self)
+ end
+
+ def latest_revision
+ @latest_revision ||= revision_for latest_commit
+ end
+
+ def previous_node
+ @previous_node ||= begin
+ parent = commit.parents.first
+ parent ? @repository.node_at([@branch, @path] * "/", parent.id) : nil
+ end
+ end
+
+ def branch
+ @branch
+ end
+
+ def grit_object
+ @grit_object ||= (path.size.zero? ? head : head / path) || :none
+ @grit_object == :none ? nil : @grit_object
+ end
+
+ def head
+ @head ||= @revision ? @repository.find_commit(@revision).tree : @repository.tree(branch)
+ end
+
+ protected
+ def path=(value)
+ pieces = value.to_s.split("/")
+ while pieces.size > 0 && (@branch.nil? || @branch.size == 0)
+ @branch = pieces.shift
+ end
+ @paths = pieces
+ @path = pieces * "/"
+ end
+
+ def revision_for(commit)
+ @repository.revision_for(commit)
+ end
+ end
+
+ def latest_revision
+ backend && backend.commits.first.id
+ end
+
+ def commit_after(commit)
+ backend && backend.commits(commit.id, 1, 1).first
+ end
+
+ def revision?(rev)
+ rev =~ /^\w{40}$/ ? rev : nil
+ end
+
+ def blame_for(node)
+ return nil unless node.file?
+ blame = {:username_length => 0}
+ num = 0
+ Grit::Blob.blame(backend, node.revision, node.path).each do |(commit, lines)|
+ lines.each do |line|
+ num += 1
+ username = commit.committer.name
+ blame[num] = [commit.id, username]
+ blame[:username_length] = [blame[:username_length], username.length].max
+ end
+ end
+ blame
+ end
+
+ def child_node_names_for(node)
+ return [] unless node.branch.nil? || node.dir?
+ if node.branch.to_s.size.zero?
+ backend.heads
+ else
+ node.grit_object.contents
+ end.collect { |h| h.name }
+ end
+
+ def full_path_for(node)
+ File.join(@options[:path], node.path)
+ end
+
+ def find_commit(id)
+ backend.commit(id)
+ end
+
+ def latest_commit_for(node)
+ backend.log(node.branch, node.path, :max_count => 1).first
+ end
+
+ def revision_for(commit)
+ commit ? commit.id : nil
+ end
+
+ def unified_diff_for(old_rev, new_rev, diff_path)
+ Grit::Commit.diff(backend, old_rev, new_rev).collect do |d|
+ "diff --git a/#{d.a_path} b/#{d.b_path}\nindex #{d.a_commit.id_abbrev}..#{d.b_commit.id_abbrev}\n#{d.diff}"
+ end.join("\n")
+ end
+
+ def tree(*args)
+ backend && backend.tree(*args)
+ end
+
+ protected
+ def backend
+ @backend ||= @options[:path].to_s.size.zero? ? nil : Grit::Repo.new(@options[:path].to_s)
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit f02522c

Please sign in to comment.