From 9843f4c739a3a5b03c8d29a5059381f40af71045 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 8 Dec 2010 15:37:22 -0800 Subject: [PATCH] use grit's #apply_patch method --- lib/gollum/wiki.rb | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index ccd9d779..8eab9f59 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -316,15 +316,10 @@ module Gollum sha2 = nil end - pcommit = @repo.commit('master') + pcommit = @repo.commit('master') + patch = full_diff_for(page, sha1, sha2) commit[:parent] = [pcommit] - commit[:tree] = write_to_real_index(pcommit.sha) do - options = {:reverse => true, :cached => true} - @repo.git.native(:apply, options) do |stdin| - stdin << full_diff_for(page, sha1, sha2) - stdin.close - end - end + commit[:tree] = @repo.git.apply_patch(pcommit.sha, patch) index = nil sha1 = commit_index(commit) { |i| index = i } @@ -556,26 +551,9 @@ module Gollum index.commit(options[:message], options[:parent], actor) end - def write_to_real_index(head_sha) - old_index = ENV['GIT_INDEX_FILE'] - temp_index = @repo.git.create_tempfile('index', :clean) - ENV['GIT_INDEX_FILE'] = temp_index - @repo.git.native('read-tree', {}, head_sha) - if yield - tree_sha = @repo.git.native('write-tree') - after_index = ENV['GIT_INDEX_FILE'] - if after_index != temp_index - raise 'environment was changed for the git call' - end - tree_sha - end - ensure - ENV['GIT_INDEX_FILE'] = old_index - end - def full_diff_for(page, sha1, sha2 = nil) sha1, sha2 = "#{sha1}^", sha1 if sha2.nil? - repo.git.native(:diff, {}, sha1, sha2, '--', page.path) + repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path) end # Ensures a commit hash has all the required fields for a commit.