Guest User

Untitled

a guest
Jul 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -lt 1 ]; then
  3. echo "syntax: $0 <commit count> [<make args>]"
  4. echo "will attempt to run 'make' on each commit starting with the commit <commit count> commits ago all the way up to the current HEAD"
  5. echo "e.g. compile-commits 10 -j10"
  6. exit 1
  7. fi
  8.  
  9. if [ ! -d ".git" ]; then
  10. echo ".git not found or not a dir"
  11. exit 2
  12. fi
  13.  
  14. commit_count=$1
  15. shift
  16.  
  17. # determine current branch
  18. head=$(cat .git/HEAD)
  19. branch=${head:16}
  20. if [ "$branch" = "" ]; then
  21. echo "could not determine branch from $head (.git/HEAD)"
  22. exit 3
  23. fi
  24.  
  25. # iterate commits - this iteration is in the opposite order (newest to oldest) of what we want
  26. ordered_commits=""
  27. for i in $(git log -$commit_count|grep "^commit [a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]$"); do
  28. if [ "$i" = "commit" ]; then continue; fi
  29. commit=$i
  30. ordered_commits="$commit $ordered_commits"
  31. done
  32.  
  33. report=""
  34. rebase_head=$commit_count
  35. let rebase_head++ # if we rebase the first commit, we need to do HEAD~(arg + 1)
  36. left=""
  37. done=""
  38. for i in $(seq 1 $commit_count); do
  39. left="$left "
  40. clr="$clr "
  41. done
  42. clr="$clr \r"
  43.  
  44. clean_up=1
  45. function trap_ctrlc()
  46. {
  47. if [ $clean_up ]; then
  48. echo -n -e "\r$clr""Aborting..."
  49. git checkout $branch &>/dev/null
  50. echo ""
  51. exit 2
  52. fi
  53. }
  54.  
  55. trap "trap_ctrlc" INT
  56.  
  57. for i in $ordered_commits; do
  58. git checkout $i &> .gco-output
  59. if [ $? -ne 0 ]; then echo "git checkout $i failed:"; echo "====="; cat .gco-output; rm .gco-output; git checkout $branch; exit 10; fi
  60. rm .gco-output
  61. echo -n -e "$i"
  62. git show HEAD | head -n5 | tail -n1
  63. echo -n -e "[$done$left]\r"
  64. make "$@" &> .make-output
  65. makeres=$?
  66. echo -n -e "$clr"
  67. if [ $makeres -ne 0 ]; then
  68. prevreport=$report
  69. report="$report$i: make failure\n"
  70. echo "make FAILURE"
  71. echo "====="
  72. cat .make-output
  73. rm .make-output
  74. while [ 1 ]; do
  75. echo -n -e "rebase (r), ignore (i), or return to $branch (b): "
  76. read x
  77. if [ "$x" = "r" ]; then
  78. git checkout $branch
  79. git rebase -i HEAD~$rebase_head
  80. exit 12
  81. elif [ "$x" = "i" ]; then
  82. break
  83. elif [ "$x" = "b" ]; then
  84. git checkout $branch
  85. if [ "$prevreport" != "" ]; then
  86. echo -n -e "Results:\n$report"
  87. fi
  88. exit 11
  89. fi
  90. done
  91. fi
  92. rm .make-output
  93. left=${left:1}
  94. done="#$done"
  95. done
  96.  
  97. git checkout $branch &> .gco-output
  98. if [ $? -ne 0 ]; then echo "git checkout $i failed:"; echo "====="; cat .gco-output; rm .gco-output; exit 10; fi
  99. rm .gco-output
  100.  
  101. if [ "$report" = "" ]; then
  102. echo "All OK"
  103. else
  104. echo -n -e "Results:\n$report"
  105. fi
Add Comment
Please, Sign In to add comment