mfprep 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. #
  3. # mfprep tag1 [tag2]
  4. #
  5. # Find commits in bugfix-2.1.x that are not yet in 2.1.x.
  6. #
  7. # Specify a version tag to start from, and optional version tag to end at.
  8. # For bugfix-2.1.x the tag will be prefixed by dev- to distinguish it from the version tag,
  9. # so at every release be sure to create a dev- tag and publish it to origin.
  10. #
  11. SELF=`basename "$0"`
  12. DRYRUN=0
  13. [[ $# < 1 || $# > 2 ]] && { echo "Usage $SELF tag1 [tag2]" ; exit 1 ; }
  14. TAG1=$1
  15. TAG2=${2:-"HEAD"}
  16. DEST=2.1.x
  17. # Validate that the required tags exist
  18. MTAG=`git tag | grep -e "^dev-$TAG1\$"`
  19. [[ -n "$MTAG" ]] || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
  20. MTAG=`git tag | grep -e "^$TAG1\$"`
  21. [[ -n "$MTAG" ]] || { echo "Can't find tag $TAG1" ; exit 1 ; }
  22. # Generate log of recent commits for bugfix-2.1.x and DEST
  23. TMPDIR=`mktemp -d`
  24. LOGB="$TMPDIR/log-bf.txt"
  25. LOG2="$TMPDIR/log-2x.txt"
  26. TMPF="$TMPDIR/tmp.txt"
  27. SCRF="$TMPDIR/update-$DEST.sh"
  28. git checkout bugfix-2.1.x
  29. git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | sed '1!G;h;$!d' >"$LOGB"
  30. git checkout $DEST
  31. git log --pretty="[%h] %s" $TAG1..$TAG2 | sed '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
  32. # Go through commit text from DEST removing all matches from the bugfix log
  33. cat "$LOG2" | while read line; do
  34. if [[ $line =~ \(((#[0-9]{5}),* *)((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?\)$ ]]; then
  35. PATT=""
  36. for i in ${!BASH_REMATCH[@]}; do
  37. if ((i > 0 && (i % 2 == 0))); then
  38. if [[ -n "${BASH_REMATCH[i]}" ]]; then
  39. [[ -n "$PATT" ]] && PATT="$PATT|"
  40. PATT="$PATT${BASH_REMATCH[i]}"
  41. fi
  42. fi
  43. done
  44. #echo "... $PATT"
  45. [[ -n "$PATT" ]] && { grep -vE "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
  46. else
  47. PATT=$( sed -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
  48. [[ -n "$PATT" ]] && { grep -v "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
  49. fi
  50. done
  51. # Convert remaining commits into git commands
  52. echo -e "#!/usr/bin/env bash\nset -e\ngit checkout ${DEST}\n" >"$TMPF"
  53. cat "$LOGB" | while read line; do
  54. if [[ $line =~ ^\[([0-9a-f]{10})\]\ *(.*)$ ]]; then
  55. CID=${BASH_REMATCH[1]}
  56. REST=${BASH_REMATCH[2]}
  57. echo "git cherry-pick $CID ;# $REST" >>"$TMPF"
  58. else
  59. echo ";# $line" >>"$TMPF"
  60. fi
  61. done
  62. mv "$TMPF" "$SCRF"
  63. chmod +x "$SCRF"
  64. ((DRYRUN)) && rm -r "$TMPDIR" || open "$TMPDIR"