milkode 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.ja.rdoc CHANGED
@@ -1,3 +1,27 @@
1
+ === 1.2.0 2013/08/07
2
+
3
+ * milk web
4
+ * Hightlight filename keywords
5
+ * Not show file infomation when same file name continue
6
+ * Delete auto search feature 'w:0' and 'fp:a b'
7
+ * Bugfix relative URL (clippy, 同名ファイルへのリンク) (thanks nicklegr)
8
+
9
+ * milk
10
+ * milk update
11
+ * Remove ignored files with update
12
+ * milk ignore
13
+ * Support global ignore. 'milk ignore --global ~/.gitignore'
14
+ * milk config
15
+ * Add 'milk config KEY VALUE' command.
16
+ * e.g. 'milk config update_with_ctags_e true'
17
+ * milk remove
18
+ * Faster DocumentTable#remove_records
19
+ * Not remove package non exist filename
20
+ * milk cleanup
21
+ * Add milk cleanup options. -p, -a
22
+ * milk add
23
+ * 'milk add' can't use already exist package
24
+
1
25
  === 1.1.0 2013/06/26
2
26
 
3
27
  * milk web
data/HISTORY.rdoc CHANGED
@@ -1,3 +1,27 @@
1
+ === 1.2.0 2013/08/07
2
+
3
+ * milk web
4
+ * Hightlight filename keywords
5
+ * Not show file infomation when same file name continue
6
+ * Delete auto search feature 'w:0' and 'fp:a b'
7
+ * Bugfix relative URL (clippy, Link for same file name) (thanks nicklegr)
8
+
9
+ * milk
10
+ * milk update
11
+ * Remove ignored files with update
12
+ * milk ignore
13
+ * Support global ignore. 'milk ignore --global ~/.gitignore'
14
+ * milk config
15
+ * Add 'milk config KEY VALUE' command.
16
+ * e.g. 'milk config update_with_ctags_e true'
17
+ * milk remove
18
+ * Faster DocumentTable#remove_records
19
+ * Not remove package non exist filename
20
+ * milk cleanup
21
+ * Add milk cleanup options. -p, -a
22
+ * milk add
23
+ * 'milk add' can't use already exist package
24
+
1
25
  === 1.1.0 2013/06/26
2
26
 
3
27
  * milk web
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
data/bin/gmilk CHANGED
@@ -6,5 +6,5 @@
6
6
  require 'rubygems'
7
7
  require 'milkode/grep/cli_grep'
8
8
 
9
- Version = "1.1.0"
9
+ Version = "1.2.0"
10
10
  Milkode::CLI_Grep.execute(STDOUT, ARGV)
data/bin/milk CHANGED
@@ -6,5 +6,5 @@
6
6
  require 'rubygems'
7
7
  require 'milkode/cli'
8
8
 
9
- Version = "1.1.0"
9
+ Version = "1.2.0"
10
10
  Milkode::CLI.start(ARGV)
@@ -1,42 +1,38 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require 'yaml'
4
- require 'pathname'
5
- require 'rubygems'
6
3
  require 'fileutils'
7
- require 'pathname'
8
- require 'milkode/common/grenfiletest'
9
- require 'milkode/common/util'
10
- require 'milkode/common/dir'
11
- include Milkode
12
4
  require 'kconv'
5
+ require 'open-uri'
6
+ require 'pathname'
7
+ require 'rubygems'
8
+ require 'yaml'
13
9
  begin
14
10
  require 'readline'
15
11
  rescue LoadError
16
12
  $no_readline = true
17
13
  end
18
- require 'open-uri'
19
14
  require 'milkode/cdstk/cdstk_command'
20
- require 'milkode/cdstk/yaml_file_wrapper'
21
15
  require 'milkode/cdstk/package'
16
+ require 'milkode/cdstk/yaml_file_wrapper'
17
+ require 'milkode/common/array_diff'
18
+ require 'milkode/common/dir'
19
+ require 'milkode/common/grenfiletest'
22
20
  require 'milkode/common/ignore_checker'
23
- require 'milkode/database/groonga_database'
21
+ require 'milkode/common/plang_detector'
22
+ require 'milkode/common/util'
24
23
  require 'milkode/database/document_record'
25
- require 'milkode/common/array_diff'
24
+ require 'milkode/database/groonga_database'
26
25
  require 'milkode/database/updater'
27
- require 'milkode/common/plang_detector'
28
26
 
29
27
  module Milkode
30
28
  class IgnoreError < RuntimeError ; end
31
29
  class AddError < RuntimeError ; end
32
30
  class ConvertError < RuntimeError ; end
33
31
 
32
+
34
33
  class Cdstk
