[Hiki-dev:00605] Re: repository backend

Back to archive index

KOMATSU Shinichiro koma2****@ms*****
2004年 12月 9日 (木) 06:19:18 JST


小松です。

From: Kazuhiko <kazuh****@fdiar*****>
Subject: [Hiki-dev:00603] Re: repository backend
Date: Tue, Dec 07, 2004 at 12:26:26AM JST

> 現在の CVS HEAD からの差分をつけておきます。svn バックエンドで hikifarm
> から hiki を作ったり、ページを編集したり追加したり削除したり、くらいは確
> 認しましたが、いろいろ試してくださると幸いです。

repo なし (repos_type == nil) で試したのですが、
その場合 misc/hikifarm/index.cgi の

    require "hiki/repos/#{repos_type}"

の部分で repos_type が空になってエラーになりますね。
こんな感じで、hikifarm.conf を読んだ後に
default 値をセットするようにしてみましたが、どうでしょう?

CVS HEAD からの差分も添付しておきます。


Index: misc/hikifarm/index.cgi
===================================================================
--- misc/hikifarm/index.cgi	(revision 18)
+++ misc/hikifarm/index.cgi	(revision 19)
@@ -13,8 +13,6 @@
 default_pages = "#{hiki}/text"
 data_path = ''
 cvsroot = nil
-repos_type = 'default'
-repos_root = nil
 hikifarm_path = './'
 
 title = ''
@@ -33,6 +31,9 @@
 @hiki = hiki
 @default_pages = default_pages
 
+repos_type ||= 'default'
+repos_root ||= nil
+
 # Support depracated configuration
 if cvsroot then
    repos_type = 'cvs'

-- 
┏━━━━━━━━━━━━━━━━━━━━━━┓
                小松  晋一朗            
            koma2****@ms*****
            koma2****@momon*****
     http://straycat.ms.u-tokyo.ac.jp/~koma2/
┗━━━━━━━━━━━━━━━━━━━━━━┛
-------------- next part --------------
diff --exclude=CVS -urN hiki.orig/hiki/config.rb hiki/hiki/config.rb
--- hiki.orig/hiki/config.rb	Tue Sep 14 11:24:49 2004
+++ hiki/hiki/config.rb	Wed Dec  8 22:43:25 2004
@@ -14,9 +14,14 @@
       default
       load_cgi_conf
 
+      require "style/#{@style}/parser"
+      require "style/#{@style}/html_formatter"
+      require "hiki/repos/#{@repos_type}"
+
       style =****@style*****( /\+/, '' )
       @parser = "Parser_#{style}"
       @formatter = "HTMLFormatter_#{style}"
+      @repos = Hiki::const_get("Repos#{@repos_type.capitalize}").new(@repos_root, @data_path)
 
       instance_variables.each do |v|
         v.sub!( /@/, '' )
@@ -102,6 +107,7 @@
       @lang          ||= 'ja'
       @database_type ||= 'flatfile'
       @cgi_name      ||= './'
+      @repos_type    ||= 'default'
       @use_wikiname    = true if @use_wikiname.nil?
       @options         = {} unles****@optio***** == Hash
     end
