script to retroactively add commitids to past openbsd commits

move db code to a Db class, move classes to lib/

+48 -33
+45
lib/db.rb
··· 1 + require "sqlite3" 2 + 3 + class Db 4 + def initialize(dbf) 5 + @db = SQLite3::Database.new dbf 6 + 7 + @db.execute "CREATE TABLE IF NOT EXISTS changesets 8 + (id INTEGER PRIMARY KEY, date INTEGER, author TEXT, commitid TEXT, 9 + log TEXT)" 10 + @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_commitid ON changesets 11 + (commitid)" 12 + 13 + @db.execute "CREATE TABLE IF NOT EXISTS files 14 + (id INTEGER PRIMARY KEY, file TEXT, first_undead_version TEXT)" 15 + @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_file ON files 16 + (file)" 17 + 18 + @db.execute "CREATE TABLE IF NOT EXISTS revisions 19 + (id INTEGER PRIMARY KEY, file_id INTEGER, changeset_id INTEGER, 20 + date INTEGER, version TEXT, author TEXT, commitid TEXT, log TEXT, 21 + state TEXT)" 22 + @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_revision ON revisions 23 + (file_id, version)" 24 + @db.execute "CREATE INDEX IF NOT EXISTS empty_changesets ON revisions 25 + (changeset_id)" 26 + @db.execute "CREATE INDEX IF NOT EXISTS cs_by_commitid ON revisions 27 + (commitid, changeset_id)" 28 + @db.execute "CREATE INDEX IF NOT EXISTS all_revs_by_author ON revisions 29 + (author, date)" 30 + @db.execute "CREATE INDEX IF NOT EXISTS all_revs_by_version_and_state ON 31 + revisions (version, state)" 32 + 33 + @db.results_as_hash = true 34 + end 35 + 36 + def execute(*args) 37 + if block_given? 38 + @db.execute(*args) do |row| 39 + yield row 40 + end 41 + else 42 + @db.execute(*args) 43 + end 44 + end 45 + end
+2 -1
openbsd-commitid.rb
··· 1 1 #!/usr/bin/env ruby 2 2 3 - $:.push "." 3 + $:.push "./lib" 4 4 5 + require "db" 5 6 require "scanner" 6 7 require "rcsfile" 7 8 require "rcsrevision"
rcsfile.rb lib/rcsfile.rb
rcsrevision.rb lib/rcsrevision.rb
+1 -32
scanner.rb lib/scanner.rb
··· 1 - require "sqlite3" 2 - 3 1 class Scanner 4 2 def initialize(dbf, root) 5 - @db = SQLite3::Database.new dbf 6 - 7 - @db.execute "CREATE TABLE IF NOT EXISTS changesets 8 - (id INTEGER PRIMARY KEY, date INTEGER, author TEXT, commitid TEXT, 9 - log TEXT)" 10 - @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_commitid ON changesets 11 - (commitid)" 12 - 13 - @db.execute "CREATE TABLE IF NOT EXISTS files 14 - (id INTEGER PRIMARY KEY, file TEXT, first_undead_version TEXT)" 15 - @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_file ON files 16 - (file)" 17 - 18 - @db.execute "CREATE TABLE IF NOT EXISTS revisions 19 - (id INTEGER PRIMARY KEY, file_id INTEGER, changeset_id INTEGER, 20 - date INTEGER, version TEXT, author TEXT, commitid TEXT, log TEXT, 21 - state TEXT)" 22 - @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_revision ON revisions 23 - (file_id, version)" 24 - @db.execute "CREATE INDEX IF NOT EXISTS empty_changesets ON revisions 25 - (changeset_id)" 26 - @db.execute "CREATE INDEX IF NOT EXISTS cs_by_commitid ON revisions 27 - (commitid, changeset_id)" 28 - @db.execute "CREATE INDEX IF NOT EXISTS all_revs_by_author ON revisions 29 - (author, date)" 30 - @db.execute "CREATE INDEX IF NOT EXISTS all_revs_by_version_and_state ON 31 - revisions (version, state)" 32 - 33 - @db.results_as_hash = true 34 - 3 + @db = Db.new dbf 35 4 @root = (root + "/").gsub(/\/\//, "/") 36 5 end 37 6