35
- # バイグラムでトークナイズする。連続する記号・アルファベット・数字は一語として扱う。
36
- # DEFAULT_TOKENIZER = "TokenBigram"
37
-
38
- # 記号・アルファベット・数字もバイグラムでトークナイズする。
39
- DEFAULT_TOKENIZER = "TokenBigramSplitSymbolAlphaDigit"
34
+ # Parameters
35
+ CONFIG_LJUST = 20 # Display parameter for 'milk config'
40
36
 
41
37
  def initialize(io = $stdout, db_dir = ".")
42
38
  @db_dir = db_dir
@@ -198,28 +194,23 @@ module Milkode
198
194
  update_dir_in(dir)
199
195
  end
200
196
 
201
- # yamlにパッケージを追加
202
197
  def add_yaml(package)
203
- # すでに同名パッケージがある
198
+ # Already exist package
204
199
  if @yaml.find_name(package.name)
205
- warning_alert("already exist '#{package.name}'.")
206
- return
200
+ raise AddError, "package named '#{package.name}' already exist."
207
201
  end
208
202
 
209
- # ファイルが存在しない
203
+ # File not exist
210
204
  unless File.exist?(package.directory)
211
- error_alert("not found '#{package.directory}'.")
212
- return
205
+ raise AddError, "not found '#{package.directory}'."
213
206
  end
214
207
 
215
- # YAML更新
208
+ # Save yaml
216
209
  @yaml.add(package)
217
210
  @yaml.save
218
211
 
219
- # データベースを開く
212
+ # Sync yaml -> db
220
213
  db_open
221
-
222
- # yamlファイルと同期する
223
214
  @grndb.yaml_sync(@yaml.contents)
224
215
  end
225
216
 
@@ -357,7 +348,7 @@ module Milkode
357
348
 
358
349
  unless package
359
350
  path = File.expand_path(arg)
360
- package = @yaml.package_root(path)
351
+ package = @yaml.package_root(path) if File.exist?(path)
361
352
  end
362
353
 
363
354
  if (package)
@@ -520,25 +511,62 @@ module Milkode
520
511
  end
521
512
  end
522
513
 
523
- def cleanup(options)
524
- # cleanup開始
525
- if (options[:force] or yes_or_no("cleanup contents? (yes/no)"))
526
- print_result do
527
- # yamlファイルのクリーンアップ
528
- @yaml.contents.find_all {|v| !File.exist? v.directory }.each do |p|
529
- @yaml.remove(p)
530
- alert("rm_package", p.directory)
531
- @package_count += 1
532
- end
533
- @yaml.save
514
+ def cleanup(args, options)
515
+ update_display_info(options)
534
516
 
535
- # データベースを開く
517
+ if (options[:all])
518
+ cleanup_all(options)
519
+ elsif (options[:packages])
520
+ cleanup_packages
521
+ else
522
+ print_result do
536
523
  db_open
524
+ args.each do |arg|
525
+ package = @yaml.find_name(arg) || @yaml.find_dir(arg)
537
526
 
538
- # yamlファイルと同期する
539
- @grndb.yaml_sync(@yaml.contents)
527
+ unless package
528
+ path = File.expand_path(arg)
529
+ package = @yaml.package_root(path) if File.exist?(path)
530
+ end
531
+
532
+ if (package)
533
+ @documents.cleanup_package_name(package.name) # TODO: Support ignore_checker
534
+ else
535
+ @out.puts "Not found package '#{arg}'."
536
+ return
537
+ end
538
+ end
539
+ end
540
+ end
541
+ end
542
+
543
+ # Remove non exist pakcages
544
+ def cleanup_packages
545
+ print_result do
546
+ cleanup_packages_in
547
+ end
548
+ end
549
+
550
+ def cleanup_packages_in
551
+ @yaml.contents.find_all {|v| !File.exist? v.directory }.each do |p|
552
+ @yaml.remove(p)
553
+ alert("rm_package", p.directory)
554
+ @package_count += 1
555
+ end
556
+ @yaml.save
557
+
558
+ db_open
559
+
560
+ @grndb.yaml_sync(@yaml.contents)
561
+ end
562
+
563
+ def cleanup_all(options)
564
+ if (options[:force] or yes_or_no("cleanup contents? (yes/no)"))
565
+ print_result do
566
+ # Remove non exist packages
567
+ cleanup_packages_in
540
568
 
541
- # データベースのクリーンアップ
569
+ # @todo Remove ignore files
542
570
  @documents.cleanup do |record|
543
571
  alert("rm_record", record.path)
544
572
  @file_count += 1
@@ -889,18 +917,32 @@ EOF
889
917
  r