diff --exclude=CVS -urN hiki.orig/hiki/repos/cvs.rb hiki/hiki/repos/cvs.rb
--- hiki.orig/hiki/repos/cvs.rb	Thu Jan  1 09:00:00 1970
+++ hiki/hiki/repos/cvs.rb	Wed Dec  8 22:54:49 2004
@@ -0,0 +1,69 @@
+# $Id$
+# Copyright (C) 2003, Koichiro Ohba <koich****@meado*****>
+# Copyright (C) 2003, Yasuo Itabashi <yasuo_itabashi{@}hotmail.com>
+# You can distribute this under GPL.
+
+require 'hiki/repos/default'
+
+# CVS Repository Backend
+module Hiki
+  class ReposCvs < ReposDefault
+     def setup()
+	oldpwd = Dir.pwd
+	begin
+	   Dir.chdir( @data_path )
+	   system( "cvs -d #{@root} init > /dev/null 2>&1" )
+	   if not File.directory?(".CVSROOT") then
+	      system( "cvs -d #{@root} co -d .CVSROOT CVSROOT > /dev/null 2>&1" )
+	   end
+	   Dir.chdir( ".CVSROOT" )
+	   system( "cvs -d #{@root} update > /dev/null 2>&1" )
+	ensure
+	   Dir.chdir( oldpwd.untaint )
+	end
+     end
+     def imported?( wiki )
+	return File.directory?( "#{@root}/#{wiki}" )
+     end
+     def import( wiki )
+	oldpwd = Dir.pwd
+	begin
+	   Dir.chdir( "#{@data_path}/#{wiki}/text" )
+	   system( "cvs -d #{@root} import -m 'Starting #{wiki}' #{wiki} T#{wiki} start > /dev/null 2>&1" )
+	   Dir.chdir( '..' )
+	   system( "cvs -d #{@root} co -d text #{wiki} > /dev/null 2>&1" )
+	ensure
+	   Dir.chdir( oldpwd.untaint )
+	end
+     end
+     def update( wiki )
+	oldpwd = Dir.pwd
+	begin
+	   Dir.chdir( "#{@data_path}/#{wiki}/text" )
+	   system( "cvs -d #{@root} update > /dev/null 2>&1" )
+	ensure
+	   Dir.chdir( oldpwd.untaint )
+	end
+     end
+     def commit( page )
+       oldpwd = Dir.pwd.untaint
+       begin
+	 Dir.chdir( "#{@data_path}/text" )
+	 system( "cvs -d #{@root} add -- #{page.escape} > /dev/null 2>&1".untaint )
+	 system( "cvs -d #{@root} ci -m '#{ENV['REMOTE_ADDR']} - #{ENV['REMOTE_HOST']}' > /dev/null 2>&1".untaint )
+       ensure
+	 Dir.chdir( oldpwd )
+       end
+     end
+     def delete( page )
+       oldpwd = Dir.pwd.untaint
+       begin
+	 Dir.chdir( "#{@data_path}/text" )
+	 system( "cvs -d #{@root} remove -- #{page.escape} > /dev/null 2>&1".untaint )
+	 system( "cvs -d #{@root} ci -m '#{ENV['REMOTE_ADDR']} - #{ENV['REMOTE_HOST']}' > /dev/null 2>&1".untaint )
+       ensure
+	 Dir.chdir( oldpwd )
+       end
+     end
+  end
+end
diff --exclude=CVS -urN hiki.orig/hiki/repos/default.rb hiki/hiki/repos/default.rb
--- hiki.orig/hiki/repos/default.rb	Thu Jan  1 09:00:00 1970
+++ hiki/hiki/repos/default.rb	Wed Dec  8 22:54:49 2004
@@ -0,0 +1,29 @@
+# $Id$
+# Copyright (C) 2003, Koichiro Ohba <koich****@meado*****>
+# Copyright (C) 2003, Yasuo Itabashi <yasuo_itabashi{@}hotmail.com>
+# You can distribute this under GPL.
+
+# Null Repository Backend
+
+module Hiki
+  class ReposDefault
+     attr_reader :root, :data_path
+     def initialize(root, data_path)
+	@root = root
+	@data_path = data_path
+     end
+     def setup()
+     end
+     def imported?( wiki )
+	return true
+     end
+     def import( wiki )
+     end
+     def update( wiki )
+     end
+     def commit( page )
+     end
+     def delete( page )
+     end
+  end
+end
diff --exclude=CVS -urN hiki.orig/hiki/repos/svn.rb hiki/hiki/repos/svn.rb
--- hiki.orig/hiki/repos/svn.rb	Thu Jan  1 09:00:00 1970
+++ hiki/hiki/repos/svn.rb	Wed Dec  8 22:54:49 2004
@@ -0,0 +1,71 @@
+# $Id$
+# Copyright (C) 2003, Koichiro Ohba <koich****@meado*****>
+# Copyright (C) 2003, Yasuo Itabashi <yasuo_itabashi{@}hotmail.com>
+# You can distribute this under GPL.
+
+require 'hiki/repos/default'
+
+# Subversion Repository Backend
+module Hiki
+  class ReposSvn < ReposDefault
+     def setup()
+	system( "svnadmin create #{@root} > /dev/null 2>&1" )
+     end
+     def imported?( wiki )
+	s = ''
+	open("|svn ls file://#{@root}/#{wiki}") do |f|
+	   s << (f.gets( nil ) ? $_ : '')
+	end
+
+	if %r|^trunk/$| =~ s then
+	   return true
+	else
+	   return false
+	end
+     end
+     def import( wiki )
+	oldpwd = Dir.pwd
+	begin
+	   Dir.chdir( "#{@data_path}/#{wiki}/text" )
+	   system( "svnadmin create #{@root}/#{wiki} > /dev/null 2>&1" )
+	   system( "svn import -m 'Starting #{wiki}' . file://#{@root}/#{wiki}/trunk > /dev/null 2>&1" )
+	   Dir.chdir( '..' )
+	   rmdir( 'text' )
+	   system( "svn checkout file://#{@root}/#{wiki}/trunk text > /dev/null 2>&1" )
+	   system( "svn propdel svn:mime-type -R text > /dev/null 2>&1" )
+	ensure
+	   Dir.chdir( oldpwd.untaint )
+	end
+     end
+     def update( wiki )
+	oldpwd = Dir.pwd
+	begin
+	   Dir.chdir( "#{@data_path}/#{wiki}/text" )
+	   system( "svn update > /dev/null 2>&1" )
+	ensure
+	   Dir.chdir( oldpwd.untaint )
+	end
+     end
+     def commit( page )
+       oldpwd = Dir.pwd.untaint
+       begin
+	 Dir.chdir( "#{@data_path}/text" )
+	 system( "svn add -- #{page.escape} > /dev/null 2>&1".untaint )
+	 system( "svn propdel svn:mime-type -- #{page.escape} > /dev/null 2>&1".untaint )
+	 system( "svn ci -m '#{ENV['REMOTE_ADDR']} - #{ENV['REMOTE_HOST']}' > /dev/null 2>&1".untaint )
+       ensure
+	 Dir.chdir( oldpwd )
+       end
+     end
+     def delete( page )
+       oldpwd = Dir.pwd.untaint
+       begin
+	 Dir.chdir( "#{@data_path}/text" )
+	 system( "svn remove -- #{page.escape} > /dev/null 2>&1".untaint )
+	 system( "svn ci -m '#{ENV['REMOTE_ADDR']} - #{ENV['REMOTE_HOST']}' > /dev/null 2>&1".untaint )
+       ensure
+	 Dir.chdir( oldpwd )
+       end
+     end
+  end
+end
diff --exclude=CVS -urN hiki.orig/hiki.cgi hiki/hiki.cgi
--- hiki.orig/hiki.cgi	Fri Sep 10 22:41:36 2004
+++ hiki/hiki.cgi	Wed Dec  8 22:43:25 2004
@@ -18,9 +18,7 @@
 
   require 'hiki/config'
   conf = Hiki::Config::new
