-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6291b41
Showing
347 changed files
with
88,526 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
== Database | ||
|
||
Repository | ||
| id | ||
| name | ||
| path | ||
| slug | ||
| latest_revision | ||
| - Commit | ||
| commit_count | ||
| synced_revision | ||
| synced_revision_at | ||
| public | ||
|+description | ||
| | ||
Commit | ||
| id | ||
| sha1 | ||
| actor | ||
- User | ||
| name | ||
| message | ||
| revision | ||
| changed_at | ||
Change | ||
| id | ||
| path | ||
| from_path | ||
| from_revision | ||
| mode | ||
| diffable | ||
|
||
== Routes/Controllers | ||
browser => default for repo | ||
# blob => view file | ||
tree => view tree (tags/branches/tree sha1) => to browser | ||
commit => view commit (with branch)=> to browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
= Warehouse 2.0 | ||
|
||
Re-Written from the ground-up for use with Git. I imagined it a "local" version of GitHub for your repositories | ||
|
||
== Getting Started | ||
|
||
I'm working on this section :) | ||
|
||
== Contributing | ||
|
||
I'd love your help, or your bug reports :) | ||
|
||
== License | ||
|
||
Copyright (c) 2010 Alex Coomans | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | ||
|
||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
require 'tasks/rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Filters added to this controller apply to all controllers in the application. | ||
# Likewise, all the methods added will be available for all controllers. | ||
|
||
class ApplicationController < ActionController::Base | ||
helper :all # include all helpers, all the time | ||
protect_from_forgery # See ActionController::RequestForgeryProtection for details | ||
helper_method :current_repository, :current_commit | ||
|
||
# Scrub sensitive parameters from your log | ||
# filter_parameter_logging :password | ||
# expiring_attr_reader :current_repository, :retrieve_current_repository | ||
# expiring_attr_reader :current_commit, :retrieve_latest_revision | ||
|
||
protected | ||
|
||
def current_repository | ||
@repo = Repository.find_by_slug(repository_name) | ||
end | ||
|
||
def repository_name | ||
@repository_name ||= params.delete(:repo) | ||
end | ||
|
||
def current_commit | ||
@latest_commit ||= @revision ? current_repository.commits.find_by_tree(@revision) : current_repository.commits.first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class BrowserController < ApplicationController | ||
include Warehouse::RepositoryResources | ||
before_filter :find_node, :except => [:multi, :tag] | ||
before_filter :render_sync_required_unless_current_commit, :only => [:index, :blame] | ||
|
||
def index | ||
render :action => @node.node_type | ||
end | ||
|
||
alias blame index | ||
|
||
def text | ||
render :text => @node.data, :content_type => Mime::TEXT | ||
end | ||
|
||
def raw | ||
if content = @node.data | ||
send_data content, :disposition => 'inline', :content_type => @node.mime_type | ||
else | ||
head :not_found | ||
end | ||
end | ||
|
||
def hil | ||
render :action => 'hil', :layout => false | ||
end | ||
|
||
def multi | ||
end | ||
|
||
def history | ||
@changes = Change.paginate(:page => params[:page], :per_page => 15, :conditions => { :path => (params[:paths] * '/'), :commit_id => current_repository.commits.all(:conditions => { :branch => current_commit.branch }) }) | ||
end | ||
|
||
def tag | ||
r = current_repository.tags.detect { |t| t.name == params[:tag].to_s } | ||
@revision = r.commit.tree.id | ||
@node = current_repository.node('', @revision) | ||
params[:paths] = [] | ||
render :action => 'dir' | ||
end | ||
|
||
protected | ||
def render_sync_required_unless_current_commit | ||
render :action => 'sync_required' unless current_commit | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class CommitsController < ApplicationController | ||
before_filter :find_query, :except => :show | ||
def index | ||
end | ||
|
||
def show | ||
@commit = current_repository.commits.find_by_sha(params[:id]) | ||
end | ||
|
||
def search | ||
render :action => 'index' | ||
end | ||
|
||
protected | ||
def find_query | ||
if params[:q] && params[:tree] | ||
conds = ["message LIKE ? AND branch = ?", '%' + params[:q] + '%', params[:tree]] | ||
elsif params[:tree] | ||
conds = { :branch => params[:tree] } | ||
else | ||
conds = nil | ||
end | ||
@commits = current_repository.commits.paginate(:page => params[:page], :per_page => 15, :conditions => conds) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||
|
||
#### PATHS | ||
# returns a link to the commit passed for the current repository | ||
def commit_path_for_current(commit) | ||
commit_path(:id => commit.sha) | ||
end | ||
|
||
def repo_path_for_current(opt = {}) | ||
opt.merge!(:repo => current_repository) | ||
repo_path(opt) | ||
end | ||
|
||
def tree_path_for_current(tree) | ||
# tree_path(:repo => current_repository, :rev => tree) | ||
end | ||
|
||
def hosted_url(*args) | ||
repository, name = extract_repository_and_args(args) | ||
hosted_url_for repository, send("#{name}_path", *args) | ||
end | ||
|
||
def hosted_url_for(repository, *args) | ||
unless repository.is_a?(Repository) || repository.nil? | ||
args.unshift repository | ||
repository = nil | ||
end | ||
repository ||= current_repository | ||
returning url_for(*args) do |path| | ||
path.insert 0, "/#{repository.slug}" if repository | ||
end | ||
end | ||
|
||
def extract_repository_and_args(args) | ||
if args.first.is_a?(Symbol) | ||
[nil, args.shift] | ||
else | ||
[args.shift, args.shift] | ||
end | ||
end | ||
|
||
#### TABS | ||
|
||
@@selected_attribute = %( class="selected").freeze | ||
def class_for(options) | ||
@@selected_attribute if current_page?(options) | ||
end | ||
|
||
def selected_navigation?(navigation) | ||
@@selected_attribute if current_navigation?(navigation) | ||
end | ||
|
||
def current_navigation?(navigation) | ||
@current_navigation ||= \ | ||
if controller.controller_name == 'broswer' && controller.action_name == 'multi' | ||
:multi | ||
else | ||
case controller.controller_name | ||
when /browser|history/ then :browser | ||
when /commit/ then :activity | ||
else :admin | ||
end | ||
end | ||
@current_navigation == navigation | ||
end | ||
|
||
## SRC CODE | ||
def highlight_source_for_node(node) | ||
highlight(node.mime_type, node.data) | ||
end | ||
|
||
### USERS | ||
def avatar_for(commit) | ||
# img = '/images/app/icons/member.png' | ||
# img = user && user.avatar? ? user.avatar_path : '/images/app/icons/member.png' | ||
# tag('img', :src => img, :class => 'avatar', :alt => 'avatar') | ||
image_tag commit.gravatar_url(:default => root_url + 'images/app/icons/member.png'), :class => 'avatar', :alt => 'avatar' | ||
end | ||
|
||
### TIME | ||
@@default_jstime_format = "%d %b, %Y %I:%M %p" | ||
def jstime(time, format = nil) | ||
content_tag 'span', time.strftime(format || @@default_jstime_format), :class => 'time' unless time.nil? | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
module BrowserHelper | ||
def link_to_node(text, node, *args) | ||
options = args.last.is_a?(Hash) ? args.pop : {} | ||
link_to text, url_for_node(node, args.first), options | ||
end | ||
|
||
def url_for_node(node, rev = nil) | ||
paths = node.respond_to?(:paths) ? node.paths : node.to_s.split('/') | ||
rev = rev ? rev.to_s : params[:rev] | ||
rev ? tree_path(:paths => paths, :rev => rev) : repo_path_for_current(:paths => paths) | ||
end | ||
|
||
def link_to_text_for_node(node) | ||
text_path(:repo => current_repository, :paths => node.paths) | ||
end | ||
|
||
def link_to_raw_for_node(node) | ||
raw_path(:repo => current_repository, :paths => node.paths) | ||
end | ||
|
||
def link_to_blame(node) | ||
blame_path(:repo => current_repository, :paths => node.paths) | ||
end | ||
|
||
def link_to_history(node, tree = 'master') | ||
history_path(:repo => current_repository, :tree => tree, :paths => node.paths) | ||
end | ||
|
||
@@default_time = Time.utc(1970, 1, 1) | ||
def latest_revision_for_node(node) | ||
if c = Change.last(:conditions => ["path LIKE ? AND commit_id IN(?) ", node.path + '%', @repo.commits.all(:conditions => { :branch => current_commit.branch, :committed_date => @@default_time..current_commit.committed_date.utc }) ]) | ||
c.commit | ||
else | ||
Commit.new | ||
# b = node.latest_revision(current_commit.committed_date + 1.second) | ||
# Commit.new(:sha => b.id, :message => b.message, :name => b.committer.name, :email => b.committer.email, :branch => current_commit.branch, :tree => b.tree.id, :committed_date => b.date) | ||
end | ||
end | ||
|
||
def link_to_crumbs(path, rev = nil) | ||
pieces = path.split '/' | ||
name = pieces.pop | ||
home_link = %(<li#{' class="crumb-divide-last"' if pieces.size == 0 && !name.nil?}>#{link_to("~ @ " + current_commit.branch, (@revision ? tree_path(:rev => current_commit.tree) : repo_path_for_current))}</li>) | ||
# home_link = %(<li#{' class="crumb-divide-last"' if pieces.size == 0 && !name.nil?}>#{link_to '~', hosted_url(rev ? :rev_browser : :browser)}</li>) | ||
return home_link unless name | ||
prefix = '' | ||
crumbs = [] | ||
pieces.each_with_index do |piece, i| | ||
# crumbs << %(<li#{' class="crumb-divide-last"' if pieces.size == i+1}>#{link_to_node(piece, "#{prefix}#{piece}", rev)}</li>) | ||
crumbs << %(<li#{' class="crumb-divide-last"' if pieces.size == i+1}>#{link_to_node(piece, "#{prefix}#{piece}", rev)}</li>) | ||
prefix << piece << '/' | ||
end | ||
crumbs.unshift(home_link).join << %(<li id="current">#{name}</li>) | ||
end | ||
|
||
def css_class_for(node) | ||
node.dir? ? 'folder' : CSS_CLASSES[File.extname(node.name)] || 'file' | ||
end | ||
|
||
|
||
# Test with | ||
# require 'grit' | ||
# t = Repository.first.full_tree | ||
# include BrowserHelper | ||
# puts html_for_repo_tree(t) | ||
def html_for_repo_tree(tree, level = 0, path = '') | ||
html = [] | ||
level += 1 | ||
html << %(#{"\t" * level}<ul>\n) if level == 1 | ||
tree.each do |a| | ||
# case a.class | ||
# when String then html << %(<li>#{a}</li>) | ||
# when Hash then a.each { |k, v| html << %(<li>#{k}</li><ul>#{html_for_repo_tree(v)}</ul>) } | ||
# when Array then a.each { |b| html << %(<li>#{a}</li>) } | ||
# end | ||
if a.is_a?(String) | ||
html << %(#{tab_level(level)}<li class="file"><a href="#" path="#{path}/#{a}">#{a}</a></li>\n) | ||
elsif a.is_a?(Hash) | ||
a.each { |k, v| html << %(#{tab_level(level)}<li class="tree"><a href="#">#{k}</a></li>\n#{tab_level(level)}<ul #{ 'style="display:none;"' unless level == 0 }>\n#{html_for_repo_tree(v,level,path + "/" + k)}\n#{tab_level(level)}</ul>\n) } | ||
elsif a.is_a?(Array) | ||
a.each { |b| html << %(#{tab_level(level)}<li class="file"><a href="#" path="#{path}/#{a}">#{a}</a></li>\n) } | ||
end | ||
end | ||
html << %(#{"\t" * level}</ul>) if level == 1 | ||
html | ||
end | ||
|
||
def html_list_for_branches(branches, type) | ||
# html = [] | ||
# br = params[:branch] || params[:tree] | ||
# html << %(<ul>) | ||
# branches.each do |b| | ||
# if br == b.name | ||
# html << %(<li><strong>#{b.name} ✓</strong></li>) | ||
# else | ||
# link = case type | ||
# when :branch then | ||
# when :tag then '' | ||
# end | ||
# html << %(<li>#{link_to b.name, link }</li>) | ||
# end | ||
# end | ||
# html << %(</ul>) | ||
end | ||
|
||
# def current_revision | ||
# @current_revision ||= current_repository.latest_commit_for_branch(@revision) | ||
# end | ||
|
||
### BLAME | ||
def blame_for(node, revision) | ||
b = [] | ||
previous = nil | ||
blame = node.blame(revision) | ||
blame.lines.each do |line| | ||
b << %(<tr#{ ' class="start-line"' if !previous.nil? && previous != line.commit}>) | ||
b << %(<td nowrap=""><pre>#{link_to truncate(line.commit.sha, :length => 8, :omission => ''), commit_path_for_current(line.commit) unless previous == line.commit}</pre></td>) | ||
b << %(<td nowrap="" class="name"><pre>#{h(line.commit.committer.name) unless previous == line.commit }</pre></td>) | ||
b << %(<td nowrap="" class="time"><pre>#{line.commit.date.strftime('%Y-%m-%d') unless previous == line.commit}</pre></td>) | ||
b << %(<td nowrap=""><pre>#{truncate(line.commit.message, :length => 25) unless previous == line.commit}</pre></td>) | ||
b << %(<td nowrap="" class="lineno">#{line.lineno}</td>) | ||
b << %(<td nowrap="" class="src">#{highlight(node.mime_type, line.line, false)}</td>) | ||
b << %(</tr>) | ||
previous = line.commit | ||
end | ||
b | ||
end | ||
|
||
protected | ||
def tab_level(l) | ||
"\t" * l | ||
end | ||
end |
Oops, something went wrong.