890
918
  end
891
919
  else
892
- dir = File.expand_path('.')
893
- r = @yaml.package_root(dir)
894
- if r.nil?
895
- @out.puts "Not registered '#{dir}'."
896
- []
897
- else
898
- [r]
899
- end
920
+ [find_package_current_dir].compact
900
921
  end
901
922
  end
902
923
 
924
+ def find_package_current_dir
925
+ dir = File.expand_path('.')
926
+ package = @yaml.package_root(dir)
927
+ @out.puts "Not registered '#{dir}'." if package.nil?
928
+ package
929
+ end
930
+
903
931
  def ignore(args, options)
932
+ if options[:global]
933
+ if args.size > 0
934
+ @yaml.set_global_gitignore(args[0])
935
+ @yaml.save
936
+ @out.puts "Set '#{args[0]}'"
937
+ else
938
+ if @yaml.global_gitignore
939
+ @out.puts @yaml.global_gitignore
940
+ end
941
+ end
942
+
943
+ return
944
+ end
945
+
904
946
  current_dir = File.expand_path('.')
905
947
 
906
948
  if (options[:package])
@@ -978,6 +1020,65 @@ EOF
978
1020
  end
979
1021
  end
980
1022
 
1023
+ def config(args, options)
1024
+ if args.empty?
1025
+ config_print
1026
+ else
1027
+ config_set(args, options)
1028
+ end
1029
+ end
1030
+
1031
+ def config_print
1032
+ package = find_package_current_dir
1033
+
1034
+ return if package.nil?
1035
+
1036
+ @out.puts "Ignore:"
1037
+ package.ignore.each do |v|
1038
+ @out.puts " #{v}"
1039
+ end
1040
+
1041
+ @out.puts "Options:"
1042
+ package.options.each do |key, value|
1043
+ @out.puts " #{(key.to_s + ':').ljust(CONFIG_LJUST)} #{value}"
1044
+ end
1045
+ end
1046
+
1047
+ def config_set(args, options)
1048
+ package = find_package_current_dir
1049
+ return if package.nil?
1050
+
1051
+ opt = package.options
1052
+
1053
+ if options[:delete]
1054
+ opt.delete(args[0].to_sym)
1055
+ else
1056
+ if args.size == 2
1057
+ opt[args[0].to_sym] = config_to_value(args[1])
1058
+ else
1059
+ @out.puts("[usage] milk config KEY VALUE")
1060
+ end
1061
+ end
1062
+
1063
+ package.set_options(opt)
1064
+
1065
+ @yaml.save
1066
+ end
1067
+
1068
+ # config_to_value('true') #=> true
1069
+ # config_to_value('false') #=> false
1070
+ # config_to_value('abc') #=> 'abc'
1071
+ def config_to_value(v)
1072
+ case v
1073
+ when 'true'
1074
+ true
1075
+ when 'false'
1076
+ false
1077
+ else
1078
+ v
1079
+ end
1080
+ end
1081
+
981
1082
  private
982
1083
 
983
1084
  def git_protocol?(options, src)
@@ -1016,16 +1117,23 @@ EOF
1016
1117
  end
1017
1118
 
1018
1119
  def updater_exec(package, is_update_with_git_pull, is_update_with_svn_update, is_no_clean)
1019
- alert("package", package.name )
1120
+ alert("package", package.name)
1020
1121
 
1021
1122
  updater = Updater.new(@grndb, package.name)
1123
+
1124
+ updater.set_global_gitignore(@yaml.global_gitignore) if @yaml.global_gitignore
1022
1125
  updater.set_package_ignore IgnoreSetting.new("/", package.ignore)
1023
1126
  updater.enable_no_auto_ignore if package.options[:no_auto_ignore]
1127
+
1024
1128
  updater.enable_silent_mode if @is_silent
1025
1129
  updater.enable_display_info if @is_display_info
1130
+ updater.enable_no_clean if is_no_clean
1131
+
1026
1132
  updater.enable_update_with_git_pull if is_update_with_git_pull
1027
1133
  updater.enable_update_with_svn_update if is_update_with_svn_update
1028
- updater.enable_no_clean if is_no_clean
1134
+ updater.enable_update_with_ctags if package.options[:update_with_ctags]
1135
+ updater.enable_update_with_ctags_e if package.options[:update_with_ctags_e]
1136
+
1029
1137
  updater.exec
1030
1138
 
1031
1139
  @package_count += 1
@@ -1053,7 +1161,7 @@ EOF
1053
1161
  # データベースからも削除
1054
1162
  # dir = File.expand_path(dir)
1055
1163
 