-  require "style/#{conf.style}/html_formatter"
-  require "style/#{conf.style}/parser"
-  require "messages/#{conf.lang}"
+  load "messages/#{conf.lang}.rb"
   require "hiki/db/#{conf.database_type}"
 
   require 'hiki/command'
diff --exclude=CVS -urN hiki.orig/misc/hikifarm/index.cgi hiki/misc/hikifarm/index.cgi
--- hiki.orig/misc/hikifarm/index.cgi	Sun Oct 31 19:37:58 2004
+++ hiki/misc/hikifarm/index.cgi	Thu Dec  9 06:06:50 2004
@@ -13,8 +13,6 @@
 default_pages = "#{hiki}/text"
 data_path = ''
 cvsroot = nil
-repos_type = nil
-repos_root = nil
 hikifarm_path = './'
 
 title = ''
@@ -33,6 +31,9 @@
 @hiki = hiki
 @default_pages = default_pages
 
+repos_type ||= 'default'
+repos_root ||= nil
+
 # Support depracated configuration
 if cvsroot then
    repos_type = 'cvs'
@@ -113,118 +114,6 @@
    }
 end
 
-# Null Repository Backend
-class ReposDefault
-   attr_reader :root, :data_path
-   def initialize(root, data_path)
-      @root = root
-      @data_path = data_path
-   end
-   def setup()
-   end
-   def imported?( wiki )
-      return true
-   end
-   def import( wiki )
-   end
-   def update( wiki )
-   end
-end
-
-# CVS Repository Backend
-class ReposCvs < ReposDefault
-   def setup()
-      oldpwd = Dir.pwd
-      begin
-         Dir.chdir( @data_path )
-         system( "cvs -d #{@root} init > /dev/null 2>&1" )
-         if not File.directory?(".CVSROOT") then
-            system( "cvs -d #{@root} co -d .CVSROOT CVSROOT > /dev/null 2>&1" )
-         end
-         Dir.chdir( ".CVSROOT" )
-         system( "cvs -d #{@root} update > /dev/null 2>&1" )
-      ensure
-         Dir.chdir( oldpwd.untaint )
-      end
-   end
-   def imported?( wiki )
-      return File.directory?( "#{@root}/#{wiki}" )
-   end
-   def import( wiki )
-      oldpwd = Dir.pwd
-      begin
-         Dir.chdir( "#{@data_path}/#{wiki}/text" )
-         system( "cvs -d #{@root} import -m 'Starting #{wiki}' #{wiki} T#{wiki} start > /dev/null 2>&1" )
-         Dir.chdir( '..' )
-         system( "cvs -d #{@root} co -d text #{wiki} > /dev/null 2>&1" )
-      ensure
-         Dir.chdir( oldpwd.untaint )
-      end
-   end
-   def update( wiki )
-      oldpwd = Dir.pwd
-      begin
-         Dir.chdir( "#{@data_path}/#{wiki}/text" )
-         system( "cvs -d #{@root} update > /dev/null 2>&1" )
-      ensure
-         Dir.chdir( oldpwd.untaint )
-      end
-   end
-end
-
-# Subversion Repository Backend
-class ReposSvn < ReposDefault
-   def setup()
-      system( "svnadmin create #{@root} > /dev/null 2>&1" )
-   end
-   def imported?( wiki )
-      s = ''
-      open("|svn ls file://#{@root}/#{wiki}") do |f|
-         s << (f.gets( nil ) ? $_ : '')
-      end
-
-      if %r|^trunk/$| =~ s then
-         return true
-      else
-         return false
-      end
-   end
-   def import( wiki )
-      oldpwd = Dir.pwd
-      begin
-         Dir.chdir( "#{@data_path}/#{wiki}/text" )
-         system( "svnadmin create #{@root}/#{wiki} > /dev/null 2>&1" )
-         system( "svn import -m 'Starting #{wiki}' . file://#{@root}/#{wiki}/trunk > /dev/null 2>&1" )
-         Dir.chdir( '..' )
-         rmdir( 'text' )
-         system( "svn checkout file://#{@root}/#{wiki}/trunk text > /dev/null 2>&1" )
-         system( "svn propdel svn:mime-type -R text > /dev/null 2>&1" )
-      ensure
-         Dir.chdir( oldpwd.untaint )
-      end
-   end
-   def update( wiki )
-      oldpwd = Dir.pwd
-      begin
-         Dir.chdir( "#{@data_path}/#{wiki}/text" )
-         system( "svn update > /dev/null 2>&1" )
-      ensure
-         Dir.chdir( oldpwd.untaint )
-      end
-   end
-end
-
-# Create repository backend
-def create_repos(repos_type, repos_root, data_path)
-   case repos_type
-   when 'cvs'
-      return ReposCvs.new(repos_root, data_path)
-   when 'svn'
-      return ReposSvn.new(repos_root, data_path)
-   else
-      return ReposDefault.new(repos_root, data_path)
-   end
-end
 
 def create_wiki( wiki, hiki, cgi_name, data_path )
    Dir.mkdir( wiki.untaint )
@@ -327,11 +216,14 @@
 
 #--- main -----------------------------------------------------------
 
+$:.unshift(hiki)
 require 'cgi'
+require "hiki/repos/#{repos_type}"
 
 cgi = CGI::new
 msg = nil
- @ repos = create_repos(repos_type, repos_root, data_path)
+
+ @ repos = Hiki::const_get("Repos#{repos_type.capitalize}").new(repos_root, data_path)
 
 @repos.setup()
 
diff --exclude=CVS -urN hiki.orig/plugin/00default.rb hiki/plugin/00default.rb
--- hiki.orig/plugin/00default.rb	Tue Sep 28 22:47:28 2004
+++ hiki/plugin/00default.rb	Wed Dec  8 22:43:25 2004
@@ -84,6 +84,7 @@
 #===== update_proc
 add_update_proc {
   updating_mail if****@conf*****_on_update
+  @conf.repos.commit(@page)
 }
 
 #----- send a mail on updating
@@ -99,6 +100,11 @@
   rescue
   end
 end
+
+#===== delete_proc
+add_delete_proc {
+  @conf.repos.delete(@page)
+}
 
 #===== hiki_header
 add_header_proc {


Hiki-dev メーリングリストの案内
Back to archive index