Commit 53c9815e71b5df7861d28555c848a1764d968312

Merge branch 'master' of git://gitorious.org/gitorious/mainline

Conflicts:

db/schema.rb

Commit diff

app/controllers/browse_controller.rb

 
55 LOGS_PER_PAGE = 30
66
77 def index
8 @git = Git.bare(@repository.full_repository_path)
8 @git = Gitorious::Gitto.new(@repository.full_repository_path)
99 @commits = @git.log(LOGS_PER_PAGE)
10 @tags_per_sha = returning({}) do |hash|
11 @git.tags.each do |tag|
12 hash[tag.sha] ||= []
13 hash[tag.sha] << tag.name
14 end
15 end
10 @tags_per_sha = @git.tags_by_sha
1611 # TODO: Patch rails to keep track of what it responds to so we can DRY this up
1712 @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
1813 respond_to do |format|
1717 end
1818
1919 def tree
20 @git = Git.bare(@repository.full_repository_path)
21 @tree = @git.gtree(params[:sha])
20 @git = Gitorious::Gitto.new(@repository.full_repository_path)
21 @tree = @git.tree(params[:sha])
2222 end
2323
2424 def commit
2525 @diffmode = params[:diffmode] == "sidebyside" ? "sidebyside" : "inline"
26 @git = Git.bare(@repository.full_repository_path)
27 @commit = @git.gcommit(params[:sha])
26 @git = Gitorious::Gitto.new(@repository.full_repository_path)
27 @commit = @git.commit(params[:sha])
2828 if @commit.parent
2929 @diff = @git.diff(@commit.parent.sha || "", @commit.sha)
3030 else
31 # initial commit
32 @diff = @commit.diff("") # fIXME: diffs are the wrong way
31 # initial commit, link to the initial tree instead
32 @diff = nil
3333 end
3434 @comment_count = @repository.comments.count(:all, :conditions => {:sha1 => @commit.sha})
3535 end
3636
3737 def diff
38 @git = Git.bare(@repository.full_repository_path)
38 @git = Gitorious::Gitto.new(@repository.full_repository_path)
3939 @diff = @git.diff(params[:sha], params[:other_sha])
4040 end
4141
4242 def blob
43 @git = Git.bare(@repository.full_repository_path)
44 @blob = @git.gblob(params[:sha])
43 @git = Gitorious::Gitto.new(@repository.full_repository_path)
44 @blob = @git.blob(params[:sha])
4545 end
4646
4747 def raw
48 @git = Git.bare(@repository.full_repository_path)
49 @blob = @git.gblob(params[:sha])
48 @git = Gitorious::Gitto.new(@repository.full_repository_path)
49 @blob = @git.blob(params[:sha])
5050 render :text => @blob.contents, :content_type => "text/plain"
5151 end
5252
5353 def log
54 @git = Git.bare(@repository.full_repository_path)
54 @git = Gitorious::Gitto.new(@repository.full_repository_path)
5555 skip = params[:page].blank? ? 0 : (params[:page].to_i-1) * LOGS_PER_PAGE
5656 @commits = @git.log(LOGS_PER_PAGE, skip)
57 @tags_per_sha = returning({}) do |hash|
58 @git.tags.each do |tag|
59 hash[tag.sha] ||= []
60 hash[tag.sha] << tag.name
61 end
62 end
57 @tags_per_sha = @git.tags_by_sha
6358 # TODO: Patch rails to keep track of what it responds to so we can DRY this up
6459 @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
6560 respond_to do |format|
toggle raw diff

app/controllers/comments_controller.rb

 
2525 def create
2626 @comment = @repository.comments.new(params[:comment])
2727 @comment.user = current_user
28 @comment.project = @project
2829 respond_to do |format|
2930 if @comment.save
3031 format.html do
toggle raw diff

app/controllers/site_controller.rb

 
11class SiteController < ApplicationController
2 before_filter :login_required, :only => [:dashboard]
23
34 def index
45 @tags = Project.tag_counts
6 @projects = Project.find(:all, :limit => 5, :order => "id desc")
7 end
8
9 def dashboard
10 @projects = current_user.projects
11 project_ids = @projects.map(&:id)
12 @recent_comments = Comment.find(:all, :limit => 10,
13 :conditions => ["comments.project_id in (?)", project_ids],
14 :order => "comments.created_at desc", :include => [:user, :repository])
15 @repository_clones = @projects.map(&:repository_clones).flatten
16 # @repository_clones = Repository.find(:all,
17 # :conditions => ["project_id in (?) and mainline = ?", project_ids, false])
518 end
619
720 def about
821 end
922
23 def faq
24 end
25
1026end
toggle raw diff

