Add quick access to diff of each commit in the history (#1555)
This commit is contained in:
@@ -506,6 +506,24 @@ module Precious
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get %r{
|
||||||
|
/commit/ # match any URL beginning with /show/
|
||||||
|
(\w+) # match the SHA1
|
||||||
|
}x do |version|
|
||||||
|
@version = version
|
||||||
|
wiki = wiki_new
|
||||||
|
begin
|
||||||
|
@commit = wiki.repo.commit(version)
|
||||||
|
parent = @commit.parent
|
||||||
|
parent_id = parent.nil? ? nil : parent.id
|
||||||
|
@diff = wiki.repo.diff(parent_id, version)
|
||||||
|
mustache :commit
|
||||||
|
rescue Gollum::Git::NoSuchShaFound
|
||||||
|
@message = "Invalid commit: #{@version}"
|
||||||
|
mustache :error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get '/search' do
|
get '/search' do
|
||||||
@query = params[:q]
|
@query = params[:q]
|
||||||
@name = @query
|
@name = @query
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<div id="wiki-wrapper" class="compare">
|
||||||
|
<div id="head">
|
||||||
|
<h1 class="py-4">{{message}}</h1>
|
||||||
|
{{author}} commited {{authored_date}}
|
||||||
|
<span class="px-2 float-right">commit <code>{{version}}</code></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="compare-content">
|
||||||
|
{{#files}}
|
||||||
|
<div class="Box data highlight my-3">
|
||||||
|
<div class="Box-header Box--condensed Box-header--gray">
|
||||||
|
<code>{{path}}</code>
|
||||||
|
</div>
|
||||||
|
<table>
|
||||||
|
{{#lines}}
|
||||||
|
<tr>
|
||||||
|
<td class="line_numbers">{{ldln}}</td>
|
||||||
|
<td class="line_numbers">{{rdln}}</td>
|
||||||
|
<td><div class="{{class}} pl-2">{{line}}</div></td>
|
||||||
|
</tr>
|
||||||
|
{{/lines}}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{{/files}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -18,7 +18,10 @@
|
|||||||
<span class="float-left col-2" id="user-icons">{{>author_template}}</span>
|
<span class="float-left col-2" id="user-icons">{{>author_template}}</span>
|
||||||
<span class="flex-auto col-1 text-gray-light">{{date}}</span>
|
<span class="flex-auto col-1 text-gray-light">{{date}}</span>
|
||||||
<span class="flex-auto col-5">{{message}}</span>
|
<span class="flex-auto col-5">{{message}}</span>
|
||||||
<span class="pl-4 float-right">[<a href="{{base_url}}/{{filename}}/{{id}}" title="View commit">{{id7}}</a>]</span>
|
<span class="pl-4 float-right">
|
||||||
|
<a href="{{href}}" class="btn btn-outline text-mono">{{id7}}</a>
|
||||||
|
<a href="{{href_page}}" title="Browse the page at this point in the history" class="btn btn-outline">{{#octicon}}code{{/octicon}}</a>
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{{/versions}}
|
{{/versions}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
<div id="wiki-history">
|
<div id="wiki-history">
|
||||||
|
|
||||||
<div class="Box flex-auto">
|
<ul class="Box flex-auto">
|
||||||
{{#versions}}
|
{{#versions}}
|
||||||
<div class="Box-row Box-row--hover-gray border-top d-flex flex-items-center">
|
<li class="Box-row Box-row--hover-gray border-top d-flex flex-items-center">
|
||||||
<span class="float-left col-2" id="user-icons">{{>author_template}}</span>
|
<span class="float-left col-2" id="user-icons">{{>author_template}}</span>
|
||||||
<span class="flex-auto col-1 text-gray-light">{{date}}</span>
|
<span class="flex-auto col-1 text-gray-light">{{date}}</span>
|
||||||
<span class="flex-auto col-7">{{message}}<br/>
|
<span class="flex-auto col-7">{{message}}<br/>
|
||||||
@@ -18,10 +18,12 @@
|
|||||||
<span class="flex-auto col-2">{{#renamed}}{{renamed}} -> {{/renamed}}<a href="{{link}}">{{file}}</a></span><br/>
|
<span class="flex-auto col-2">{{#renamed}}{{renamed}} -> {{/renamed}}<a href="{{link}}">{{file}}</a></span><br/>
|
||||||
{{/files}}
|
{{/files}}
|
||||||
</span>
|
</span>
|
||||||
<span class="pl-4 float-right">[{{id7}}]</span>
|
<span class="pl-4 float-right">
|
||||||
</div>
|
<a href="{{href}}" class="btn btn-outline text-mono">{{id7}}</a>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
{{/versions}}
|
{{/versions}}
|
||||||
</div>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
require_relative 'compare.rb'
|
||||||
|
|
||||||
|
module Precious
|
||||||
|
module Views
|
||||||
|
class Commit < Compare
|
||||||
|
|
||||||
|
attr_reader :version
|
||||||
|
|
||||||
|
def title
|
||||||
|
"Changes in #{@version[0..6]}: #{message}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def author
|
||||||
|
@commit.author.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def authored_date
|
||||||
|
@commit.authored_date
|
||||||
|
end
|
||||||
|
|
||||||
|
def message
|
||||||
|
@commit.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def files
|
||||||
|
files = @diff.split(%r{^diff --git a/.+ b/.+$}).reject(&:empty?)
|
||||||
|
files.map do |diff|
|
||||||
|
matched = diff.match(%r{(?<=^--- a/).+$})
|
||||||
|
matched = diff.match(%r{(?<=^\+\+\+ b/).+$}) if matched.nil?
|
||||||
|
{
|
||||||
|
path: matched[0],
|
||||||
|
lines: lines(diff)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -17,9 +17,9 @@ module Precious
|
|||||||
@versions[1][0..6]
|
@versions[1][0..6]
|
||||||
end
|
end
|
||||||
|
|
||||||
def lines
|
def lines(diff = @diff)
|
||||||
lines = []
|
lines = []
|
||||||
lines_to_parse = @diff.split("\n")[4..-1]
|
lines_to_parse = diff.split("\n")[4..-1]
|
||||||
# If the diff is of a rename, the diff header will be one line longer than normal because it will contain a line starting with '+++' to indicate the 'new' filename.
|
# If the diff is of a rename, the diff header will be one line longer than normal because it will contain a line starting with '+++' to indicate the 'new' filename.
|
||||||
# Make sure to skip that header line if it is present.
|
# Make sure to skip that header line if it is present.
|
||||||
lines_to_parse = lines_to_parse[1..-1] if lines_to_parse[0].start_with?('+++')
|
lines_to_parse = lines_to_parse[1..-1] if lines_to_parse[0].start_with?('+++')
|
||||||
@@ -28,7 +28,7 @@ module Precious
|
|||||||
:class => line_class(line),
|
:class => line_class(line),
|
||||||
:ldln => left_diff_line_number(line),
|
:ldln => left_diff_line_number(line),
|
||||||
:rdln => right_diff_line_number(line) }
|
:rdln => right_diff_line_number(line) }
|
||||||
end if @diff
|
end if diff
|
||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -17,15 +17,18 @@ module Precious
|
|||||||
i = @versions.size + 1
|
i = @versions.size + 1
|
||||||
@versions.map do |v|
|
@versions.map do |v|
|
||||||
i -= 1
|
i -= 1
|
||||||
|
filename = path_for_version(v.tracked_pathname)
|
||||||
{ :id => v.id,
|
{ :id => v.id,
|
||||||
:id7 => v.id[0..6],
|
:id7 => v.id[0..6],
|
||||||
|
:href => page_route("gollum/commit/#{v.id}"),
|
||||||
|
:href_page => page_route("#{filename}/#{v.id}"),
|
||||||
:num => i,
|
:num => i,
|
||||||
:selected => @page.version.id == v.id,
|
:selected => @page.version.id == v.id,
|
||||||
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
||||||
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
||||||
:date => v.authored_date.strftime("%B %d, %Y"),
|
:date => v.authored_date.strftime("%B %d, %Y"),
|
||||||
:user_icon => self.user_icon_code(v.author.email),
|
:user_icon => self.user_icon_code(v.author.email),
|
||||||
:filename => path_for_version(v.tracked_pathname),
|
:filename => filename,
|
||||||
:date_full => v.authored_date,
|
:date_full => v.authored_date,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ module Precious
|
|||||||
i -= 1
|
i -= 1
|
||||||
{ :id => v.id,
|
{ :id => v.id,
|
||||||
:id7 => v.id[0..6],
|
:id7 => v.id[0..6],
|
||||||
|
:href => page_route("gollum/commit/#{v.id}"),
|
||||||
:num => i,
|
:num => i,
|
||||||
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
||||||
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
||||||
|
|||||||
Reference in New Issue
Block a user