tree_truth.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # Copyright 2013 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. #
  6. # Script for printing recent commits in a buildbot run.
  7. # Return the sha1 of the given tag. If not present, return "".
  8. # $1: path to repo
  9. # $2: tag name
  10. tt_sha1_for_tag() {
  11. oneline=$(cd $1 && git log -1 $2 --format='%H' 2>/dev/null)
  12. if [ $? -eq 0 ] ; then
  13. echo $oneline
  14. fi
  15. }
  16. # Return the sha1 of HEAD, or ""
  17. # $1: path to repo
  18. tt_sha1_for_head() {
  19. ( cd $1 && git log HEAD -n1 --format='%H' | cat )
  20. }
  21. # For the given repo, set tag to HEAD.
  22. # $1: path to repo
  23. # $2: tag name
  24. tt_tag_head() {
  25. ( cd $1 && git tag -f $2 )
  26. }
  27. # For the given repo, delete the tag.
  28. # $1: path to repo
  29. # $2: tag name
  30. tt_delete_tag() {
  31. ( cd $1 && git tag -d $2 )
  32. }
  33. # For the given repo, set tag to "three commits ago" (for testing).
  34. # $1: path to repo
  35. # $2: tag name
  36. tt_tag_three_ago() {
  37. local sh=$(cd $1 && git log --pretty=oneline -n 3 | tail -1 | awk '{print $1}')
  38. ( cd $1 && git tag -f $2 $sh )
  39. }
  40. # List the commits between the given tag and HEAD.
  41. # If the tag does not exist, only list the last few.
  42. # If the tag is at HEAD, list nothing.
  43. # Output format has distinct build steps for repos with changes.
  44. # $1: path to repo
  45. # $2: tag name
  46. # $3: simple/short repo name to use for display
  47. tt_list_commits() {
  48. local tag_sha1=$(tt_sha1_for_tag $1 $2)
  49. local head_sha1=$(tt_sha1_for_head $1)
  50. local display_name=$(echo $3 | sed 's#/#_#g')
  51. if [ "${tag_sha1}" = "${head_sha1}" ] ; then
  52. return
  53. fi
  54. if [ "${tag_sha1}" = "" ] ; then
  55. echo "@@@BUILD_STEP Recent commits in repo $display_name@@@"
  56. echo "NOTE: git tag was not found so we have no baseline."
  57. echo "Here are some recent commits, but they may not be new for this build."
  58. ( cd $1 && git log -n 10 --stat | cat)
  59. else
  60. echo "@@@BUILD_STEP New commits in repo $display_name@@@"
  61. ( cd $1 && git log -n 500 $2..HEAD --stat | cat)
  62. fi
  63. }
  64. # Clean out the tree truth tags in all repos. For testing.
  65. tt_clean_all() {
  66. for project in $@; do
  67. tt_delete_tag $CHROME_SRC/../$project tree_truth
  68. done
  69. }
  70. # Print tree truth for all clank repos.
  71. tt_print_all() {
  72. for project in $@; do
  73. local full_path=$CHROME_SRC/../$project
  74. tt_list_commits $full_path tree_truth $project
  75. tt_tag_head $full_path tree_truth
  76. done
  77. }
  78. # Print a summary of the last 10 commits for each repo.
  79. tt_brief_summary() {
  80. echo "@@@BUILD_STEP Brief summary of recent CLs in every branch@@@"
  81. for project in $@; do
  82. echo $project:
  83. local full_path=$CHROME_SRC/../$project
  84. (cd $full_path && git log -n 10 --format=" %H %s %an, %ad" | cat)
  85. echo "================================================================="
  86. done
  87. }
  88. CHROME_SRC=$1
  89. shift
  90. PROJECT_LIST=$@
  91. tt_brief_summary $PROJECT_LIST
  92. tt_print_all $PROJECT_LIST