Merge branch 'master' of github.com:github/gollum

This commit is contained in:
rick
2010-08-30 18:04:36 -07:00
9 changed files with 201 additions and 91 deletions
+6 -5
View File
@@ -58,7 +58,7 @@ module Precious
format = params[:format].intern
name = params[:rename] if params[:rename]
wiki.update_page(page, name, format, params[:content], commit_message)
wiki.update_page(page, name, format, params[:content], commit_message(wiki))
redirect "/#{Gollum::Page.cname name}"
end
@@ -70,7 +70,7 @@ module Precious
format = params[:format].intern
begin
wiki.write_page(name, format, params[:content], commit_message)
wiki.write_page(name, format, params[:content], commit_message(wiki))
redirect "/#{name}"
rescue Gollum::DuplicatePageError => e
@message = "Duplicate page: #{e.message}"
@@ -141,6 +141,7 @@ module Precious
@content = page.formatted_data
mustache :page
elsif file = wiki.file(name)
content_type MIME::Types.type_for(name).to_s
file.raw_data
else
@name = name
@@ -148,10 +149,10 @@ module Precious
end
end
def commit_message
def commit_message(wiki)
{ :message => params[:message],
:name => `git config --get user.name `.strip,
:email => `git config --get user.email`.strip }
:name => wiki.repo.config['user.name'],
:email => wiki.repo.config['user.email'] }
end
end
end
+89 -13
View File
@@ -135,9 +135,12 @@ module Gollum
parents = pcommit ? [pcommit] : []
actor = Grit::Actor.new(commit[:name], commit[:email])
sha = index.commit(commit[:message], parents, actor)
sha1 = index.commit(commit[:message], parents, actor)
@ref_map.clear
sha
update_working_dir(index, '', name, format)
sha1
end
# Public: Update an existing page with new content. The location of the
@@ -162,21 +165,26 @@ module Gollum
format ||= page.format
index = self.repo.index
dir = ::File.dirname(page.path)
dir = '' if dir == '.'
index.read_tree(pcommit.tree.id)
if page.name == name && page.format == format
index.add(page.path, normalize(data))
else
index.delete(page.path)
dir = ::File.dirname(page.path)
dir = '' if dir == '.'
add_to_index(index, dir, name, format, data, :allow_same_ext)
end
actor = Grit::Actor.new(commit[:name], commit[:email])
sha = index.commit(commit[:message], [pcommit], actor)
sha1 = index.commit(commit[:message], [pcommit], actor)
@ref_map.clear
sha
update_working_dir(index, dir, page.name, page.format)
update_working_dir(index, dir, name, format)
sha1
end
# Public: Delete a page.
@@ -195,10 +203,16 @@ module Gollum
index.read_tree(pcommit.tree.id)
index.delete(page.path)
dir = ::File.dirname(page.path)
dir = '' if dir == '.'
actor = Grit::Actor.new(commit[:name], commit[:email])
sha = index.commit(commit[:message], [pcommit], actor)
sha1 = index.commit(commit[:message], [pcommit], actor)
@ref_map.clear
sha
update_working_dir(index, dir, page.name, page.format)
sha1
end
# Public: Lists all pages for this wiki.
@@ -277,6 +291,45 @@ module Gollum
data.gsub(/\r/, '')
end
# Assemble a Page's filename from its name and format.
#
# name - The String name of the page (may be in human format).
# format - The Symbol format of the page.
#
# Returns the String filename.
def page_file_name(name, format)
ext = @page_class.format_to_ext(format)
@page_class.cname(name) + '.' + ext
end
# Update the given file in the repository's working directory if there
# is a working directory present.
#
# index - The Grit::Index with which to sync.
# dir - The String directory in which the file lives.
# name - The String name of the page (may be in human format).
# format - The Symbol format of the page.
#
# Returns nothing.
def update_working_dir(index, dir, name, format)
unless @repo.bare
path =
if dir == ''
page_file_name(name, format)
else
::File.join(dir, page_file_name(name, format))
end
Dir.chdir(::File.join(@repo.path, '..')) do
if file_path_scheduled_for_deletion?(index.tree, path)
@repo.git.rm({'f' => true}, '--', path)
else
@repo.git.checkout({}, 'HEAD', '--', path)
end
end
end
end
# Fill an array with a list of pages.
#
# ref - A String ref that is either a commit SHA or references one.
@@ -290,8 +343,32 @@ module Gollum
end
end
# Determine if a given page path is scheduled to be deleted in the next
# commit for the given Index.
# Determine if a given file is scheduled to be deleted in the next commit
# for the given Index.
#
# map - The Hash map:
# key - The String directory or filename.
# val - The Hash submap or the String contents of the file.
# path - The String path of the file including extension.
#
# Returns the Boolean response.
def file_path_scheduled_for_deletion?(map, path)
parts = path.split('/')
if parts.size == 1
deletions = map.keys.select { |k| !map[k] }
deletions.any? { |d| d == parts.first }
else
part = parts.shift
if rest = map[part]
file_path_scheduled_for_deletion?(rest, parts.join('/'))
else
false
end
end
end
# Determine if a given page (regardless of format) is scheduled to be
# deleted in the next commit for the given Index.
#
# map - The Hash map:
# key - The String directory or filename.
@@ -311,7 +388,7 @@ module Gollum
if rest = map[part]
page_path_scheduled_for_deletion?(rest, parts.join('/'))
else
nil
false
end
end
end
@@ -332,8 +409,7 @@ module Gollum
#
# Returns nothing (modifies the Index in place).
def add_to_index(index, dir, name, format, data, allow_same_ext = false)
ext = @page_class.format_to_ext(format)
path = @page_class.cname(name) + '.' + ext
path = page_file_name(name, format)
dir = '/' if dir.strip.empty?