1056
- alert("rm_package", dir)
1164
+ alert("rm_package", package.name)
1057
1165
  @package_count += 1
1058
1166
 
1059
1167
  @documents.remove_match_path(dir) do |record|
@@ -78,10 +78,13 @@ EOF
78
78
  # 指定ディレクトリの所属するパッケージのルートディレクトリを得る。
79
79
  # 見つからない場合はnilを返す。
80
80
  def package_root(dir)
81
- nd = Util::normalize_filename dir
82
- @contents.find do |v|
83
- v if nd =~ /^#{Regexp.escape(v.directory)}(:?\/|\Z)/
84
- end
81
+ nd = Util::normalize_filename(dir)
82
+
83
+ @contents.find_all {|v|
84
+ nd =~ /^#{Regexp.escape(v.directory)}(:?\/|\Z)/
85
+ }.max_by {|v|
86
+ v.directory.length
87
+ }
85
88
  end
86
89
 
87
90
  # マイグレーション
@@ -100,6 +103,14 @@ EOF
100
103
  end
101
104
  end
102
105
 
106
+ def global_gitignore
107
+ @data['global_gitignore']
108
+ end
109
+
110
+ def set_global_gitignore(filename)
111
+ @data['global_gitignore'] = filename
112
+ end
113
+
103
114
  private
104
115
 
105
116
  def parse_contents
@@ -98,5 +98,13 @@ module Milkode
98
98
  save
99
99
  end
100
100
  end
101
+
102
+ def global_gitignore
103
+ @data.global_gitignore
104
+ end
105
+
106
+ def set_global_gitignore(filename)
107
+ @data.set_global_gitignore(filename)
108
+ end
101
109
  end
102
110
  end
@@ -44,7 +44,7 @@ end
44
44
  get '/' do
45
45
  if Database.validate?
46
46
  @setting = WebSetting.new
47
- @version = "1.1.0"
47
+ @version = "1.2.0"
48
48
 
49
49
  @package_num = Database.instance.yaml_package_num
50
50
  @file_num = Database.instance.totalRecords
@@ -333,7 +333,7 @@ EOF
333
333
 
334
334
  if (result)
335
335
  path2 = path.gsub(/#{suffix}\Z/, result)
336
- " (<a href='#{Mkurl.new(File.join('/home', path2), params).inherit_query_shead}'>#{result}</a>) "
336
+ " (<a href='#{url_for Mkurl.new(File.join('/home', path2), params).inherit_query_shead}'>#{result}</a>) "
337
337
  else
338
338
  ''
339
339
  end
@@ -218,10 +218,18 @@ module Milkode
218
218
 
219
219
  def update_in(package)
220
220
  updater = Updater.new(@grndb, package.name)
221
+
222
+ yaml = yaml_load
223
+
224
+ updater.set_global_gitignore(yaml.global_gitignore) if yaml.global_gitignore
221
225
  updater.set_package_ignore IgnoreSetting.new("/", package.ignore)
222
226
  updater.enable_no_auto_ignore if package.options[:no_auto_ignore]
227
+
223
228
  updater.enable_update_with_git_pull if package.options[:update_with_git_pull]
224
229
  updater.enable_update_with_svn_update if package.options[:update_with_svn_update]
230
+ updater.enable_update_with_ctags if package.options[:update_with_ctags]
231
+ updater.enable_update_with_ctags_e if package.options[:update_with_ctags_e]
232
+
225
233
  updater.exec
226
234
  updater.result
227
235
  end
@@ -63,22 +63,23 @@ module Milkode
63
63
  if @match_records.empty? && recommended_wide_match_range?
64
64
  grep_contents(@q.keywords, DEFAULT_WIDE_MATCH_RANGE)
65
65
 
66
- if @match_records.empty?
67
- grep_contents(@q.keywords, 0)
68
- end
66
+ # 検索範囲0の自動マッチは混乱をまねくのでやめる
67
+ # if @match_records.empty?
68
+ # grep_contents(@q.keywords, 0)
69
+ # end
69
70
  end
70
71
 
71
- # 先頭をファイル名とみなす
72
- if @match_records.empty? && recommended_fpath_or_packages?
73
- # おすすめクエリーに変換
74
- q2 = @q.conv_head_keyword_to_fpath_or_packages
72
+ # 先頭をファイル名とみなす自動マッチは混乱をまねくのでやめる
73
+ # if @match_records.empty? && recommended_fpath_or_packages?
74
+ # # おすすめクエリーに変換
75
+ # q2 = @q.conv_head_keyword_to_fpath_or_packages
75
76
 
76
- # 検索
77
- @records, @total_records = Database.instance.search(q2.keywords, q2.multi_match_keywords, q2.packages, path, q2.fpaths, q2.suffixs, q2.fpath_or_packages, @offset, LIMIT_NUM)
77
+ # # 検索
78
+ # @records, @total_records = Database.instance.search(q2.keywords, q2.multi_match_keywords, q2.packages, path, q2.fpaths, q2.suffixs, q2.fpath_or_packages, @offset, LIMIT_NUM)
78
79
 
79
- # 再grep
80
- grep_contents(q2.keywords, q2.wide_match_range)
81
- end
80
+ # # 再grep
81
+ # grep_contents(q2.keywords, q2.wide_match_range)
82
+ # end
82
83
 
83
84
  # 検索3 : マッチするファイル
84
85
  @match_files = []
@@ -124,6 +125,8 @@ module Milkode
124
125
  # 近接マッチ無効
125
126
  # g << [m]
126
127
  end
128
+
129
+ @prev = nil
127
130
 
128
131
  <<EOF
129
132
  #{recommended_contents}
@@ -311,9 +314,20 @@ EOF
311
314
  coderay.set_range(first_index..last_index)
312
315
 
313
316
  url = @homeurl + record_link(record)
317
+
318
+ path = Util::relative_path(record.shortpath, @path)
319
+
320
+ if path != @prev
321
+ dt = <<EOS
322
+ <dt class='result-record'><a href='#{url + "#n#{coderay.highlight_lines[0]}"}'>#{path}</a>#{result_refinement(record)}</dt>
323
+ EOS
324
+ @prev = path
325
+ else
326
+ dt = " <dt class='result-record-empty'></dt>"
327
+ end
314
328
 
315
329
  <<EOS
316
- <dt class='result-record'><a href='#{url + "#n#{coderay.highlight_lines[0]}"}'>#{Util::relative_path record.shortpath, @path}</a>#{result_refinement(record)}</dt>
330
+ #{dt}
317
331
  <dd>
318
332
  #{coderay.to_html_anchorlink(url)}
319
333
  </dd>
@@ -333,8 +347,11 @@ EOS
333
347
  end
334
348
 
335
349
  def result_record(record)
350
+ filename = Util::relative_path(record.shortpath, @path).to_s
351
+ filename = Util::highlight_keywords(filename, @q.keywords, 'highlight-filename')
352
+
336
353
  <<EOS
337
- <dt class='result-file'>#{file_or_dirimg(true, @suburl)}<a href='#{@homeurl + record_link(record)}'>#{Util::relative_path record.shortpath, @path}</a></dt>
354
+ <dt class='result-file'>#{file_or_dirimg(true, @suburl)}<a href='#{@homeurl + record_link(record)}'>#{filename}</a></dt>
338
355
  EOS
339
356
  end
340
357
 
@@ -78,8 +78,11 @@ EOF
78
78
  end
79
79
 
80
80
  def result_record(record)
81
+ filename = Util::relative_path(record.shortpath, @path).to_s
82
+ filename = Util::highlight_keywords(filename, @q.fpaths + @q.fpath_or_packages, 'highlight-filename')
83
+
81
84
  <<EOS
82
- <dt class='result-file'>#{file_or_dirimg(true, @suburl)}<a href='#{@homeurl + record_link(record)}'>#{Util::relative_path record.shortpath, @path}</a></dt>
85
+ <dt class='result-file'>#{file_or_dirimg(true, @suburl)}<a href='#{@homeurl + record_link(record)}'>#{filename}</a></dt>
83
86
  EOS
84
87
  end
85
88
 
@@ -100,13 +100,13 @@ function clippy_text(text, bgcolor) {
100
100
  ' width="110"' +
101
101
  ' height="14"' +
102
102
  ' id="clippy" >' +
103
- ' <param name="movie" value="/flash/clippy.swf"/>' +
103
+ ' <param name="movie" value="<%= url_for "/flash/clippy.swf" %>"/>' +
104
104
  ' <param name="allowScriptAccess" value="always" />' +
105
105
  ' <param name="quality" value="high" />' +
106
106
  ' <param name="scale" value="noscale" />' +
107
107
  ' <param NAME="FlashVars" value="text=' + text + '">' +
108
108
  ' <param name="bgcolor" value="#FFFFFF">' +
109
- ' <embed src="/flash/clippy.swf"' +
109
+ ' <embed src="<%= url_for "/flash/clippy.swf" %>"' +
110
110
  ' width="110"' +
111
111
  ' height="14"' +
112
112
  ' name="clippy"' +
@@ -139,7 +139,7 @@ function lineno_setup(path, lineno) {
139
139
  // copy text button
140
140
  $("#lineno-path").html(directpath + clippy_text(directpath, '#FFFFFF'));
141
141
  $("#lineno-body").html(n_lineno_dom.html());
142
- $("#lineno-copyall").html("Lineno + Text" + clippy_text(directpath + " " + escapeHTML(n_lineno_dom.text()), '#F5F5F5'));
142
+ $("#lineno-copyall").html("Line No. + Text" + clippy_text(directpath + " " + escapeHTML(n_lineno_dom.text()), '#F5F5F5'));
143
143
  }
144
144
 
145
145
  function open_newtab() {
@@ -42,8 +42,12 @@ div.search-summary {
42
42
 
43
43
  dt.result-record {
44
44
  font-size: 105%;
45
+ margin-top: 5px;
45
46
  }
46
47
 
48
+ dt.result-record-empty {
49
+ margin-top: 5px;
50
+ }
47
51
  dt.result-file {
48
52
  font-size: 95%;
49
53
  }
@@ -264,3 +268,9 @@ label.ui-corner-all {
264
268
  background-position: 0px;
265
269
  }
266
270
 
271
+ /* */
272
+
273
+ .highlight-filename {
274
+ background-color: #d0ff9c;
275
+ }
276
+
data/lib/milkode/cli.rb CHANGED
@@ -83,10 +83,13 @@ EOF
83
83
  cdstk.pwd(options)
84
84
  end
85
85
 
86
- desc "cleanup", "Creanup garbage recoeds"
86
+ desc "cleanup keyword_or_path1 [keyword_or_path2 ...]", "Cleanup garbage records"
87
+ option :all, :type => :boolean, :aliases => '-a', :desc => 'Cleanup all.'
87
88
  option :force, :type => :boolean, :aliases => '-f', :desc => 'Force cleanup.'
88
- def cleanup
89
- cdstk.cleanup(options)
89
+ option :packages, :type => :boolean, :aliases => '-p', :desc => 'Cleanup non exist packages.'
90
+ option :verbose, :type => :boolean, :aliases => '-v', :desc => 'Be verbose.'
91
+ def cleanup(*args)
92
+ cdstk.cleanup(args, options)
90
93
  end
91
94
 
92
95
  desc "rebuild [keyword1 keyword2]", "Rebuild database"
@@ -135,6 +138,7 @@ EOF
135
138
  option :delete, :type => :boolean, :aliases => '-d', :desc => "Delete ignore setting."
136
139
  option :delete_all, :type => :boolean, :desc => "Delete all ignore setting."
137
140
  option :dry_run, :type => :boolean, :aliases => '-n', :desc => "Ignore setting test."
141
+ option :global, :type => :boolean, :desc => "Set global .gitignore file."
138
142
  def ignore(*paths)
139
143
  begin
140
144
  cdstk.ignore(paths, options)
@@ -203,6 +207,23 @@ EOF
203
207
  cdstk.files(args, options)
204
208
  end
205
209
 
210
+ desc "config [options] KEY VALUE", <<EOF
211
+ Config package settings.
212
+
213
+ $ milk coinfig no_auto_ignore true
214
+
215
+ Configs:
216
+ no_auto_ignore # Not add package's .gitignore
217
+ update_with_ctags # Update with 'ctags -R'
218
+ update_with_ctags_e # Update with 'ctags -R -e'
219
+ update_with_git_pull # Update with 'git pull'
220
+ update_with_svn_update # Update with 'svn update'
221
+ EOF
222
+ option :delete, :type => :boolean, :aliases => '-d', :desc => "Delete key."
223
+ def config(*args)
224
+ cdstk.config(args, options)
225
+ end
226
+
206
227
  # --------------------------------------------------------------------------
207
228
 
208
229
  no_tasks do
@@ -5,6 +5,7 @@ require 'fileutils'
5
5
  require 'pathname'
6
6
  require 'kconv'
7
7
  require 'open3'
8
+ require 'strscan'
8
9
 
9
10
  module Milkode
10
11
  module Util
@@ -240,6 +241,28 @@ module Milkode
240
241
  false
241
242
  end
242
243
  end
244
+
245
+ def highlight_keywords(src, keywords, css_class)
246
+ if keywords.empty?
247
+ src
248
+ else
249
+ highlight_keywords_sub(src, keywords, css_class, 0)
250
+ end
251
+ end
252
+
253
+ def highlight_keywords_sub(src, keywords, css_class, index)
254
+ keyword = keywords[index]
255
+
256
+ array = src.split(keyword)
257
+
258
+ if index + 1 <= keywords.size
259
+ array = array.map do |subsrc|
260
+ highlight_keywords_sub(subsrc, keywords, css_class, index + 1)
261
+ end
262
+ end
263
+
264
+ array.join("<span class='#{css_class}'>#{keyword}</span>")
265
+ end
243
266
  end
244
267
  end
245
268
 
@@ -35,34 +35,40 @@ module Milkode
35
35
  end
36
36
 
37
37
  # レコードをまとめて削除する
38
- # 検索結果にマッチしたレコード等をまとめて削除
39
- # 削除前にインデックスを削除し、削除後にインデックスを再度追加してい
40
- # 大量のレコードを削除する場合に高速に動作する
38
+ # 過去の方法
39
+ # 検索結果にマッチしたレコード等をまとめて削除
40
+ # 削除前にインデックスを削除し、削除後にインデックスを再度追加してい
41
+ # 大量のレコードを削除する場合に高速に動作する
42
+ #
43
+ # 現在の方法
44
+ # 上記の方法がかえって遅くなったので元に戻す
45
+ # 普通に速くなった気がする
46
+ #
41
47
  def remove_records(records, &block)
42
- Groonga::Schema.define do |schema|
43
- schema.change_table("terms") do |table|
44
- table.remove_index("documents.path")
45
- table.remove_index("documents.package")
46
- table.remove_index("documents.restpath")
47
- table.remove_index("documents.content")
48
- table.remove_index("documents.suffix")
49
- end
50
- end
48
+ # Groonga::Schema.define do |schema|
49
+ # schema.change_table("terms") do |table|
50
+ # table.remove_index("documents.path")
51
+ # table.remove_index("documents.package")
52
+ # table.remove_index("documents.restpath")
53
+ # table.remove_index("documents.content")
54
+ # table.remove_index("documents.suffix")
55
+ # end
56
+ # end
51
57
 
52
58
  records.each do |record|
53
59
  yield record if block
54
60
  record.key.delete
55
61
  end
56
62
 
57
- Groonga::Schema.define do |schema|
58
- schema.change_table("terms") do |table|
59
- table.index("documents.path", :with_position => true)
60
- table.index("documents.package", :with_position => true)
61
- table.index("documents.restpath", :with_position => true)
62
- table.index("documents.content", :with_position => true)
63
- table.index("documents.suffix", :with_position => true)
64
- end
65
- end
63
+ # Groonga::Schema.define do |schema|
64
+ # schema.change_table("terms") do |table|
65
+ # table.index("documents.path", :with_position => true)
66
+ # table.index("documents.package", :with_position => true)
67
+ # table.index("documents.restpath", :with_position => true)
68
+ # table.index("documents.content", :with_position => true)
69
+ # table.index("documents.suffix", :with_position => true)
70
+ # end
71
+ # end
66
72
  end
67
73
 
68
74
  def initialize(table)
@@ -326,13 +332,13 @@ module Milkode
326
332
  end
327
333
 
328
334
  # 指定されたパッケージのクリーンアップ
329
- def cleanup_package_name(package_name)
335
+ def cleanup_package_name(package_name, ignore_checker = nil)
330
336
  # クリーンアップ対象のファイルを検索
331
337
  result = @table.select { |record| record.package == package_name }
332
338
 
333
- # 存在しないファイルの削除
339
+ # 存在しない&無視ファイルの削除
334
340
  result.each do |r|
335
- unless File.exist? r.path
341
+ if !File.exist?(r.path) || (ignore_checker && ignore_checker.ignore?("/#{r.restpath}"))
336
342
  yield r if block_given?
337
343
  # p r.restpath
338
344
  remove(r.path)
@@ -35,13 +35,28 @@ module Milkode
35
35
  Dir.chdir(@package.directory) { system("svn update") }
36
36
  end
37
37
 
38
+ # Add global .gitignore
39
+ if @options[:global_gitignore]
40
+ add_global_gitignore(@options[:global_gitignore])
41
+ end
42
+
43
+ # update
44
+ update_dir(@package.directory)
45
+
38
46
  # cleanup
39
47
  unless @options[:no_clean]
40
- @grndb.documents.cleanup_package_name(@package_name)
48
+ @grndb.documents.cleanup_package_name(@package_name, @current_ignore)
41
49
  end
42
50
 
43
- # update
44
- update_dir(@package.directory)
51
+ # ctags
52
+ if @options[:update_with_ctags]
53
+ Dir.chdir(@package.directory) { system("ctags -R") }
54
+ end
55
+
56
+ # ctags -e
57
+ if @options[:update_with_ctags_e]
58
+ Dir.chdir(@package.directory) { system("ctags -R -e") }
59
+ end
45
60
 
46
61
  # 更新時刻の更新
47
62
  @grndb.packages.touch(@package_name, :updatetime)
@@ -71,10 +86,22 @@ module Milkode
71
86
  @options[:update_with_svn_update] = true
72
87
  end
73
88
 
89
+ def enable_update_with_ctags
90
+ @options[:update_with_ctags] = true
91
+ end
92
+
93
+ def enable_update_with_ctags_e
94
+ @options[:update_with_ctags_e] = true
95
+ end
96
+
74
97
  def enable_no_clean
75
98
  @options[:no_clean] = true
76
99
  end
77
100
 
101
+ def set_global_gitignore(filename)
102
+ @options[:global_gitignore] = filename
103
+ end
104
+
78
105
  class Result
79
106
  attr_reader :file_count
80
107
  attr_reader :add_count
@@ -227,6 +254,14 @@ module Milkode
227
254
  end
228
255
  end
229
256
 
257
+ def add_global_gitignore(filename)
258
+ if File.exist? filename
259
+ alert_info("add_ignore", filename)
260
+ str = Util::load_content($stdout, filename)
261
+ @current_ignore.add IgnoreSetting.create_from_gitignore("/", str)
262
+ end
263
+ end
264
+
230
265
  def alert_info(title, msg)
231
266
  alert(title, msg) if @options[:display_info]
232
267
  end
data/milkode.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{milkode}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ongaeshi"]
12
- s.date = %q{2013-06-26}
12
+ s.date = %q{2013-08-07}
13
13
  s.description = %q{Line based local source code search engine & grep-command & web-app.}
14
14
  s.email = %q{ongaeshi0621@gmail.com}
15
15
  s.executables = ["gmilk", "milk"]
data/test/test_cdstk.rb CHANGED
@@ -32,8 +32,8 @@ class TestCdstk < Test::Unit::TestCase
32
32
  obj.init({})
33
33
 
34
34
  io.puts('--- add ---')
35
- obj.add(['../../lib/milkode/findgrep', '../../lib/milkode/common'], {})
36
- obj.add(['../../lib/milkode/findgrep'], {})
35
+ obj.add(['../../lib/milkode/grep', '../../lib/milkode/common'], {})
36
+ obj.add(['../../lib/milkode/grep'], {})
37
37
  obj.add(['../data/abc.zip'], {})
38
38
  obj.add(['../data/nodir_abc.zip'], {})
39
39
  obj.add(['../data/nodir_abc_xpi.xpi'], {})
@@ -80,7 +80,7 @@ class TestCdstk < Test::Unit::TestCase
80
80
  obj.list(['com'], {:verbose => false})
81
81
 
82
82
  io.puts('--- cleanup ---')
83
- obj.cleanup({:force=>true})
83
+ obj.cleanup([], {:force=>true})
84
84
 
85
85
  io.puts('--- rebuild ---')
86
86
  obj.rebuild([], {:all => true})
@@ -190,4 +190,31 @@ EOF
190
190
  assert_equal nil , obj.package_root('/hoge/a/dir1/dir3')
191
191
  assert_equal '/path/to/dir', obj.package_root('/path/to/dir').directory
192
192
  end
193
+
194
+ def test_global_gitignore_empty
195
+ obj = MilkodeYaml.new(SRC)
196
+ assert_equal nil, obj.global_gitignore
197
+ end
198
+
199
+ def test_global_gitignore_read
200
+ obj = MilkodeYaml.new(<<EOF)
201
+ ---
202
+ version: '0.2'
203
+ global_gitignore: '/path/to/.gitignore'
204
+ contents:
205
+ - directory: /a/dir1
206
+ EOF
207
+
208
+ assert_equal '/path/to/.gitignore', obj.global_gitignore
209
+ end
210
+
211
+ def test_global_gitignore_set
212
+ # set
213
+ obj = MilkodeYaml.new(SRC)
214
+ obj.set_global_gitignore('/path/to/.gitignore')
215
+
216
+ # reload
217
+ obj = MilkodeYaml.new(obj.dump)
218
+ assert_equal '/path/to/.gitignore', obj.global_gitignore
219
+ end
193
220
  end
data/test/test_updater.rb CHANGED
@@ -107,8 +107,7 @@ module Milkode
107
107
  updater = Updater.new(@grndb, 'ignore_test')
108
108
  updater.enable_no_auto_ignore
109
109
  updater.exec
110
- # result_test updater.result, 6, 2, 0
111
- result_test updater.result, 5, 1, 0
110
+ result_test updater.result, 5, 4, 0
112
111
  end
113
112
 
114
113
  def t_silent_mode
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - ongaeshi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-26 00:00:00 +09:00
18
+ date: 2013-08-07 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency