script to retroactively add commitids to past openbsd commits

after running, output a changelog-style file of each tree

+87
+2
openbsd-commitid.rb
··· 36 36 end 37 37 38 38 sc.repo_surgery(CVSTMP, CVSROOT, tree) 39 + 40 + sc.changelog("cvs.openbsd.org", File.open("Changelog-#{tree}", "w+")) 39 41 end
+85
scanner.rb
··· 288 288 system("rm", "-rf", tmp_dir + "/#{tree}") || 289 289 raise("rm of #{tmp_dir}/#{tree} failed") 290 290 end 291 + 292 + def changelog(domain, fh) 293 + last = {} 294 + files = [] 295 + 296 + printlog = Proc.new{ 297 + fh.puts "Changes by: #{last["author"]}@#{domain} " << 298 + Time.at(last["date"].to_i).strftime("%Y/%m/%d %H:%M:%S") 299 + fh.puts "Commitid: #{last["commitid"]}" 300 + fh.puts "" 301 + fh.puts "Modified files:" 302 + 303 + # group files by directory 304 + dirs = {} 305 + files.each do |f| 306 + dir = f.split("/") 307 + file = dir.pop.gsub(/,v$/, "") 308 + 309 + if dir.length == 0 310 + dir = "." 311 + else 312 + dir = dir.join("/") 313 + end 314 + 315 + dirs[dir] ||= [] 316 + if !dirs[dir].include?(file) 317 + dirs[dir].push file 318 + end 319 + end 320 + 321 + # print padded and wrapped directory and file lines 322 + dirs.each do |dir,fs| 323 + dl = " #{dir}" 324 + if dir.length < 15 325 + (15 - dir.length).times do 326 + dl += " " 327 + end 328 + end 329 + dl += ":" 330 + fl = (72 - dl.length) 331 + cl = dl 332 + (fs.count + 1).times do 333 + if (f = fs.shift) 334 + if cl.length + f.length > 72 335 + fh.puts cl.gsub(/[ ]{8}/, "\t") 336 + cl = " " * dl.length 337 + end 338 + 339 + cl += " " + f 340 + else 341 + fh.puts cl.gsub(/[ ]{8}/, "\t") 342 + break 343 + end 344 + end 345 + end 346 + 347 + fh.puts "" 348 + fh.puts "Log message:" 349 + fh.puts last["log"] 350 + fh.puts "" 351 + fh.puts "" 352 + } 353 + 354 + @db.execute("SELECT 355 + changesets.date, changesets.author, changesets.commitid, changesets.log, 356 + files.file 357 + FROM changesets 358 + LEFT OUTER JOIN revisions ON revisions.changeset_id = changesets.id 359 + LEFT OUTER JOIN files ON revisions.file_id = files.id 360 + ORDER BY changesets.date, files.file") do |csfile| 361 + if csfile["commitid"] == last["commitid"] 362 + files.push csfile["file"] 363 + else 364 + if files.any? 365 + printlog.call 366 + end 367 + files = [ csfile["file"] ] 368 + last = csfile 369 + end 370 + end 371 + 372 + if last.any? 373 + printlog.call 374 + end 375 + end 291 376 end