Do not re-canonicalize names referring to existing page files when updating format extensions

This commit is contained in:
Arran Cudbard-Bell
2011-05-31 18:29:09 -07:00
committed by Arran Cudbard-Bell
parent af7a52970f
commit 6926746624
3 changed files with 40 additions and 19 deletions
+3 -2
View File
@@ -73,7 +73,7 @@ module Gollum
# #
# dir - The String subdirectory of the Gollum::Page without any # dir - The String subdirectory of the Gollum::Page without any
# prefix or suffix slashes (e.g. "foo/bar"). # prefix or suffix slashes (e.g. "foo/bar").
# name - The String Gollum::Page name. # name - The String Gollum::Page filename_stripped.
# format - The Symbol Gollum::Page format. # format - The Symbol Gollum::Page format.
# data - The String wiki data to store in the tree map. # data - The String wiki data to store in the tree map.
# allow_same_ext - A Boolean determining if the tree map allows the same # allow_same_ext - A Boolean determining if the tree map allows the same
@@ -111,7 +111,8 @@ module Gollum
# is a working directory present. # is a working directory present.
# #
# dir - The String directory in which the file lives. # dir - The String directory in which the file lives.
# name - The String name of the page (may be in human format). # name - The String name of the page or the stripped filename
# (should be pre-canonicalized if required).
# format - The Symbol format of the page. # format - The Symbol format of the page.
# #
# Returns nothing. # Returns nothing.
+18 -2
View File
@@ -76,11 +76,20 @@ module Gollum
end end
# Reusable filter to turn a filename (without path) into a canonical name. # Reusable filter to turn a filename (without path) into a canonical name.
# Strips extension, converts spaces to dashes. # Strips extension, converts dashes to spaces.
# #
# Returns the filtered String. # Returns the filtered String.
def self.canonicalize_filename(filename) def self.canonicalize_filename(filename)
filename.split('.')[0..-2].join('.').gsub('-', ' ') strip_filename(filename).gsub('-', ' ')
end
# Reusable filter to strip extension and path from filename
#
# filename - The string path or filename to strip
#
# Returns the stripped String.
def self.strip_filename(filename)
::File.basename(filename, ::File.extname(filename))
end end
# Public: Initialize a page. # Public: Initialize a page.
@@ -100,6 +109,13 @@ module Gollum
@blob && @blob.name @blob && @blob.name
end end
# Public: The on-disk filename of the page with extension stripped.
#
# Returns the String name.
def filename_stripped
self.class.strip_filename(filename)
end
# Public: The canonical page name without extension, and dashes converted # Public: The canonical page name without extension, and dashes converted
# to spaces. # to spaces.
# #
+19 -15
View File
@@ -222,12 +222,14 @@ module Gollum
else else
Committer.new(self, commit) Committer.new(self, commit)
end end
committer.add_to_index('', name, format, data) filename = Gollum::Page.cname(name)
committer.add_to_index('', filename, format, data)
committer.after_commit do |index, sha| committer.after_commit do |index, sha|
@access.refresh @access.refresh
index.update_working_dir('', name, format) index.update_working_dir('', filename, format)
end end
multi_commit ? committer : committer.commit multi_commit ? committer : committer.commit
@@ -259,7 +261,10 @@ module Gollum
name ||= page.name name ||= page.name
format ||= page.format format ||= page.format
dir = ::File.dirname(page.path) dir = ::File.dirname(page.path)
dir = '' if dir == '.' dir = '' if dir == '.'
filename = (rename = page.name != name) ?
Gollum::Page.cname(name) : page.filename_stripped
multi_commit = false multi_commit = false
committer = if obj = commit[:committer] committer = if obj = commit[:committer]
@@ -268,18 +273,18 @@ module Gollum
else else
Committer.new(self, commit) Committer.new(self, commit)
end end
if page.name == name && page.format == format if !rename && page.format == format
committer.add(page.path, normalize(data)) committer.add(page.path, normalize(data))
else else
committer.delete(page.path) committer.delete(page.path)
committer.add_to_index(dir, name, format, data, :allow_same_ext) committer.add_to_index(dir, filename, format, data, :allow_same_ext)
end end
committer.after_commit do |index, sha| committer.after_commit do |index, sha|
@access.refresh @access.refresh
index.update_working_dir(dir, page.name, page.format) index.update_working_dir(dir, page.filename_stripped, page.format)
index.update_working_dir(dir, name, format) index.update_working_dir(dir, filename, format)
end end
multi_commit ? committer : committer.commit multi_commit ? committer : committer.commit
@@ -318,7 +323,7 @@ module Gollum
dir = '' if dir == '.' dir = '' if dir == '.'
@access.refresh @access.refresh
index.update_working_dir(dir, page.name, page.format) index.update_working_dir(dir, page.filename_stripped, page.format)
end end
multi_commit ? committer : committer.commit multi_commit ? committer : committer.commit
@@ -356,7 +361,7 @@ module Gollum
files = [] files = []
if page if page
files << [page.path, page.name, page.format] files << [page.path, page.filename_stripped, page.format]
else else
# Grit::Diff can't parse reverse diffs.... yet # Grit::Diff can't parse reverse diffs.... yet
patch.each_line do |line| patch.each_line do |line|
@@ -516,13 +521,12 @@ module Gollum
# Assemble a Page's filename from its name and format. # Assemble a Page's filename from its name and format.
# #
# name - The String name of the page (may be in human format). # name - The String name of the page (should be pre-canonicalized).
# format - The Symbol format of the page. # format - The Symbol format of the page.
# #
# Returns the String filename. # Returns the String filename.
def page_file_name(name, format) def page_file_name(name, format)
ext = @page_class.format_to_ext(format) name + '.' + @page_class.format_to_ext(format)
@page_class.cname(name) + '.' + ext
end end
# Fill an array with a list of pages. # Fill an array with a list of pages.