tangled
alpha
login
or
join now
jcs.org
/
openbsd-commitid
0
fork
atom
script to retroactively add commitids to past openbsd commits
0
fork
atom
overview
issues
pulls
pipelines
move output functions into a separate class
jcs.org
11 years ago
65994f12
f6009b49
+145
-136
3 changed files
expand all
collapse all
unified
split
lib
outputter.rb
scanner.rb
openbsd-commitid.rb
+139
lib/outputter.rb
···
1
1
+
class Outputter
2
2
+
def initialize(scanner)
3
3
+
@scanner = scanner
4
4
+
end
5
5
+
6
6
+
def changelog(domain, fh)
7
7
+
last = {}
8
8
+
files = []
9
9
+
10
10
+
printlog = Proc.new {
11
11
+
fh.puts "Changes by: #{last["author"]}@#{domain} " <<
12
12
+
Time.at(last["date"].to_i).strftime("%Y/%m/%d %H:%M:%S")
13
13
+
fh.puts "Commitid: #{last["commitid"]}"
14
14
+
fh.puts ""
15
15
+
fh.puts "Modified files:"
16
16
+
17
17
+
# group files by directory
18
18
+
dirs = {}
19
19
+
files.each do |f|
20
20
+
dir = f.split("/")
21
21
+
file = dir.pop.gsub(/,v$/, "")
22
22
+
23
23
+
if dir.length == 0
24
24
+
dir = "."
25
25
+
else
26
26
+
dir = dir.join("/")
27
27
+
end
28
28
+
29
29
+
dirs[dir] ||= []
30
30
+
if !dirs[dir].include?(file)
31
31
+
dirs[dir].push file
32
32
+
end
33
33
+
end
34
34
+
35
35
+
# print padded and wrapped directory and file lines
36
36
+
dirs.each do |dir,fs|
37
37
+
dl = " #{dir}"
38
38
+
if dir.length < 15
39
39
+
(15 - dir.length).times do
40
40
+
dl += " "
41
41
+
end
42
42
+
end
43
43
+
dl += ":"
44
44
+
fl = (72 - dl.length)
45
45
+
cl = dl
46
46
+
(fs.count + 1).times do
47
47
+
if (f = fs.shift)
48
48
+
if cl.length + f.length > 72
49
49
+
fh.puts cl.gsub(/[ ]{8}/, "\t")
50
50
+
cl = " " * dl.length
51
51
+
end
52
52
+
53
53
+
cl += " " + f
54
54
+
else
55
55
+
fh.puts cl.gsub(/[ ]{8}/, "\t")
56
56
+
break
57
57
+
end
58
58
+
end
59
59
+
end
60
60
+
61
61
+
fh.puts ""
62
62
+
fh.puts "Log message:"
63
63
+
fh.puts last["log"]
64
64
+
fh.puts ""
65
65
+
fh.puts ""
66
66
+
}
67
67
+
68
68
+
@scanner.db.execute("SELECT
69
69
+
changesets.date, changesets.author, changesets.commitid, changesets.log,
70
70
+
files.file
71
71
+
FROM changesets
72
72
+
LEFT OUTER JOIN revisions ON revisions.changeset_id = changesets.id
73
73
+
LEFT OUTER JOIN files ON revisions.file_id = files.id
74
74
+
ORDER BY changesets.date, files.file") do |csfile|
75
75
+
if csfile["commitid"] == last["commitid"]
76
76
+
files.push csfile["file"]
77
77
+
else
78
78
+
if files.any?
79
79
+
printlog.call
80
80
+
end
81
81
+
files = [ csfile["file"] ]
82
82
+
last = csfile
83
83
+
end
84
84
+
end
85
85
+
86
86
+
if last.any?
87
87
+
printlog.call
88
88
+
end
89
89
+
end
90
90
+
91
91
+
def dup_script(script, tree)
92
92
+
script.puts "#!/bin/sh -x"
93
93
+
script.puts "if [ \"$TMPCVSDIR\" = \"\" ]; then echo 'set $TMPCVSDIR'; " +
94
94
+
"exit 1; fi"
95
95
+
script.puts "if [ \"$CVSROOT\" = \"\" ]; then echo 'set $CVSROOT'; " +
96
96
+
"exit 1; fi"
97
97
+
script.puts ""
98
98
+
script.puts "cd $TMPCVSDIR"
99
99
+
script.puts "cvs -Q -d $CVSROOT co -r1.1 #{tree} || exit 1"
100
100
+
script.puts ""
101
101
+
102
102
+
dead11s = {}
103
103
+
@scanner.db.execute("SELECT
104
104
+
file, first_undead_version
105
105
+
FROM files
106
106
+
WHERE first_undead_version NOT LIKE '1.1'") do |rev|
107
107
+
dead11s[rev["file"]] = rev["first_undead_version"]
108
108
+
end
109
109
+
110
110
+
dead11s.each do |file,rev|
111
111
+
confile = file.gsub(/,v$/, "")
112
112
+
113
113
+
script.puts "cvs -Q -d $CVSROOT co -r#{rev} '#{tree}/#{confile}' " +
114
114
+
"|| exit 1"
115
115
+
end
116
116
+
117
117
+
script.puts ""
118
118
+
script.puts "cd $TMPCVSDIR/#{tree}"
119
119
+
120
120
+
csid = nil
121
121
+
@scanner.db.execute("SELECT
122
122
+
files.file, changesets.commitid, changesets.author, changesets.date,
123
123
+
revisions.version
124
124
+
FROM revisions
125
125
+
LEFT OUTER JOIN files ON files.id = file_id
126
126
+
LEFT OUTER JOIN changesets ON revisions.changeset_id = changesets.id
127
127
+
WHERE revisions.commitid IS NULL
128
128
+
ORDER BY changesets.date ASC, files.file ASC") do |rev|
129
129
+
if csid == nil || rev["commitid"] != csid
130
130
+
script.puts "# commit #{rev["commitid"]} at #{Time.at(rev["date"])} " +
131
131
+
"by " + rev["author"]
132
132
+
csid = rev["commitid"]
133
133
+
end
134
134
+
135
135
+
script.puts "cvs admin -C #{rev["version"]}:#{rev["commitid"]} '" +
136
136
+
rev["file"].gsub(/,v$/, "") + "'"
137
137
+
end
138
138
+
end
139
139
+
end
+1
-134
lib/scanner.rb
···
2
2
def initialize(dbf, root)
3
3
@db = Db.new dbf
4
4
@root = (root + "/").gsub(/\/\//, "/")
5
5
+
@outputter = Outputter.new(self)
5
6
end
6
7
7
8
def recursively_scan(dir = nil)
···
256
257
257
258
system("rm", "-rf", tmp_dir + "/#{tree}") ||
258
259
raise("rm of #{tmp_dir}/#{tree} failed")
259
259
-
end
260
260
-
261
261
-
def changelog(domain, fh)
262
262
-
last = {}
263
263
-
files = []
264
264
-
265
265
-
printlog = Proc.new{
266
266
-
fh.puts "Changes by: #{last["author"]}@#{domain} " <<
267
267
-
Time.at(last["date"].to_i).strftime("%Y/%m/%d %H:%M:%S")
268
268
-
fh.puts "Commitid: #{last["commitid"]}"
269
269
-
fh.puts ""
270
270
-
fh.puts "Modified files:"
271
271
-
272
272
-
# group files by directory
273
273
-
dirs = {}
274
274
-
files.each do |f|
275
275
-
dir = f.split("/")
276
276
-
file = dir.pop.gsub(/,v$/, "")
277
277
-
278
278
-
if dir.length == 0
279
279
-
dir = "."
280
280
-
else
281
281
-
dir = dir.join("/")
282
282
-
end
283
283
-
284
284
-
dirs[dir] ||= []
285
285
-
if !dirs[dir].include?(file)
286
286
-
dirs[dir].push file
287
287
-
end
288
288
-
end
289
289
-
290
290
-
# print padded and wrapped directory and file lines
291
291
-
dirs.each do |dir,fs|
292
292
-
dl = " #{dir}"
293
293
-
if dir.length < 15
294
294
-
(15 - dir.length).times do
295
295
-
dl += " "
296
296
-
end
297
297
-
end
298
298
-
dl += ":"
299
299
-
fl = (72 - dl.length)
300
300
-
cl = dl
301
301
-
(fs.count + 1).times do
302
302
-
if (f = fs.shift)
303
303
-
if cl.length + f.length > 72
304
304
-
fh.puts cl.gsub(/[ ]{8}/, "\t")
305
305
-
cl = " " * dl.length
306
306
-
end
307
307
-
308
308
-
cl += " " + f
309
309
-
else
310
310
-
fh.puts cl.gsub(/[ ]{8}/, "\t")
311
311
-
break
312
312
-
end
313
313
-
end
314
314
-
end
315
315
-
316
316
-
fh.puts ""
317
317
-
fh.puts "Log message:"
318
318
-
fh.puts last["log"]
319
319
-
fh.puts ""
320
320
-
fh.puts ""
321
321
-
}
322
322
-
323
323
-
@db.execute("SELECT
324
324
-
changesets.date, changesets.author, changesets.commitid, changesets.log,
325
325
-
files.file
326
326
-
FROM changesets
327
327
-
LEFT OUTER JOIN revisions ON revisions.changeset_id = changesets.id
328
328
-
LEFT OUTER JOIN files ON revisions.file_id = files.id
329
329
-
ORDER BY changesets.date, files.file") do |csfile|
330
330
-
if csfile["commitid"] == last["commitid"]
331
331
-
files.push csfile["file"]
332
332
-
else
333
333
-
if files.any?
334
334
-
printlog.call
335
335
-
end
336
336
-
files = [ csfile["file"] ]
337
337
-
last = csfile
338
338
-
end
339
339
-
end
340
340
-
341
341
-
if last.any?
342
342
-
printlog.call
343
343
-
end
344
344
-
end
345
345
-
346
346
-
def dup_script(script, tree)
347
347
-
script.puts "#!/bin/sh -x"
348
348
-
script.puts "if [ \"$TMPCVSDIR\" = \"\" ]; then echo 'set $TMPCVSDIR'; " +
349
349
-
"exit 1; fi"
350
350
-
script.puts "if [ \"$CVSROOT\" = \"\" ]; then echo 'set $CVSROOT'; " +
351
351
-
"exit 1; fi"
352
352
-
script.puts ""
353
353
-
script.puts "cd $TMPCVSDIR"
354
354
-
script.puts "cvs -Q -d $CVSROOT co -r1.1 #{tree} || exit 1"
355
355
-
script.puts ""
356
356
-
357
357
-
dead11s = {}
358
358
-
@db.execute("SELECT
359
359
-
file, first_undead_version
360
360
-
FROM files
361
361
-
WHERE first_undead_version NOT LIKE '1.1'") do |rev|
362
362
-
dead11s[rev["file"]] = rev["first_undead_version"]
363
363
-
end
364
364
-
365
365
-
dead11s.each do |file,rev|
366
366
-
confile = file.gsub(/,v$/, "")
367
367
-
368
368
-
script.puts "cvs -Q -d $CVSROOT co -r#{rev} '#{tree}/#{confile}' " +
369
369
-
"|| exit 1"
370
370
-
end
371
371
-
372
372
-
script.puts ""
373
373
-
script.puts "cd $TMPCVSDIR/#{tree}"
374
374
-
375
375
-
csid = nil
376
376
-
@db.execute("SELECT
377
377
-
files.file, changesets.commitid, changesets.author, changesets.date,
378
378
-
revisions.version
379
379
-
FROM revisions
380
380
-
LEFT OUTER JOIN files ON files.id = file_id
381
381
-
LEFT OUTER JOIN changesets ON revisions.changeset_id = changesets.id
382
382
-
WHERE revisions.commitid IS NULL
383
383
-
ORDER BY changesets.date ASC, files.file ASC") do |rev|
384
384
-
if csid == nil || rev["commitid"] != csid
385
385
-
script.puts "# commit #{rev["commitid"]} at #{Time.at(rev["date"])} " +
386
386
-
"by " + rev["author"]
387
387
-
csid = rev["commitid"]
388
388
-
end
389
389
-
390
390
-
script.puts "cvs admin -C #{rev["version"]}:#{rev["commitid"]} '" +
391
391
-
rev["file"].gsub(/,v$/, "") + "'"
392
392
-
end
393
260
end
394
261
end
+5
-2
openbsd-commitid.rb
···
6
6
require "scanner"
7
7
require "rcsfile"
8
8
require "rcsrevision"
9
9
+
require "outputter"
9
10
10
11
CVSROOT = "/var/cvs-commitid/"
11
12
CVSTMP = "/var/cvs-tmp/"
···
38
39
39
40
sc.repo_surgery(CVSTMP, CVSROOT, tree)
40
41
41
41
-
sc.changelog("cvs.openbsd.org", f = File.open("out/Changelog-#{tree}", "w+"))
42
42
+
sc.outputter.changelog("cvs.openbsd.org",
43
43
+
f = File.open("out/Changelog-#{tree}", "w+"))
42
44
f.close
43
45
44
44
-
sc.dup_script(f = File.open("out/add_commitids_to_#{tree}.sh", "w+"), tree)
46
46
+
sc.outputter.dup_script(f = File.open("out/add_commitids_to_#{tree}.sh",
47
47
+
"w+"), tree)
45
48
f.close
46
49
end