script to retroactively add commitids to past openbsd commits
at master 87 lines 3.6 kB view raw
1# 2# Copyright (c) 2014, 2016 joshua stein <jcs@jcs.org> 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions 6# are met: 7# 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. The name of the author may not be used to endorse or promote products 14# derived from this software without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27 28require "sqlite3" 29 30class Db 31 def initialize(dbf) 32 @db = SQLite3::Database.new dbf 33 @db.results_as_hash = true 34 35 @db.execute "CREATE TABLE IF NOT EXISTS changesets 36 (id INTEGER PRIMARY KEY, date INTEGER, author TEXT, commitid TEXT, 37 log TEXT, branch TEXT, csorder INTEGER)" 38 @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_cs_commitid ON changesets 39 (commitid)" 40 @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_cs_csorder ON changesets 41 (csorder)" 42 @db.execute "CREATE INDEX IF NOT EXISTS cs_branch ON changesets (branch)" 43 44 @db.execute "CREATE TABLE IF NOT EXISTS files 45 (id INTEGER PRIMARY KEY, file TEXT, first_undead_version TEXT, 46 cksum TEXT)" 47 @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_f_file ON files 48 (file)" 49 50 @db.execute "CREATE TABLE IF NOT EXISTS revisions 51 (id INTEGER PRIMARY KEY, file_id INTEGER, changeset_id INTEGER, 52 date INTEGER, version TEXT, author TEXT, commitid TEXT, log TEXT, 53 state TEXT, branch TEXT)" 54 @db.execute "CREATE UNIQUE INDEX IF NOT EXISTS u_r_revision ON revisions 55 (file_id, version)" 56 @db.execute "CREATE INDEX IF NOT EXISTS r_empty_changesets ON revisions 57 (changeset_id)" 58 @db.execute "CREATE INDEX IF NOT EXISTS r_cs_by_commitid ON revisions 59 (commitid, changeset_id)" 60 @db.execute "CREATE INDEX IF NOT EXISTS r_all_revs_by_author ON revisions 61 (author, date)" 62 @db.execute "CREATE INDEX IF NOT EXISTS r_all_revs_by_version_and_state ON 63 revisions (version, state)" 64 @db.execute "CREATE INDEX IF NOT EXISTS r_branch ON revisions (branch)" 65 66 @db.execute("CREATE TABLE IF NOT EXISTS vendor_branches 67 (id INTEGER PRIMARY KEY, revision_id INTEGER, branch TEXT)") 68 @db.execute("CREATE INDEX IF NOT EXISTS vb_revision ON vendor_branches 69 (revision_id)") 70 @db.execute("CREATE INDEX IF NOT EXISTS vb_branch_branch ON vendor_branches 71 (branch)") 72 end 73 74 def execute(*args) 75 if block_given? 76 @db.execute(*args) do |row| 77 yield row 78 end 79 else 80 @db.execute(*args) 81 end 82 end 83 84 def last_insert_row_id 85 @db.last_insert_row_id 86 end 87end