diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb
index cd7b21a3..b703e163 100644
--- a/lib/gollum/app.rb
+++ b/lib/gollum/app.rb
@@ -506,6 +506,24 @@ module Precious
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
@query = params[:q]
@name = @query
diff --git a/lib/gollum/templates/commit.mustache b/lib/gollum/templates/commit.mustache
new file mode 100644
index 00000000..8e4d2379
--- /dev/null
+++ b/lib/gollum/templates/commit.mustache
@@ -0,0 +1,26 @@
+
+
+
{{message}}
+ {{author}} commited {{authored_date}}
+ commit {{version}}
+
+
+
+ {{#files}}
+
+
+
+ {{#lines}}
+
+ | {{ldln}} |
+ {{rdln}} |
+ {{line}} |
+
+ {{/lines}}
+
+
+ {{/files}}
+
+
diff --git a/lib/gollum/templates/history.mustache b/lib/gollum/templates/history.mustache
index 3429e868..b966ddaf 100644
--- a/lib/gollum/templates/history.mustache
+++ b/lib/gollum/templates/history.mustache
@@ -18,7 +18,10 @@
{{>author_template}}
{{date}}
{{message}}
- [{{id7}}]
+
+ {{id7}}
+ {{#octicon}}code{{/octicon}}
+
{{/versions}}
diff --git a/lib/gollum/templates/latest_changes.mustache b/lib/gollum/templates/latest_changes.mustache
index 79bee321..5d16773f 100644
--- a/lib/gollum/templates/latest_changes.mustache
+++ b/lib/gollum/templates/latest_changes.mustache
@@ -8,9 +8,9 @@
-
+
{{#versions}}
-
+
-
{{>author_template}}
{{date}}
{{message}}
@@ -18,10 +18,12 @@
{{#renamed}}{{renamed}} -> {{/renamed}}{{file}}
{{/files}}
- [{{id7}}]
-
+
+ {{id7}}
+
+
{{/versions}}
-
+
diff --git a/lib/gollum/views/commit.rb b/lib/gollum/views/commit.rb
new file mode 100644
index 00000000..fabd21c0
--- /dev/null
+++ b/lib/gollum/views/commit.rb
@@ -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
diff --git a/lib/gollum/views/compare.rb b/lib/gollum/views/compare.rb
index f4ca21d9..aea2e8de 100644
--- a/lib/gollum/views/compare.rb
+++ b/lib/gollum/views/compare.rb
@@ -17,9 +17,9 @@ module Precious
@versions[1][0..6]
end
- def lines
+ def lines(diff = @diff)
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.
# 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?('+++')
@@ -28,7 +28,7 @@ module Precious
:class => line_class(line),
:ldln => left_diff_line_number(line),
:rdln => right_diff_line_number(line) }
- end if @diff
+ end if diff
lines
end
diff --git a/lib/gollum/views/history.rb b/lib/gollum/views/history.rb
index d362c269..c6e51a09 100644
--- a/lib/gollum/views/history.rb
+++ b/lib/gollum/views/history.rb
@@ -17,15 +17,18 @@ module Precious
i = @versions.size + 1
@versions.map do |v|
i -= 1
+ filename = path_for_version(v.tracked_pathname)
{ :id => v.id,
:id7 => v.id[0..6],
+ :href => page_route("gollum/commit/#{v.id}"),
+ :href_page => page_route("#{filename}/#{v.id}"),
:num => i,
:selected => @page.version.id == v.id,
: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,
:date => v.authored_date.strftime("%B %d, %Y"),
:user_icon => self.user_icon_code(v.author.email),
- :filename => path_for_version(v.tracked_pathname),
+ :filename => filename,
:date_full => v.authored_date,
}
end
diff --git a/lib/gollum/views/latest_changes.rb b/lib/gollum/views/latest_changes.rb
index 170097ce..95d0eb61 100644
--- a/lib/gollum/views/latest_changes.rb
+++ b/lib/gollum/views/latest_changes.rb
@@ -16,6 +16,7 @@ module Precious
i -= 1
{ :id => v.id,
:id7 => v.id[0..6],
+ :href => page_route("gollum/commit/#{v.id}"),
:num => i,
: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,