app/controllers/users_controller.rb

 
2727 current_user.activate
2828 flash[:notice] = "Your account has been activated, welcome!"
2929 end
30 else
31 flash[:error] = "Invalid activation code"
3032 end
3133 redirect_back_or_default('/')
3234 end
toggle raw diff

app/helpers/browse_helper.rb

 
9999 end
100100
101101 def render_diffmode_selector
102 out = %Q{<ul class="diffmode_selector">}
102 out = %Q{<ul class="mode_selector">}
103103 out << %Q{<li class="list_header">Diff rendering mode:</li>}
104104 if @diffmode == "sidebyside"
105105 out << %Q{<li><a href="?diffmode=inline">inline</a></li>}
112112 out
113113 end
114114
115 def with_line_numbers(&block)
116 out = []
117 #yield.split("\n").each_with_index{ |s,i| out << "#{i+1}: #{s}" }
118 out << %Q{<table id="codeblob">}
119 yield.to_s.split("\n").each_with_index do |line, count|
120 lineno = count + 1
121 out << %Q{<tr id="line#{lineno}">}
122 out << %Q{<td class="line-numbers"><a href="#line#{lineno}" name="line#{lineno}">#{lineno}</a></td>}
123 out << %Q{<td class="code">#{line}</td>}
124 out << "</tr>"
125 end
126 out << "</table>"
127 out.join("\n")
128
129 end
130
115131end
toggle raw diff

app/models/comment.rb

 
1414class Comment < ActiveRecord::Base
1515 belongs_to :user
1616 belongs_to :repository
17 belongs_to :project
1718
1819 attr_protected :user_id
1920
20 validates_presence_of :user_id, :repository_id, :body
21 validates_presence_of :user_id, :repository_id, :body, :project_id
2122
2223
2324end
toggle raw diff

app/models/project.rb

 
1919 acts_as_taggable
2020
2121 belongs_to :user
22 has_many :comments
2223 has_many :repositories, :order => "mainline desc, created_at asc",
2324 :dependent => :destroy
2425 has_one :mainline_repository, :conditions => ["mainline = ?", true],
2526 :class_name => "Repository"
26 has_many :branch_repositories, :conditions => ["mainline = ?", false],
27 has_many :repository_clones, :conditions => ["mainline = ?", false],
2728 :class_name => "Repository"
2829
2930 URL_FORMAT_RE = /^(http|https|nntp):\/\//.freeze
toggle raw diff

app/models/repository.rb

 
9696 end
9797 end
9898
99 def last_commit
100 if has_commits?
101 @last_commit ||= Git.bare(full_repository_path).log(1).first
102 end
103 @last_commit
104 end
105
99106 def create_new_repos_task
100107 Task.create!(:target_class => self.class.name,
101108 :command => parent ? "clone_git_repository" : "create_git_repository",
toggle raw diff

app/models/ssh_key.rb

 
1313class SshKey < ActiveRecord::Base
1414 belongs_to :user
1515
16 SSH_KEY_FORMAT = /^ssh\-[a-z0-9]{3,4} [a-z0-9\+=\n\/]+ [a-z0-9_\.\-]*(@[a-z0-9\.\-]*)?$/ims
16 SSH_KEY_FORMAT = /^ssh\-[a-z0-9]{3,4} [a-z0-9\+=\/]+ [a-z0-9_\.\-]*(@[a-z0-9\.\-]*)?$/ims
1717
1818 validates_presence_of :user_id, :key
1919 validates_format_of :key, :with => SSH_KEY_FORMAT
2020
2121 before_validation { |k| k.key.to_s.strip! }
22 before_save :lint_key!
22 before_validation :lint_key!
2323 after_create :create_new_task
2424 # we only allow people to create/destroy keys after_update :create_update_task
2525 after_destroy :create_delete_task
3232 %Q{### START KEY #{self.id || "nil"} ###\n} +
3333 %Q{command="gitorious #{user.login}",no-port-forwarding,} +
3434 %Q{no-X11-forwarding,no-agent-forwarding,no-pty #{key}} +
35 %Q{\n### END KEY #{self.id || "nil"} ###}
35 %Q{\n### END KEY #{self.id || "nil"} ###\n}
3636 end
3737
3838 def self.add_to_authorized_keys(keydata, key_file_class=SshKeyFile)
5959
6060 protected
6161 def lint_key!
62 key.gsub!(/\n*/m, "")
62 self.key.gsub!(/(\r|\n)*/m, "")
6363 end
6464end
toggle raw diff

app/models/user.rb

 
3333 attr_protected :login
3434
3535 validates_presence_of :login, :email
36 validates_format_of :login, :with => /^[a-z0-9\-_\.]+$/i
37 validates_format_of :email, :with => /^[^@\s]+@([\-a-z0-9]+\.)+[a-z]{2,}$/i
3638 validates_presence_of :password, :if => :password_required?
3739 validates_presence_of :password_confirmation, :if => :password_required?
3840 validates_length_of :password, :within => 4..40, :if => :password_required?
toggle raw diff

app/views/browse/blob.html.erb

 
11<% @page_title = "#{current_path.join("/")} - #{@repository.name} in #{@project.title}" -%>
2
3<ul class="mode_selector">
4 <li class="list_header">
5 Softwrap mode:
6 </li>
7 <li>
8 <%= link_to_function "Toggle", "Gitorious.Wordwrapper.toggle($$('table#codeblob td.code'))" -%>
9 </li>
10</ul>
11
212<h1>
313 Blob of <code><%= current_path.join("/") -%></code>
414 <small>(<%= link_to "raw blob data", raw_blob_path(@blob.sha, current_path) -%>)</small>
515</h1>
6<pre><%=h @blob.contents -%></pre>
16
17<pre><%= with_line_numbers{ h(@blob.contents) } -%></pre>
718
819<%= render :partial => "submenu" -%>
toggle raw diff

app/views/browse/commit.html.erb

 
1414
1515<% #TODO: commit diff stats (as sparklines?) -%>
1616
17<h2>Commit diff</h2>
18<%= render_diffmode_selector -%>
19
20<% @diff.each do |file| -%>
21 <h4><%= h(file.path) -%><%#=link_to h(file.path), blob_path(file.sha, file.path) -%></h4>
22 <%= render_diff(file.patch, file.src, file.dst, @diffmode) -%>
23 <small><%= link_to_function "toggle raw diff", "$('#{file.object_id}').toggle()" -%></small>
24 <div class="toggle_diff" style="display:none" id="<%= file.object_id -%>">
25 <p><pre><%= h(file.patch) -%></pre></p>
26 </div>
17<% if @diff.blank? -%>
18 <p>
19 This is the initial commit in this repository,
20 <%= link_to "browse the initial tree state", tree_path(@commit.gtree.sha) -%>.
21 </p>
22<% else -%>
23 <h2>Commit diff</h2>
24 <%= render_diffmode_selector -%>
25
26 <% @diff.each do |file| -%>
27 <h4><%= h(file.path) -%><%#=link_to h(file.path), blob_path(file.sha, file.path) -%></h4>
28 <%= render_diff(file.patch, file.src, file.dst, @diffmode) -%>
29 <small><%= link_to_function "toggle raw diff", "$('#{file.object_id}').toggle()" -%></small>
30 <div class="toggle_diff" style="display:none" id="<%= file.object_id -%>">
31 <p><pre><%= h(file.patch) -%></pre></p>
32 </div>
33 <% end -%>
2734<% end -%>
2835
2936<%= render :partial => "submenu" -%>
toggle raw diff

app/views/browse/index.atom.builder

 
11atom_feed do |feed|
22 feed.title("Gitorious: #{@project.title} - #{@repository.name}")
3 feed.updated((@commits.first.date))
3 feed.updated((@commits.blank? ? nil : @commits.first.date))
44
55 @commits.each do |commit|
66 item_url = "http://gitorious.org" + project_repository_commit_path(@project, @repository, commit.sha)
toggle raw diff

app/views/layouts/application.html.erb

 
1313 <%= GitoriousConfig["extra_html_head_data"] -%>
1414</head>
1515
16<body>
16<body id="<%= controller.controller_name -%>">
1717 <div id="container">
1818 <div id="header">
1919 <div class="login-logout">
3434 <div id="menu">
3535 <ul>
3636 <li><%= link_to "Home", root_path -%></li>
37 <% if logged_in? -%>
38 <li><%= link_to "Dashboard", dashboard_path -%></li>
39 <% end -%>
3740 <li><%= link_to "Projects", projects_path -%></li>
41 <% if logged_in? -%>
42 <li><%= link_to "FAQ", faq_path -%></li>
43 <% else -%>
3844 <li><%= link_to "About", about_path -%></li>
45 <% end -%>
3946 </ul>
4047 </div>
4148 <div id="submenu">
7676 <ul>
7777 <li><%= link_to "Home", root_path -%> | </li>
7878 <li><%= link_to "About", about_path -%> | </li>
79 <li><%= link_to "FAQ", faq_path -%> | </li>
7980 <li><%= link_to "Discussion group", "http://groups.google.com/group/gitorious" -%></li>
8081 </ul>
8182 </div>
toggle raw diff

app/views/projects/index.html.erb

 
44<% @projects.each do |project| -%>
55 <li>
66 <h3><%= link_to project.title, project_path(project) -%></h3>
7 <em><%= truncate project.description, 100 -%></em>
7 <em><%= truncate project.description, 250 -%></em>
88 </li>
99<% end -%>
1010</ul>
toggle raw diff

app/views/projects/show.html.erb

 
44
55<ul class="infobox">
66 <li><strong>Owner:</strong> <%= link_to h(@project.user.login), user_path(@project.user) -%></li>
7 <li><strong>Created:</strong> <%= @project.created_at.to_s(:short) -%></li>
78 <li><strong>Labels:</strong>
89 <%= @project.tag_list.blank? ? "none" : linked_tag_list_as_sentence(@project.tags) -%></li>
910 <li><strong>License:</strong> <%= h(@project.license) -%></li>
2727 <thead>
2828 <th>Name</th>
2929 <th>Owner</th>
30 <th>Created</th>
30 <th>Last Commit</th>
3131 <th></th>
3232 </thead>
3333 <% @repositories.each do |repos| # fixme: need to graph the parent relation proper -%>
4040 <%= h(@project.slug) -%> (<%= link_to h(repos.user.login), user_path(repos.user) -%>)
4141 </td>
4242 <td>
43 <%= repos.created_at.to_s(:short) -%>
43 <%= repos.last_commit ? repos.last_commit.author.date.to_s(:short) : "<em>none</em>" -%>
4444 </td>
4545 <td><%= link_to "browse", project_repository_browse_path(@project, repos) -%></td>
4646 </tr>
5353 <%= link_to h(repos.user.login), user_path(repos.user) -%>
5454 </td>
5555 <td>
56 <%= repos.created_at.to_s(:short) -%>
56 <%= repos.last_commit ? repos.last_commit.author.date.to_s(:short) : "<em>none</em>" -%>
5757 </td>
5858 <td><%= link_to "browse", project_repository_browse_path(@project, repos) -%></td>
5959 </tr>
toggle raw diff

app/views/repositories/_infobox.html.erb

 
66 <%= link_to h(@repository.parent.gitdir), project_repository_path(@project, @repository.parent) -%>
77 <% end -%>
88 <li><strong>Created:</strong> <%= @repository.created_at.to_s(:short) -%></li>
9 <li><strong>Mirror url:</strong> <code><%=h @repository.clone_url -%></code></li>
9 <li>
10 <strong>Clone url:</strong> <code><%=h @repository.clone_url -%></code>
11 <small><%= link_to_function "More info…", "$('detailed_clone_info').toggle()" -%></small>
12 <div id="detailed_clone_info" class="info_hint" style="display:none">
13 You can clone this repository with the following command:
14 <% if logged_in? && current_user.can_write_to?(@repository) -%>
15 <code>git clone <%= @repository.push_url -%></code>
16 <% else -%>
17 <code>git clone <%= @repository.clone_url -%></code>
18 <% end -%>
19 </div>
20 </li>
1021 <% if logged_in? && current_user.can_write_to?(@repository) -%>
11 <li><strong>push url:</strong> <code><%=h @repository.push_url -%></code></li>
22 <li>
23 <strong>Push url:</strong> <code><%=h @repository.push_url -%></code>
24 <small><%= link_to_function "More info…", "$('detailed_push_info').toggle()" -%></small>
25 <div id="detailed_push_info" class="info_hint" style="display:none">
26You can run "<code>git push git@gitorious.org:tumbline/mainline.git</code>", or
27you can setup a remote by doing the following:
28<pre>
29git remote add origin <%= @repository.push_url %>
30# to push the master branch to the origin remote we added above:
31git push origin master
32# after that you can just do:
33git push
34</pre>
35 </div>
36 </li>
1237 <% end -%>
1338</ul>
toggle raw diff

app/views/repositories/show.html.erb

 
77<% render_if_ready(@repository) do -%>
88
99 <%= render :partial => "infobox" -%>
10
11 <p>You can clone this repository with the following command:</p>
12 <% if logged_in? && current_user.can_write_to?(@repository) -%>
13 <pre>git clone <%= @repository.push_url -%></pre>
14 <% else -%>
15 <pre>git clone <%= @repository.clone_url -%></pre>
16 <% end -%>
1710
1811 <ul class="tab_menu">
1912 <li class="selected">Recent commits</li>
2013 <li><%= link_to "comments (#{@comment_count})", project_repository_comments_path(@project, @repository) -%></li>
2114 </ul>
2215
23 <h2>Recent commits <small>(<%= link_to "browse", project_repository_browse_path(@project, @repository) -%>)</small></h2>
16 <h2>
17 Recent commits
18 <small>
19 (<%= link_to "Shortlog", project_repository_browse_path(@project, @repository) -%> |
20 <%= link_to "HEAD tree", project_repository_tree_path(@project, @repository, "HEAD", []) -%>)
21 </small>
22 </h2>
2423 <ul>
2524 <% if @commits.blank? -%>
2625 <li><em>No commits yet…</em></li>
toggle raw diff

app/views/site/about.html.erb

 
4646 If you experience any technical issues feel free to
4747 <a href="mailto:johan@johansorensen.com">send an email</a>, there's also the
4848 <a href="http://groups.google.com/group/gitorious">discussion group</a> for more
49 general Gitorious discussions around Gitorious.
50 </p>
51</div>
52
53<div class="section">
54 <a name="faq"></a><h1>FAQ</h1>
55
56 <h3>How do I point my local Git repository at Gitorious?</h3>
57 <p>
58 Easiest way is to put something like the following in your <code>.git/config</code>
59 file of the repository you wish to push:
60 <pre>
61 [remote "origin"]
62 url = git@gitorious.org:<em>project</em>/<em>repository.git</em>
63 fetch = +refs/heads/*:refs/remotes/origin/*
64 [branch "master"]
65 remote = origin
66 merge = refs/heads/master
67 </pre>
68 and then <code>git push origin master</code> to push the code to Gitorious.
69 </p>
70
71 <hr />
72
73 <h3>Why is my email displayed?</h3>
74 <p>
75 The email you used to signup with Gitorious is displayed to other users, so that they
76 can contact you about your projects if they need to. We do however take light
77 measures against crawlers by not displaying your email in completely plain text. <br />
78 But just to be clear: we won't sell or use any information you give to
79 gitorious.org against you or anyone else for financial and/or personal gains.
80 </p>
81
82 <hr />
83
84 <h3>Why do I need to upload my public SSH key?</h3>
85 <p>
86 When you push to a Git repository, your public key is how we authenticate
87 you and if have the permissions required to do a commit to a given repository
49 general Gitorious discussions around Gitorious. There's also the
50 <a href="irc://irc.freenode.net/gitorious"><code>#gitorious</code></a> IRC
51 channel on FreeNode.
8852 </p>
8953</div>
9054
5656 <ul class="links">
5757 <li><a href="#about">About</a></li>
5858 <li><a href="#contact">Contact</a></li>
59 <li><a href="#faq">FAQ</a></li>
59 <li><%= link_to "FAQ", faq_path -%></li>
6060 </ul>
6161<% end -%>
toggle raw diff

app/views/site/dashboard.html.erb

 
1<% @page_title = "#{current_user.login}'s dashboard" -%>
2
3<div id="recent_comments">
4 <h2>Recent comments on your commits</h2>
5 <% @recent_comments.each do |comment| -%>
6 <div class="comment">
7 <p class="body"><%= sanitize(comment.body) -%></p>
8 <p class="byline hint">
9 on <%= link_to h(comment.repository.name), project_repository_comments_path(comment.project, comment.repository, :anchor => dom_id(comment)) -%>
10 <% unless comment.sha1.blank? -%>
11 (<%= link_to h(comment.sha1[0..6]), project_repository_commit_path(comment.project, comment.repository, comment.sha1) -%>)
12 <% end -%>
13 in <%= link_to h(comment.project.title), comment.project -%> by
14 <%= link_to(h(comment.user.login), comment.user) -%>
15 <%= time_ago_in_words(comment.created_at) -%> ago
16 </p>
17 </div>
18 <% end -%>
19 <% if @recent_comments.blank? -%>
20 <p class="hint">Sorry, no comments yet</p>
21 <% end -%>
22</div>
23