1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
=begin
== plugin/history.rb - CVS Խɽץ饰
Copyright (C) 2003 Hajime BABA <baba.hajime@nifty.com>
$Id: history.rb,v 1.28 2005/06/29 06:10:45 fdiary Exp $
You can redistribute and/or modify this file under the terms of the LGPL.
Copyright (C) 2003 Yasuo Itabashi <yasuo_itabashi{@}hotmail.com>
=== Ȥ
* Hiki cvs ץ饰 (뤤 svn ץ饰) ѤƤ
ȤǤ
* ξǡHiki Υץ饰ǥ쥯ȥ˥ԡС
˥塼ˡԽפƻȤ褦ˤʤޤ
=== ܺ
* ʲλĤΥץ饰ޥɤɲäޤ
* history ڡԽΰɽ
* history_src ӥΥɽ
* history_diff ǤդΥӥ֤κʬɽ
ºݤˤϡ
@conf.cgi_name?c=history;p=FrontPage
@conf.cgi_name?c=plugin;plugin=history_diff;p=FrontPage;r=2
Τ褦˻Ѥޤ
* ˤϥ֥ʤȤˤƤޤ
* Subversion бŬǤ(ͤȤäƤʤΤ)
* ץ饰κˡ褯狼äƤʤΤǡɤʤľƤ
=== history
2003/12/17 Yasuo Itabashi(Yas) Subversionб, ѹսζĴб, Ruby 1.7ʹߤб
=== notice
HikifarmѤƤ硢hiki.conf
@conf.repos_type = (defined? repos_type) ? "#{repos_type}" : nil
ɲäƤ-- Yas
CSSspan.add_line, span.del_lineꤹȡѹսʸ°ѹǤޤ
-- Yas
=== SEE ALSO
* νϷ WiLiKi ԽͤˤƤޤ
http://www.shiro.dreamhost.com/scheme/wiliki/wiliki.cgi
=end
def history
h = Hiki::History::new(@cgi, @db, @conf)
h.history
end
def history_src
h = Hiki::History::new(@cgi, @db, @conf)
h.history_src
end
def history_diff
h = Hiki::History::new(@cgi, @db, @conf)
h.history_diff
end
add_body_enter_proc(Proc::new do
add_plugin_command('history', history_label, {'p' => true})
end)
module Hiki
class History < Command
private
def history_repos_type
@conf.repos_type # 'cvs' or 'svn' or 'svnsingle'
end
def history_repos_root
@conf.repos_root # hiki.conf
end
# Subroutine to invoke external command using `` sequence.
def history_exec_command(cmd_string)
Dir.chdir("#{@db.pages_path}") do
`#{cmd_string.untaint}`
end
end
# Subroutine to output proper HTML for Hiki.
def history_output(s)
# Imported codes from hiki/command.rb::cmd_view()
parser = @conf.parser::new( @conf )
tokens = parser.parse( s )
formatter = @conf.formatter::new( tokens, @db, @plugin, @conf )
@page = Page::new( @cgi, @conf )
data = Util::get_common_data( @db, @plugin, @conf )
@plugin.hiki_menu(data, @cmd)
pg_title = @plugin.page_name(@p)
data[:title] = title( "#{pg_title} - #{history_label}")
data[:view_title] = "#{pg_title} - #{history_label}"
data[:body] = formatter.apply_tdiary_theme(s)
@cmd = 'view' # important!!!
generate_page(data) # private method inherited from Command class
end
def recent_revs(revs, rev)
ind = revs.index(revs.assoc(rev)) || 0
prev_rev = revs[ind + 1]
prev2_rev = revs[ind + 2]
if ind - 1 >= 0
next_rev = revs[ind - 1]
else
next_rev = nil
end
[prev2_rev, prev_rev, revs[ind], next_rev]
end
def diff_link(rev1, rev2, rev_title1, rev_title2, link)
title = []
title << (rev_title1 || (rev1 and rev1[0]) || nil)
title << (rev_title2 || (rev2 and rev2[0]) || nil)
title = title.compact
title.reverse! unless rev2.nil?
title = title.join("<=>").escapeHTML
do_link = (link and rev1)
rv = "["
if do_link
rev_param = "r=#{rev1[0]}"
rev_param << ";r2=#{rev2[0]}" if rev2
rv << %Q[<a href="#{@conf.cgi_name}#{cmdstr('plugin', "plugin=history_diff;p=#{@p.escape};#{rev_param}")}" title="#{title}">]
end
rv << title
if do_link
rv << "</a>"
end
rv << "]\n"
rv
end
public
# Output summary of change history
def history
# parse the result and make revisions array
revs = @conf.repos.revisions(@p)
# construct output sources
prevdiff = 1
sources = ''
sources << @plugin.hiki_anchor(@p.escape, @plugin.page_name(@p))
sources << "\n<br>\n"
sources << "\n<table border=\"1\">\n"
if @conf.options['history.hidelog']
sources << " <tr><th>#{history_th_label[0].escapeHTML}</th><th>#{history_th_label[1].escapeHTML}</th><th>#{history_th_label[2].escapeHTML}</th><th>#{history_th_label[3].escapeHTML}</th></tr>\n"
else
case history_repos_type
when 'cvs'
sources << " <tr><th rowspan=\"2\">#{history_th_label[0].escapeHTML}</th><th>#{history_th_label[1].escapeHTML}</th><th>#{history_th_label[2].escapeHTML}</th><th>#{history_th_label[3].escapeHTML}</th></tr><tr><th colspan=\"3\">#{history_th_label[4].escapeHTML}</th></tr>\n"
else
sources << " <tr><th rowspan=\"2\">#{history_th_label[0].escapeHTML}</th><th>#{history_th_label[1].escapeHTML}</th><th>#{history_th_label[3].escapeHTML}</th></tr><tr><th colspan=\"2\">#{history_th_label[4].escapeHTML}</th></tr>\n"
end
end
revs.each do |rev,time,changes,log|
# time << " GMT"
op = "[<a href=\"#{@conf.cgi_name}#{cmdstr('plugin', "plugin=history_src;p=#{@p.escape};r=#{rev}")}\">View</a> this version] "
if revs.size != 1
op << "[Diff to "
op << "<a href=\"#{@conf.cgi_name}#{cmdstr('plugin', "plugin=history_diff;p=#{@p.escape};r=#{rev}")}\">current</a>" unless prevdiff == 1
op << " | " unless (prevdiff == 1 || prevdiff >= revs.size)
op << "<a href=\"#{@conf.cgi_name}#{cmdstr('plugin', "plugin=history_diff;p=#{@p.escape};r=#{rev};r2=#{revs[prevdiff][0]}")}\">previous</a>" unless prevdiff >= revs.size
op << "]"
end
if @conf.options['history.hidelog']
case history_repos_type
when 'cvs'
sources << " <tr><td>#{rev}</td><td>#{time.escapeHTML}</td><td>#{changes.escapeHTML}</td><td align=right>#{op}</td></tr>\n"
else
sources << " <tr><td>#{rev}</td><td>#{time.escapeHTML}</td><td align=right>#{op}</td></tr>\n"
end
else
log.gsub!(/=============================================================================/, '')
log.chomp!
log = "*** no log message ***" if log.empty?
case history_repos_type
when 'cvs'
sources << " <tr><td rowspan=\"2\">#{rev}</td><td>#{time.escapeHTML}</td><td>#{changes.escapeHTML}</td><td align=right>#{op}</td></tr><tr><td colspan=\"3\">#{log.escapeHTML}</td></tr>\n"
else
sources << " <tr><td rowspan=\"2\">#{rev}</td><td>#{time.escapeHTML}</td><td align=right>#{op}</td></tr><tr><td colspan=\"2\">#{log.escapeHTML}</td></tr>\n"
end
end
prevdiff += 1
end
sources << "</table>\n"
history_output(sources)
end
# Output source at an arbitrary revision
def history_src
# make command string
r = @cgi.params['r'][0] || '1'
txt = @conf.repos.get_revision(@p, r)
txt = "*** no source ***" if txt.empty?
# construct output sources
sources = ''
sources << "<div class=\"section\">\n"
sources << @plugin.hiki_anchor(@p.escape, @plugin.page_name(@p))
sources << "\n<br>\n"
sources << "<a href=\"#{@conf.cgi_name}#{cmdstr('edit', "p=#{@p.escape};r=#{r.escapeHTML}")}\">#{history_revert_label.escapeHTML}</a><br>\n"
sources << "<a href=\"#{@conf.cgi_name}#{cmdstr('plugin', "plugin=history_diff;p=#{@p.escape};r=#{r.escapeHTML}")}\">#{history_diffto_current_label.escapeHTML}</a><br>\n"
sources << "<a href=\"#{@conf.cgi_name}#{cmdstr('history', "p=#{@p.escape}")}\">#{history_backto_summary_label.escapeHTML}</a><br>\n"
sources << "</div>\n"
sources << "<div class=\"diff\">\n"
sources << txt.escapeHTML.gsub(/\n/, "<br>\n").gsub(/ /, ' ')
sources << "</div>\n"
history_output(sources)
end
# Output diff between two arbitrary revisions
def history_diff
# make command string
r = @cgi.params['r'][0] || '1'
r2 = @cgi.params['r2'][0]
if r2.nil? || r2.to_i == 0
new = @db.load(@p)
old = @conf.repos.get_revision(@p, r)
else
new = @conf.repos.get_revision(@p, r)
old = @conf.repos.get_revision(@p, r2)
end
# parse the result and make revisions array
revs = @conf.repos.revisions(@p)
prev2_rev, prev_rev, curr_rev, next_rev = recent_revs(revs, r.to_i)
last_rev = revs[0]
diff = word_diff( old, new )
# construct output sources
sources = ''
sources << "<div class=\"section\">\n"
sources << @plugin.hiki_anchor(@p.escape, @plugin.page_name(@p))
sources << "<br>\n"
sources << "<a href=\"#{@conf.cgi_name}#{cmdstr('plugin', "plugin=history_src;p=#{@p.escape};r=#{curr_rev[0]}")}\">#{history_view_this_version_src_label.escapeHTML}</a><br>\n" if curr_rev
sources << "<a href=\"#{@conf.cgi_name}#{cmdstr('history', "p=#{@p.escape}")}\">#{history_backto_summary_label.escapeHTML}</a><br>\n"
sources << "\n"
if prev_rev
do_link = (last_rev and prev_rev and last_rev[0] != prev_rev[0])
sources << diff_link(prev_rev, nil, nil, "HEAD", do_link)
end
if prev_rev and prev2_rev
sources << diff_link(prev_rev, prev2_rev, nil, nil, true)
end
sources << diff_link(curr_rev, r2.nil? ? nil : prev_rev, nil, nil, false)
if next_rev
sources << diff_link(next_rev, curr_rev, nil, nil, true)
end
do_link = (r2 and last_rev and last_rev[0] != curr_rev[0])
sources << diff_link(curr_rev, nil, nil, "HEAD", do_link)
sources << "</div>\n<br>\n"
sources << "<ul>"
sources << " <li>#{history_add_line_label}</li>"
sources << " <li>#{history_delete_line_label}</li>"
sources << "</ul>"
sources << "<div class=\"diff\">#{diff.gsub(/\n/, "<br>\n")}</div>\n"
history_output(sources)
end
end
end
|