diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 707e87fd1..7655f1eb4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -34,7 +34,7 @@ class RepositoriesController < ApplicationController before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -521,6 +521,13 @@ update end end + # 每次提交对应的文件差异 + def commit_diff + @commit_diff = $g.commit_diff(@project.gpid, params[:changeset]) + @commit_details = $g.commit(@project.gpid, params[:changeset]) + render :layout => 'base_projects' + end + def diff if params[:format] == 'diff' @diff = @repository.diff(@path, @rev, @rev_to) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ff4aa61fb..36187b460 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -41,6 +41,16 @@ module RepositoriesHelper identifiers.include?(iden) ? false :true end + # 获取diff内容行号 + def diff_line_num content + content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i + end + + # 处理内容 + def diff_content content + content.gsub!(/.*@@ -\d+,\d+ \+\d+,\d+ @@\n/m,'') + end + def format_revision(revision) if revision.respond_to? :format_identifier revision.format_identifier diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ea9ad2cc0..588ee144d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -643,8 +643,8 @@ class Attachment < ActiveRecord::Base def decrease_attchments_count if self.container_type == "Project" && !self.project.project_score.nil? - aatach_count = self.container.project_score.attach_num - 1 - self.container.project_score.update_attribute(:attach_num, aatach_count) + attach_count = self.container.project_score.attach_num - 1 + self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count) end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index e1de4cd9e..c82f6f0be 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -184,7 +184,7 @@ class Issue < ActiveRecord::Base def decrease_issues_count unless self.project.project_score.nil? issue_count = self.project.project_score.issue_num - 1 - self.project.project_score.update_attribute(:issue_num, issue_count) + self.project.project_score.update_attribute(:issue_num, issue_count < 0 ? 0 : issue_count) end end diff --git a/app/models/journal.rb b/app/models/journal.rb index b184c82e6..c37b8d2c5 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -219,8 +219,9 @@ class Journal < ActiveRecord::Base # 减少留言数量统计 def decrease_issues_journal_count unless self.issue.project.nil? - project = self.issue.project - project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num - 1) + journal_count = self.issue.project.project_score.issue_journal_num - 1 + # project = self.issue.project + self.issue.project.project_score.update_attribute(:issue_journal_num, journal_count < 0 ? 0 : journal_count) end end diff --git a/app/models/message.rb b/app/models/message.rb index 675d37790..6381f444f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -146,10 +146,10 @@ class Message < ActiveRecord::Base # 讨论区 if self.parent_id.nil? count = self.project.project_score.board_num - 1 - self.project.project_score.update_attribute(:board_num, count) + self.project.project_score.update_attribute(:board_num, count < 0 ? 0 : count) else # 回复 count = self.project.project_score.board_message_num - 1 - self.project.project_score.update_attribute(:board_message_num, count) + self.project.project_score.update_attribute(:board_message_num, count < 0 ? 0 : count) end end end diff --git a/app/models/news.rb b/app/models/news.rb index fee5d2801..d0fccae17 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -126,7 +126,7 @@ class News < ActiveRecord::Base def decrease_news_count if self.project && !self.project.project_score.nil? count = self.project.project_score.news_num - 1 - self.project.project_score.update_attribute(:news_num, count) + self.project.project_score.update_attribute(:news_num, count < 0 ? 0 : count) end end diff --git a/app/views/common/_file.html.erb b/app/views/common/_file.html.erb index 97443beea..486c760f1 100644 --- a/app/views/common/_file.html.erb +++ b/app/views/common/_file.html.erb @@ -8,7 +8,7 @@ <%= line_num %> -
<%= line.html_safe %>
+
<%= line.html_safe %>
<% line_num += 1 %> diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 657873f8b..33c792aaf 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -12,7 +12,7 @@ <%= favicon %> <%= javascript_heads %> <%= heads_for_theme %> - <%= stylesheet_link_tag 'header','public', 'pleft', 'project','prettify','jquery/jquery-ui-1.9.2','repository','share' %> + <%= stylesheet_link_tag 'header','scm','public', 'pleft', 'project','prettify','jquery/jquery-ui-1.9.2','repository','share' %> <%= javascript_include_tag 'cookie','project', 'header','prettify','select_list_move','attachments' %> <%= call_hook :view_layouts_base_html_head %> diff --git a/app/views/repositories/_commit_details.html.erb b/app/views/repositories/_commit_details.html.erb new file mode 100644 index 000000000..ef8faecd7 --- /dev/null +++ b/app/views/repositories/_commit_details.html.erb @@ -0,0 +1,15 @@ +
+ <% if !user_commit_rep(changeset.author_email).nil? %> + + <%= image_tag(url_to_avatar(user_commit_rep(changeset.author_email)), :width => "20", :height => "20", :class => "fl portraitRadius mt2 ml4 mr5") %> + <%= link_to user_commit_rep(changeset.author_email), user_path(user_commit_rep(changeset.author_email)), :length => 30 %>提交于 +
+   +
+ <% else %> + <%= changeset.author_email %>提交于 +
+   +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/repositories/_dir_list_content.html.erb b/app/views/repositories/_dir_list_content.html.erb index 81706c25e..dda0cddbd 100644 --- a/app/views/repositories/_dir_list_content.html.erb +++ b/app/views/repositories/_dir_list_content.html.erb @@ -24,10 +24,10 @@ <% if @repository.report_last_commit %> -<%= link_to_revision(entry.changeset, @repository) if entry.changeset %> -<%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %> -<%= entry.author %> -<%=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %> + <%= link_to_revision(entry.changeset, @repository) if entry.changeset %> + <%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %> + <%= entry.author %> + <%=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %> <% end %> <% end %> diff --git a/app/views/repositories/_revisions.html.erb b/app/views/repositories/_revisions.html.erb index 4d6e39f88..a27789dc1 100644 --- a/app/views/repositories/_revisions.html.erb +++ b/app/views/repositories/_revisions.html.erb @@ -20,27 +20,13 @@
+
<%= @commit_details.message %>
+ + + + + + + + +<% @commit_diff.each do |cd| %> +
+ + <%= cd.new_path %> + +
+
+ + + <% line_num = diff_line_num(cd.diff) %> + <% diff_content = diff_content(cd.diff) %> + <% syntax_highlight_lines(cd.new_path, Redmine::CodesetUtil.to_utf8_by_setting(diff_content)).each do |line| %> + + + <% if line[0,1] == "-" %> + + <% elsif line[0,1] == "+" %> + + <% else%> + + <% end %> + + <% line_num += 1 %> + <% end %> + +
+ <%= line_num %> +
<%= line.html_safe %>
<%= line.html_safe %>
<%= line.html_safe %>
+
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7060e4eb6..310fe29dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -831,7 +831,7 @@ RedmineApp::Application.routes.draw do :controller => 'repositories', :format => false, :constraints => { - :action => /(browse|show|entry|raw|annotate|diff)/, + :action => /(browse|show|entry|raw|annotate|diff|commit_diff)/, :rev => /[a-z0-9\.\-_]+/ } @@ -850,15 +850,15 @@ RedmineApp::Application.routes.draw do :controller => 'repositories', :format => false, :constraints => { - :action => /(browse|show|entry|raw|annotate|diff)/, + :action => /(browse|show|entry|raw|annotate|diff|commit_diff)/, :rev => /[a-z0-9\.\-_]+/ } get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', :controller => 'repositories', - :action => /(browse|show|entry|raw|changes|annotate|diff)/ + :action => /(browse|show|entry|raw|changes|annotate|diff|commit_diff)/ get 'projects/:id/repository/:action(/*path(.:ext))', :controller => 'repositories', - :action => /(browse|show|entry|raw|changes|annotate|diff)/ + :action => /(browse|show|entry|raw|changes|annotate|diff|commit_diff)/ get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil get 'projects/:id/repository', :to => 'repositories#show', :path => nil diff --git a/public/images/vlicon/file.png b/public/images/vlicon/file.png new file mode 100644 index 000000000..bbfa6078d Binary files /dev/null and b/public/images/vlicon/file.png differ diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 11c01aa09..1a231b8a0 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -694,7 +694,7 @@ p.other-formats { text-align: right; font-size:0.9em; color: #666; } /*pre标签换行*/ .break_word{word-break: break-all;word-wrap: break-word;} -.break_word_firefox{white-space: pre-wrap;word-break: break-all;} +.break_word_firefox{white-space: pre-wrap !important;word-break: break-all;} /*问题跟踪attachment显示*/ div.attachments { margin-top: 12px; } @@ -896,9 +896,9 @@ a:hover.Reply_pic{border:1px solid #64bdd9;} /*end*/ /***** Diff *****/ .diff_out { background: #fcc; } -.diff_out span { background: #faa; } +/*.diff_out span { background: #faa; }*/ .diff_in { background: #cfc; } -.diff_in span { background: #afa; } +/*.diff_in span { background: #afa; }*/ .text-diff { padding: 1em; @@ -1169,3 +1169,18 @@ div.disable_link {background-color: #c1c1c1 !important;} .proInfoBox2{ border:1px solid #dddddd; height:45px; padding:10px 0; background-color:#f1f1f1;} .proInfoBox2 ul li{ height:24px; position:relative;} .maxwidth150{max-width: 150px;} + +/*版本库diff*/ +.showing-changes-info {width:650px; padding:10px; background-color:#ffffff; line-height:2;} +.showing-changes-project {width:650px; padding:10px; border-top:1px solid #dce0e6; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} +.showing-changes-row {width:650px; padding:10px; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} +#changed-files-detail {display:none;} +#changed-files-detail li {list-style-type:disc; margin-left:15px;} +.showing-changes-detail {width:670px; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} +.changes-detail-chart {width:100%; overflow:auto; border-collapse:collapse; margin:0px; padding:0px; background-color:#f1f1f1;} +.diff-line-number {width:35px; min-width:35px; max-width:50px; border-right:1px solid #c1c1c1; padding:0px 5px; text-align:right; background-color:#f1f1f1;} +.code-line-old {background-color:#ffecec;} +.number-line-old {background-color:#ffdddd; border-color:#f1c0c0;} +.code-line-new {background-color:#eaffea;} +.number-line-new {background-color:#dbffdb; border-color:#c1e9c1;} +.branch-label {padding-right: 5px; border-radius:2px; color:#888888; display:inline-block; background-color:#f8fafc;} \ No newline at end of file