Update Wiki#update_page to use Index#read_tree goodness.
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|||||||
s.rdoc_options = ["--charset=UTF-8"]
|
s.rdoc_options = ["--charset=UTF-8"]
|
||||||
s.extra_rdoc_files = %w[README.md LICENSE]
|
s.extra_rdoc_files = %w[README.md LICENSE]
|
||||||
|
|
||||||
s.add_dependency('grit', "~> 2.1")
|
s.add_dependency('grit', "~> 2.2")
|
||||||
s.add_dependency('github-markup', [">= 0.4.0", "< 1.0.0"])
|
s.add_dependency('github-markup', [">= 0.4.0", "< 1.0.0"])
|
||||||
s.add_dependency('albino', "~> 1.0")
|
s.add_dependency('albino', "~> 1.0")
|
||||||
s.add_dependency('sinatra', "~> 1.0")
|
s.add_dependency('sinatra', "~> 1.0")
|
||||||
|
|||||||
+38
-10
@@ -155,19 +155,19 @@ module Gollum
|
|||||||
def update_page(page, name, format, data, commit = {})
|
def update_page(page, name, format, data, commit = {})
|
||||||
commit = normalize_commit(commit)
|
commit = normalize_commit(commit)
|
||||||
pcommit = @repo.commit('master')
|
pcommit = @repo.commit('master')
|
||||||
map = tree_map(pcommit.tree)
|
|
||||||
name ||= page.name
|
name ||= page.name
|
||||||
format ||= page.format
|
format ||= page.format
|
||||||
index = nil
|
index = self.repo.index
|
||||||
|
|
||||||
|
index.read_tree(pcommit.tree.id)
|
||||||
|
|
||||||
if page.name == name && page.format == format
|
if page.name == name && page.format == format
|
||||||
index = tree_map_to_index(map)
|
|
||||||
index.add(page.path, normalize(data))
|
index.add(page.path, normalize(data))
|
||||||
else
|
else
|
||||||
map = delete_from_tree_map(map, page.path)
|
index.delete(page.path)
|
||||||
dir = ::File.dirname(page.path)
|
dir = ::File.dirname(page.path)
|
||||||
map = add_to_tree_map(map, dir, name, format, data, :allow_same_ext)
|
dir = '' if dir == '.'
|
||||||
index = tree_map_to_index(map)
|
add_to_index(index, dir, name, format, data, :allow_same_ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
actor = Grit::Actor.new(commit[:name], commit[:email])
|
actor = Grit::Actor.new(commit[:name], commit[:email])
|
||||||
@@ -311,6 +311,32 @@ module Gollum
|
|||||||
index
|
index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Determine if a given page path 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 page file. This may include the format
|
||||||
|
# extension in which case it will be ignored.
|
||||||
|
#
|
||||||
|
# Returns the Boolean response.
|
||||||
|
def page_path_scheduled_for_deletion?(map, path)
|
||||||
|
parts = path.split('/')
|
||||||
|
if parts.size == 1
|
||||||
|
deletions = map.keys.select { |k| !map[k] }
|
||||||
|
downfile = parts.first.downcase.sub(/\.\w+$/, '')
|
||||||
|
deletions.any? { |d| d.downcase.sub(/\.\w+$/, '') == downfile }
|
||||||
|
else
|
||||||
|
part = parts.shift
|
||||||
|
if rest = map[part]
|
||||||
|
page_path_scheduled_for_deletion?(rest, parts.join('/'))
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Adds a page to the given Index.
|
# Adds a page to the given Index.
|
||||||
#
|
#
|
||||||
# index - The Grit::Index to which the page will be added.
|
# index - The Grit::Index to which the page will be added.
|
||||||
@@ -332,20 +358,22 @@ module Gollum
|
|||||||
|
|
||||||
dir = '/' if dir.strip.empty?
|
dir = '/' if dir.strip.empty?
|
||||||
|
|
||||||
|
fullpath = ::File.join(dir, path)
|
||||||
|
fullpath = fullpath[1..-1] if fullpath =~ /^\//
|
||||||
|
|
||||||
if index.current_tree && tree = index.current_tree / dir
|
if index.current_tree && tree = index.current_tree / dir
|
||||||
downpath = path.downcase.sub(/\.\w+$/, '')
|
downpath = path.downcase.sub(/\.\w+$/, '')
|
||||||
|
|
||||||
tree.blobs.each do |blob|
|
tree.blobs.each do |blob|
|
||||||
|
next if page_path_scheduled_for_deletion?(index.tree, fullpath)
|
||||||
file = blob.name.downcase.sub(/\.\w+$/, '')
|
file = blob.name.downcase.sub(/\.\w+$/, '')
|
||||||
file_ext = ::File.extname(blob.name).sub(/^\./, '')
|
file_ext = ::File.extname(blob.name).sub(/^\./, '')
|
||||||
if downpath == file && !(allow_same_ext && file_ext == ext)
|
if downpath == file && !(allow_same_ext && file_ext == ext)
|
||||||
raise DuplicatePageError.new(dir, blob, path)
|
raise DuplicatePageError.new(dir, blob.name, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fullpath = ::File.join(dir, path)
|
|
||||||
fullpath = fullpath[1..-1] if fullpath =~ /^\//
|
|
||||||
index.add(fullpath, normalize(data))
|
index.add(fullpath, normalize(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user