script to retroactively add commitids to past openbsd commits
1#!/usr/bin/env ruby
2#
3# Copyright (c) 2014, 2016 joshua stein <jcs@jcs.org>
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# 3. The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29PWD = File.realpath(File.dirname(__FILE__))
30
31require PWD + "/lib/db"
32require PWD + "/lib/scanner"
33require PWD + "/lib/rcsfile"
34require PWD + "/lib/rcsrevision"
35require PWD + "/lib/outputter"
36
37CVSROOT = "/var/cvs-commitid/"
38CVSTMP = "/var/cvs-tmp/"
39CVSTREES = [ "CVSROOT", "src", "ports", "www", "xenocara" ]
40
41GENESIS = "01-14f762f4672bf0b4c0899cd15e1acdcb978a688b3c939111ed13d1958c6a2706-0000000"
42
43File.write(PWD + "/out/commitid_genesis", "#{GENESIS}\n")
44
45CVSTREES.each do |tree|
46 if !Dir.exists?("#{CVSROOT}/#{tree}")
47 next
48 end
49
50 sc = Scanner.new(PWD + "/db/openbsd-#{tree}.db", "#{CVSROOT}/#{tree}/")
51
52 if tree == "src"
53 # these revisions didn't get proper commitids with the others in the
54 # changeset, so fudge them
55 sc.commitid_hacks = {
56 "sys/dev/pv/xenvar.h,v" => {
57 "1.1" => "Ij2SOB19ATTH0yEx",
58 "1.2" => "pq3FAYuwXteAsF4d",
59 "1.3" => "C8vFI0RNH9XPJUKs",
60 },
61 "usr.bin/mg/theo.c,v" => {
62 "1.144" => "gSveQVkxMLs6vRqK",
63 "1.145" => "GbEBL4CfPvDkB8hj",
64 "1.146" => "8rkHsVfUx5xgPXRB",
65 },
66 }
67
68 # some rcs files have manually edited history that we need to work around
69 sc.prev_revision_hacks = {
70 # initial history gone?
71 "sbin/isakmpd/pkcs.c,v" => { "1.4" => "0" },
72 # 1.6 gone
73 "sys/arch/sun3/sun3/machdep.c,v" => { "1.7" => "1.5" },
74 }
75 end
76if false
77 # walk the directory of RCS files, create a "files" record for each one,
78 # then run `rlog` on it and create a "revisions" record for each
79 sc.recursively_scan
80
81 # group revisions into changesets by date/author/message, or for newer
82 # commits, their stored commitid
83 sc.group_into_changesets
84
85 # make sure every revision is accounted for
86 sc.stray_commitids_to_changesets
87
88 # assign a canonical date/message/order to each changeset
89 sc.fill_in_changeset_data
90
91 # check out the cvs tree in CVSTMP/tree and place each dead-1.1 file at its
92 # initial non-dead revision found during `rlog`
93 sc.stage_tmp_cvs(CVSTMP, CVSROOT, tree)
94
95 # calculate a hash for each commit by running 'cvs show' on it, and store it
96 # in the commitids-{tree} file
97 sc.recalculate_commitids(CVSTMP, CVSROOT, tree, GENESIS)
98end
99 # output a shell script to add/change all of the commitids in a clean repo
100 sc.outputter.dup_script(f = File.open(PWD +
101 "/out/add_commitids_to_#{tree}.sh", "w+"), tree)
102 f.close
103
104 system("cp", "-f", CVSROOT + "/CVSROOT/commitids-#{tree}",
105 PWD + "/out/commitids-#{tree}")
106end