- Patch so that irb saves its history (bug 518584, ruby issue 1556)

This commit is contained in:
Mamoru Tasaka 2009-10-25 15:16:49 +00:00
parent 9b01046539
commit de154d4802
2 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,111 @@
Thu Jul 23 15:04:20 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
ruby* lib/irb.rb, lib/irb/init.rb, lib/irb/ext/save-history.rb: add
ruby IRB::irb_at_exit. no use finalizer saving history. [ruby-dev-38563]
Index: lib/irb/ext/save-history.rb
===================================================================
--- lib/irb/ext/save-history.rb (revision 24225)
+++ lib/irb/ext/save-history.rb (revision 24254)
@@ -50,23 +50,24 @@
module HistorySavingAbility
include Readline
- def HistorySavingAbility.create_finalizer
- proc do
- if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
- if hf = IRB.conf[:HISTORY_FILE]
- file = File.expand_path(hf)
- end
- file = IRB.rc_file("_history") unless file
- open(file, 'w' ) do |f|
- hist = HISTORY.to_a
- f.puts(hist[-num..-1] || hist)
- end
- end
- end
- end
+# def HistorySavingAbility.create_finalizer
+# proc do
+# if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
+# if hf = IRB.conf[:HISTORY_FILE]
+# file = File.expand_path(hf)
+# end
+# file = IRB.rc_file("_history") unless file
+# open(file, 'w' ) do |f|
+# hist = HISTORY.to_a
+# f.puts(hist[-num..-1] || hist)
+# end
+# end
+# end
+# end
def HistorySavingAbility.extended(obj)
- ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
+# ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
+ IRB.conf[:AT_EXIT].push proc{obj.save_history}
obj.load_history
obj
end
@@ -80,6 +81,19 @@
end
end
end
+
+ def save_history
+ if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
+ if history_file = IRB.conf[:HISTORY_FILE]
+ history_file = File.expand_path(history_file)
+ end
+ history_file = IRB.rc_file("_history") unless history_file
+ open(history_file, 'w' ) do |f|
+ hist = HISTORY.to_a
+ f.puts(hist[-num..-1] || hist)
+ end
+ end
+ end
end
end
Index: lib/irb/init.rb
===================================================================
--- lib/irb/init.rb (revision 24225)
+++ lib/irb/init.rb (revision 24254)
@@ -114,6 +114,8 @@
# @CONF[:LC_MESSAGES] = "en"
@CONF[:LC_MESSAGES] = Locale.new
+ @CONF[:AT_EXIT] = []
+
@CONF[:DEBUG_LEVEL] = 1
end
Index: lib/irb.rb
===================================================================
--- lib/irb.rb (revision 24225)
+++ lib/irb.rb (revision 24254)
@@ -65,13 +65,21 @@
trap("SIGINT") do
irb.signal_handle
end
-
- catch(:IRB_EXIT) do
- irb.eval_input
+
+ begin
+ catch(:IRB_EXIT) do
+ irb.eval_input
+ end
+ ensure
+ irb_at_exit
end
# print "\n"
end
+ def IRB.irb_at_exit
+ @CONF[:AT_EXIT].each{|hook| hook.call}
+ end
+
def IRB.irb_exit(irb, ret)
throw :IRB_EXIT, ret
end

View File

@ -16,7 +16,7 @@
Name: ruby
Version: %{rubyver}%{?dotpatchlevel}
Release: 2%{?dist}
Release: 3%{?dist}
License: Ruby or GPLv2
URL: http://www.ruby-lang.org/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -45,6 +45,8 @@ Patch27: ruby-1.8.6-p287-CVE-2008-5189.patch
Patch28: ruby-1.8.6-p287-remove-ssl-rand-range.patch
Patch29: ruby-always-use-i386.patch
Patch31: ruby-1.8.6-p369-ri-gem_multipath.patch
# Patch from ruby_1_8 branch
Patch32: ruby-1.8head-irb-save-history.patch
Summary: An interpreter of object-oriented scripting language
Group: Development/Languages
@ -175,6 +177,7 @@ pushd %{name}-%{arcver}
%patch28 -p1
%patch29 -p1
%patch31 -p1
%patch32 -p0
popd
%build
@ -537,6 +540,9 @@ rm -rf $RPM_BUILD_ROOT
%{_emacs_sitestartdir}/ruby-mode-init.el
%changelog
* Sun Oct 25 2009 Mamoru Tasaka <mtasaka@ioa.s.u-tokyo.ac.jp> - 1.8.6.383-3
- Patch so that irb saves its history (bug 518584, ruby issue 1556)
* Sat Oct 24 2009 Mamoru Tasaka <mtasaka@ioa.s.u-tokyo.ac.jp> - 1.8.6.383-2
- Restore the previous changes