[issue #64] Yet another hacks.
This commit is contained in:
parent
8733c4dc34
commit
b117ec1331
6
Gemfile
6
Gemfile
|
@ -1,6 +1,7 @@
|
|||
source 'http://rubygems.org'
|
||||
|
||||
gem 'rails', '3.0.11' #, :git => 'git://github.com/rails/rails.git'
|
||||
gem 'shotgun'
|
||||
|
||||
gem 'pg', '~> 0.11.0'
|
||||
gem 'silent-postgres', '~> 0.1.1'
|
||||
|
@ -26,8 +27,9 @@ gem "russian"
|
|||
|
||||
# gem 'ghoul_grack', '~> 0.0.1'
|
||||
gem 'grack', :git => 'git://github.com/rdblue/grack.git', :require => 'git_http'
|
||||
#gem "grit", :git => 'git://github.com/mojombo/grit.git', :branch => 'master'
|
||||
gem "grit", :git => 'git://github.com/github/grit.git', :branch => 'master'
|
||||
#gem "grit", :git => 'git://github.com/gvino/grit.git', :branch => 'master'
|
||||
gem "grit", :git => 'git://github.com/mojombo/grit.git', :branch => 'master'
|
||||
#gem "grit", :git => 'git://github.com/github/grit.git', :branch => 'master'
|
||||
gem 'whenever', :require => false
|
||||
gem 'delayed_job'
|
||||
gem 'highline', '~> 1.6.8'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
GIT
|
||||
remote: git://github.com/github/grit.git
|
||||
revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
|
||||
remote: git://github.com/mojombo/grit.git
|
||||
revision: 3fc864f3c637e06e2fa7a81f6b48a5df58a9bc5b
|
||||
branch: master
|
||||
specs:
|
||||
grit (2.4.1)
|
||||
|
@ -206,6 +206,8 @@ GEM
|
|||
rails
|
||||
valuable
|
||||
sexp_processor (3.0.10)
|
||||
shotgun (0.9)
|
||||
rack (>= 1.0)
|
||||
silent-postgres (0.1.1)
|
||||
sinatra (1.2.8)
|
||||
rack (~> 1.1)
|
||||
|
@ -276,6 +278,7 @@ DEPENDENCIES
|
|||
ruby_parser
|
||||
russian
|
||||
schema_plus (~> 0.2.1)
|
||||
shotgun
|
||||
silent-postgres (~> 0.1.1)
|
||||
unicorn (~> 4.1.1)
|
||||
web-app-theme
|
||||
|
|
|
@ -109,13 +109,7 @@ class WikiController < ApplicationController
|
|||
return
|
||||
end
|
||||
@page = @wiki.page(@name)
|
||||
puts 'test'
|
||||
puts @versions.inspect
|
||||
puts @wiki.repo.diff(@versions.first, @versions.last, @page.path).inspect
|
||||
puts @page.path
|
||||
puts @page.path.encoding
|
||||
@diffs = [@wiki.repo.diff(@versions.first, @versions.last, @page.path).first]
|
||||
puts @diffs.inspect
|
||||
render :compare
|
||||
else
|
||||
redirect_to project_wiki_path(@project, CGI.escape(@name))
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
|
||||
require './lib/grit'
|
|
@ -0,0 +1,3 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require './lib/grit/repo.rb'
|
||||
require './lib/grit/diff.rb'
|
|
@ -0,0 +1,56 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Grit
|
||||
class Diff
|
||||
def self.list_from_string(repo, text)
|
||||
lines = text.split("\n")
|
||||
|
||||
diffs = []
|
||||
|
||||
while !lines.empty?
|
||||
m, a_path, b_path = *lines.shift.match(%r{^diff --git "{0,1}a/(.+?)"{0,1} "{0,1}b/(.+?)"{0,1}$})
|
||||
|
||||
if lines.first =~ /^old mode/
|
||||
m, a_mode = *lines.shift.match(/^old mode (\d+)/)
|
||||
m, b_mode = *lines.shift.match(/^new mode (\d+)/)
|
||||
end
|
||||
|
||||
if lines.empty? || lines.first =~ /^diff --git/
|
||||
diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
|
||||
next
|
||||
end
|
||||
|
||||
sim_index = 0
|
||||
new_file = false
|
||||
deleted_file = false
|
||||
renamed_file = false
|
||||
|
||||
if lines.first =~ /^new file/
|
||||
m, b_mode = lines.shift.match(/^new file mode (.+)$/)
|
||||
a_mode = nil
|
||||
new_file = true
|
||||
elsif lines.first =~ /^deleted file/
|
||||
m, a_mode = lines.shift.match(/^deleted file mode (.+)$/)
|
||||
b_mode = nil
|
||||
deleted_file = true
|
||||
elsif lines.first =~ /^similarity index (\d+)\%/
|
||||
sim_index = $1.to_i
|
||||
renamed_file = true
|
||||
2.times { lines.shift } # shift away the 2 `rename from/to ...` lines
|
||||
end
|
||||
|
||||
m, a_blob, b_blob, b_mode = *lines.shift.match(%r{^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$})
|
||||
b_mode.strip! if b_mode
|
||||
|
||||
diff_lines = []
|
||||
while lines.first && lines.first !~ /^diff/
|
||||
diff_lines << lines.shift
|
||||
end
|
||||
diff = diff_lines.join("\n")
|
||||
|
||||
diffs << Diff.new(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff, renamed_file, sim_index)
|
||||
end
|
||||
|
||||
diffs
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Grit
|
||||
class Repo
|
||||
|
||||
alias_method :native_grit_diff, :diff
|
||||
|
||||
def diff(a, b, *paths)
|
||||
diff = self.git.native('diff', {}, a, b, '--', *paths).force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||
Grit.log 'in grit'
|
||||
Grit.log diff
|
||||
if diff =~ /diff --git "{0,1}a/
|
||||
diff = diff.sub(/.*?(diff --git "{0,1}a)/m, '\1')
|
||||
else
|
||||
diff = ''
|
||||
end
|
||||
Diff.list_from_string(self, diff)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue