
https://svn.lrde.epita.fr/svn/lrdetools/trunk Index: ChangeLog from Nicolas Pouillard <ertai@lrde.epita.fr> Files categories: closer to GNU Arch. * vcs/lib/vcs/app.rb: Add grab_dirs, factor user_configuration_setup and vcs_extensions_setup. * vcs/lib/vcs/vcs.rb: Add Vcs.classify, Vcs.merge_user_conf, and a default configuration. * vcs/lib/vcs/status.rb: Handle precious files, and factor with Vcs.classify. * vcs/lib/vcs/form.rb: Typo. * vcs/lib/vcs/diff.rb, vcs/lib/vcs/changelog.rb: Adapt to the new version of from_status. * vcs/NEWS: Adapt. NEWS | 27 ++++++++++++++++----------- lib/vcs/app.rb | 25 ++++++++++++++++--------- lib/vcs/changelog.rb | 4 ++-- lib/vcs/diff.rb | 2 +- lib/vcs/form.rb | 2 +- lib/vcs/status.rb | 26 +++++++++++++++----------- lib/vcs/vcs.rb | 35 +++++++++++++++++++++++++---------- 7 files changed, 76 insertions(+), 45 deletions(-) Index: vcs/lib/vcs/form.rb --- vcs/lib/vcs/form.rb (revision 236) +++ vcs/lib/vcs/form.rb (working copy) @@ -50,7 +50,7 @@ |title: |subject: #{@@subject_format}. | - |--- | ###################### Your ChangeLog entrie ############## 80c| # | --- + |--- | ###################### Your ChangeLog entry ############### 80c| # | --- |<%= title %>. | |".head_cut! Index: vcs/lib/vcs/app.rb --- vcs/lib/vcs/app.rb (revision 236) +++ vcs/lib/vcs/app.rb (working copy) @@ -75,23 +75,30 @@ Vcs.default ||= vcs_type end - def vcs_extensions_setup - dir = Pathname.pwd - while not dir.root? and not (vcs_dir = dir + 'vcs').exist? - dir = dir + '..' + def grab_dirs ( basename, dir=Pathname.pwd ) + results = [] + while not dir.root? + path = dir + basename + results << path if path.exist? + dir = dir.parent + end + path = ENV['HOME'].to_path/basename + results << path if path.exist? and not results.include? path + results end + + def vcs_extensions_setup + grab_dirs('vcs').each do |vcs_dir| vcs_dir = vcs_dir.expand_path vcs_dir.load_path! extension_dirs << vcs_dir + end VcsApp.requirements() end def user_configuration_setup - home = ENV['HOME'].to_path - vcs_user_conf = home/'.vcsrc' - if vcs_user_conf.exist? - Vcs.user_conf = OpenStruct.new(YAML.load(vcs_user_conf.read)) - Vcs.color = Vcs.user_conf.color.to_sym unless Vcs.user_conf.color.nil? + grab_dirs('.vcs').each do |vcs_user_conf| + Vcs.merge_user_conf(vcs_user_conf) end end Index: vcs/lib/vcs/changelog.rb --- vcs/lib/vcs/changelog.rb (revision 236) +++ vcs/lib/vcs/changelog.rb (working copy) @@ -23,9 +23,9 @@ return @@entries[args] if @@entries.has_key? args @@entries[args] = result = [] from_status(*args) do |line, file_st, prop_st, copy_st, file| - next if file_st =~ /[?X\\,]/ + next if file_st.chr =~ /[?X\\,+]/ next if file.to_s == 'ChangeLog' - ls = [@@file_st[file_st[0]], @@prop_st[prop_st[0]]].compact! + ls = [@@file_st[file_st], @@prop_st[prop_st]].compact! ls.first.capitalize! unless ls.empty? result << [file, ls.join(', ')] end Index: vcs/lib/vcs/diff.rb --- vcs/lib/vcs/diff.rb (revision 236) +++ vcs/lib/vcs/diff.rb (working copy) @@ -25,7 +25,7 @@ def diffw! ( *args ) files = Set.new from_status(*args) do |line, file_st, prop_st, cpy, file| - next if file_st =~ /[?X\\,D]/ + next if file_st.chr =~ /[?X\\,+D]/ next if file.to_s == 'ChangeLog' next if file.directory? files << file Index: vcs/NEWS --- vcs/NEWS (revision 236) +++ vcs/NEWS (working copy) @@ -12,19 +12,24 @@ with `commit_' or `ci_'. * Status & User Configuration File: - >>>> ~/.vcsrc <<<< + All .vcs files between your current path and root will be honored. + Example of configuration file. + >>>> ~/.vcs <<<< --- - global_ignore: - - !re ,messages - - !re .*\.(diff|patch)$ - global_unmask: - - !re \bdoc - >>>> ~/.vcsrc <<<< + exclude: # Excluded Files: + - !re ,messages # not displayed (default ^-.*$) + + unmask: # Unmasked Files: + - !re \bdoc # displayed with a `\' (default ^\\.*$) - - During a status files which match global_ignore regexps will not be - printed. - - Files which match global_unmask are prepend by 'U' - - Files which begins by `,' (vcs internal use) are prepend by ',' + precious: # Precious Files: + - !re .*\.(diff|patch)$ # displayed with a `+' (default ^\+.*$) + # .vcs files are also treat as precious + + junk: # Junk Files: + - !re ... # displayed with a `,' (default ^,.*$) + + >>>> ~/.vcsrc <<<< * Color: - Status: the status output is now colored depending of the meaning of Index: vcs/lib/vcs/vcs.rb --- vcs/lib/vcs/vcs.rb (revision 236) +++ vcs/lib/vcs/vcs.rb (working copy) @@ -30,14 +30,18 @@ # class Vcs @@version ||= '0.3.0' - @@user_conf ||= OpenStruct.new - @@color ||= :auto + @@user_conf ||= OpenStruct.new( + :exclude => [/^-/], + :unmask => [/^\\/], + :junk => [/^,/], + :precious => [/^(\+|\.vcs)/], + :color => :auto + ) @@output_io_methods ||= %w[ print puts putc ] # FIXME and so ... cattr_accessor :version cattr_accessor :default cattr_accessor :user_conf - cattr_accessor :color cattr_accessor :output_io_methods class Failure < Exception @@ -353,21 +357,32 @@ @@checkers << (block.nil?)? meth : block end - def match ( regexps, file ) + def user_conf_match ( sym, file ) + if user_conf.nil? or (regexps = user_conf.send(sym)).nil? + return false + end regexps.each do |re| return true if re.match(file) end return false end - def user_conf_global_ignore ( file ) - return false if user_conf.nil? or user_conf.global_ignore.nil? - match(user_conf.global_ignore, file) + def classify ( file ) + [:precious, :unmask, :exclude, :junk].each do |category| + return category if Vcs.user_conf_match(category, file) + end + return :unrecognize + end + + def merge_user_conf ( conf ) + conf = YAML.load(conf.read) if conf.is_a? Pathname + conf.each do |k, v| + user_conf.send("#{k}=", (v.is_a? Array)? ((user_conf.send(k) || []) + v) : v.to_s.to_sym) + end end - def user_conf_global_unmask ( file ) - return false if user_conf.nil? or user_conf.global_unmask.nil? - match(user_conf.global_unmask, file) + def color + user_conf.color end # Here we can handle version conflicts with vcs extensions Index: vcs/lib/vcs/status.rb --- vcs/lib/vcs/status.rb (revision 236) +++ vcs/lib/vcs/status.rb (working copy) @@ -7,23 +7,26 @@ class Svn + @@category_symbol = + { + :precious => ?+, + :unmask => ?\\, + :junk => ?, + } + def from_status ( *args, &block ) status_(*args).each_line do |line| next unless line =~ /^.{5} / m = /^(.)(.)(.)(.)(.\s*)(.*)$/.match(line) line, file_st, bl1, prop_st, cpy, bl2, file = m.to_a file = file.to_path - if file_st == '?' - if Vcs.user_conf_global_ignore(file) - # nothing ... - next - elsif Vcs.user_conf_global_unmask(file) - file_st = '\\' - elsif file.basename.to_s =~ /^,/ - file_st = ',' - end + file_st, prop_st, cpy = file_st[0], prop_st[0], cpy[0] + if file_st == ?? + category = Vcs.classify(file) + next if category == :exclude + file_st = @@category_symbol[category] || file_st end - line = "#{file_st}#{bl1}#{prop_st}#{cpy}#{bl2}#{file}" + line = "#{file_st.chr}#{bl1}#{prop_st.chr}#{cpy.chr}#{bl2}#{file}" block[line, file_st, prop_st, cpy, file] end end @@ -31,7 +34,7 @@ def color_status! ( *args ) from_status(*args) do |line, file_st, prop_st, cpy, file| - line[0] = @h.color(file_st, *@@style[file_st[0]]) + line[0] = @h.color(file_st.chr, *@@style[file_st]) puts line end end @@ -54,6 +57,7 @@ ?M => [:GREEN], ?\\ => [:YELLOW], ?, => [:YELLOW], + ?+ => [:YELLOW], ?G => [:BLUE], ?D => [:MAGENTA], ?R => [:MAGENTA],