2
0

genhtml.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env tclsh
  2. # Load commits history as "sha1 unixtime".
  3. set commits [exec git log unstable {--pretty="%H %at"}]
  4. set raw_tags [exec git tag]
  5. # Load all the tags that are about stable releases.
  6. foreach tag $raw_tags {
  7. if {[string match v*-stable $tag]} {
  8. set tag [string range $tag 1 end-7]
  9. puts $tag
  10. }
  11. if {[regexp {^[0-9]+.[0-9]+.[0-9]+$} $tag]} {
  12. lappend tags $tag
  13. }
  14. }
  15. # For each tag, create a list of "name unixtime"
  16. foreach tag $tags {
  17. set taginfo [exec git log $tag -n 1 "--pretty=\"$tag %at\""]
  18. set taginfo [string trim $taginfo {"}]
  19. lappend labels $taginfo
  20. }
  21. # For each commit, check the amount of code changed and create an array
  22. # mapping the commit to the number of lines affected.
  23. foreach c $commits {
  24. set stat [exec git show --oneline --numstat [lindex $c 0]]
  25. set linenum 0
  26. set affected 0
  27. foreach line [split $stat "\n"] {
  28. incr linenum
  29. if {$linenum == 1 || [string match *deps/* $line]} continue
  30. if {[catch {llength $line} numfields]} continue
  31. if {$numfields == 0} continue
  32. catch {
  33. incr affected [lindex $line 0]
  34. incr affected [lindex $line 1]
  35. }
  36. }
  37. set commit_to_affected([lindex $c 0]) $affected
  38. }
  39. set base_time [lindex [lindex $commits end] 1]
  40. puts [clock format $base_time]
  41. # Generate a graph made of HTML DIVs.
  42. puts {<html>
  43. <style>
  44. .box {
  45. position:absolute;
  46. width:10px;
  47. height:5px;
  48. border:1px black solid;
  49. background-color:#44aa33;
  50. opacity: 0.04;
  51. }
  52. .label {
  53. position:absolute;
  54. background-color:#dddddd;
  55. font-family:helvetica;
  56. font-size:12px;
  57. padding:2px;
  58. color:#666;
  59. border:1px #aaa solid;
  60. border-radius: 5px;
  61. }
  62. #outer {
  63. position:relative;
  64. width:1500;
  65. height:500;
  66. border:1px #aaa solid;
  67. }
  68. </style>
  69. <div id="outer">
  70. }
  71. foreach c $commits {
  72. set sha [lindex $c 0]
  73. set t [expr {([lindex $c 1]-$base_time)/(3600*24*2)}]
  74. set affected [expr $commit_to_affected($sha)]
  75. set left $t
  76. set height [expr {log($affected)*20}]
  77. puts "<div class=\"box\" style=\"left:$left; bottom:0; height:$height\"></div>"
  78. }
  79. set bottom -30
  80. foreach l $labels {
  81. set name [lindex $l 0]
  82. set t [expr {([lindex $l 1]-$base_time)/(3600*24*2)}]
  83. set left $t
  84. if {$left < 0} continue
  85. incr bottom -20
  86. if {$bottom == -210} {set bottom -30}
  87. puts "<div class=\"label\" style=\"left:$left; bottom:$bottom\">$name</div>"
  88. }
  89. puts {</div></html>}