Permalink
Browse files

Merge branch 'master' into db-dev

  • Loading branch information...
2 parents b0a3db4 + bf82a19 commit 5a78bb46cf904fd7a467d6579fc4c7b2efde7b84 @KitaitiMakoto committed May 17, 2012
Showing with 66 additions and 2 deletions.
  1. +4 −0 hiki/repos/cvs.rb
  2. +7 −0 hiki/repos/default.rb
  3. +4 −0 hiki/repos/git.rb
  4. +4 −0 hiki/repos/hg.rb
  5. +9 −0 hiki/repos/plain.rb
  6. +4 −0 hiki/repos/svn.rb
  7. +2 −2 hiki/util.rb
  8. +32 −0 test/test_repos_plain.rb
View
@@ -57,6 +57,10 @@ def delete(page, msg = default_msg)
end
end
+ def rename(old_page, new_page)
+ raise NotImplementedError
+ end
+
def get_revision(page, revision)
ret = ''
Dir.chdir("#{@data_path}/text") do
View
@@ -43,6 +43,10 @@ def delete(page, log = nil)
raise "Please override this function."
end
+ def rename(old_page, new_page)
+ raise "Please override this function."
+ end
+
def get_revision(page, revision)
raise "Please override this function."
end
@@ -83,6 +87,9 @@ def commit(page, log = nil)
def delete(page, log = nil)
end
+ def rename(old_page, new_page)
+ end
+
def get_revision(page, revision)
revision = revision.to_i
begin
View
@@ -19,6 +19,10 @@ def delete(page, msg = default_msg)
end
end
+ def rename(old_page, new_page)
+ raise NotImplementedError
+ end
+
def get_revision(page, revision)
ret = ''
Dir.chdir("#{@data_path}/text") do
View
@@ -23,6 +23,10 @@ def delete(page, msg = default_msg)
end
end
+ def rename(old_page, new_page)
+ raise NotImplementedError
+ end
+
def get_revision(page, revision)
r = ""
Dir.chdir("#{@data_path}/text") do
View
@@ -50,6 +50,15 @@ def delete(page, log = nil)
File.open("#{@root}/#{wiki.untaint}/#{escape(page).untaint}/.removed", 'w'){|f|}
end
+ def rename(old_page, new_page)
+ wiki = File.read("#{@data_path}/text/.wiki")
+ old_dir = "#{@root}/#{wiki.untaint}/#{escape(old_page).untaint}"
+ new_dir = "#{@root}/#{wiki.untaint}/#{escape(new_page).untaint}"
+ # TODO raise custom exception
+ raise if File.exist?(new_dir)
+ FileUtils.mv(old_dir, new_dir)
+ end
+
def get_revision(page, revision)
wiki = File.read("#{@data_path}/text/.wiki")
File.read("#{@root}/#{wiki.untaint}/#{escape(page).untaint}/#{revision.to_i}")
View
@@ -93,6 +93,10 @@ def delete(page, msg = default_msg)
end
end
+ def rename(old_page, new_page)
+ raise NotImplementedError
+ end
+
def get_revision(page, revision)
ret = ''
Dir.chdir("#{@data_path}/text") do
View
@@ -374,9 +374,9 @@ def to_native(str, charset=nil)
to = case @charset
when /^utf-8$/i
'w'
- when /^shift_jis/i
+ when /\Ashift_jis\z/i
's'
- when /^EUC-JP/i
+ when /\Aeuc-jp\z/i
'e'
else
'e' # XXX what should we use?
View
@@ -68,6 +68,38 @@ def test_revisions
assert_equal(expected, @repos.revisions('HogeHoge'))
end
+ def test_rename
+ FileUtils.mkdir("#{@root}/#{@wiki}/HogeHoge")
+ FileUtils.mkdir("#{@root}/#{@wiki}/FooBar")
+ mkfile("#{@root}/#{@wiki}/HogeHoge/1", 'hogehoge')
+ mkfile("#{@root}/#{@wiki}/FooBar/1", 'foobar')
+
+ mkfile("#{@data_path}/text/HogeHoge", 'hogehoge')
+ mkfile("#{@data_path}/text/FooBar", 'foobar new')
+
+ @repos.commit('FooBar')
+ @repos.rename("FooBar", "FooBarBaz")
+ assert_equal('foobar', File.read("#{@root}/#{@wiki}/FooBarBaz/1"))
+ assert_equal('foobar new', File.read("#{@root}/#{@wiki}/FooBarBaz/2"))
+ end
+
+ def test_rename_new_page_already_exist
+ FileUtils.mkdir("#{@root}/#{@wiki}/HogeHoge")
+ FileUtils.mkdir("#{@root}/#{@wiki}/FooBar")
+ mkfile("#{@root}/#{@wiki}/HogeHoge/1", 'hogehoge')
+ mkfile("#{@root}/#{@wiki}/FooBar/1", 'foobar')
+
+ mkfile("#{@data_path}/text/HogeHoge", 'hogehoge')
+ mkfile("#{@data_path}/text/FooBar", 'foobar new')
+
+ @repos.commit('FooBar')
+ assert_raise(RuntimeError) do
+ @repos.rename("FooBar", "HogeHoge")
+ end
+
+ assert_equal('hogehoge', File.read("#{@root}/#{@wiki}/HogeHoge/1"))
+ end
+
private
def mkfile(file, contents)
File.open(file, 'w') do |f|

0 comments on commit 5a78bb4

Please sign in to comment.