среда, 20 февраля 2008 г.

Долой баги из svn-dump'ов

SOURCE_FILE = 'dmp.bin'
CUTTED_FILE = 'dmp_cutted.txt'

cutarray = [
  [1433, 'Editors/TMMatEditor/Res/preview.bmp'],
  [1621, 'Editors/TMMatEditor/Res/Toolbar.bmp']
]

File.open(SOURCE_FILE, 'r'){|f|
  File.open(CUTTED_FILE, 'w'){ |tf|
    f.binmode
    tf.binmode

    cntr = 0
    curr_rev = 0
    skip_node = false
    header = true
    node_text = ''
    while !f.eof?
      if header
        5.times do
          tf.puts(f.gets)
        end
        header = false
      end
      ln = f.gets
      node_text += ln
      if ln[':']
        n,v = ln.split(': ')
        if (n == 'Content-length')
          if skip_node
            puts " skipping content "
            node_text = ''
            f.read(v.to_i + 1)
            cntr += 1
          else
            tf.puts node_text
            node_text = ''
            tf.write(f.read(v.to_i + 1))
          end
        elsif n == 'Revision-number'
          skip_node = false
          curr_rev = v.to_i
          print  " #{curr_rev}"
        elsif n == 'Node-path'
          skip_node = false
          cutarray.each{ |c|
            skip_node = true if (c[0] == curr_rev) and (v.chomp == c[1])
          }
        end
      end
    end

    puts "\nNodes cutted: #{cntr}"
  }
}

Комментариев нет: