patch.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python3
  2. # Applies a commit or commits on branch or branches
  3. # USAGE:
  4. # patch.py -c <commit-list> -b <branch-list> [-p] [-t]
  5. # - <commit-list>: list of commit SHAs to apply.
  6. # - <branch-list>: branches where the commit should be applied. * can be used as wildchar
  7. # - p: push the changes to <branch-list>
  8. # - t: increment version number and create a tag
  9. import os, subprocess, com, re
  10. push = False
  11. def clone(repo):
  12. com.cmd("git clone --recurse-submodules https://github.com/lvgl/" + repo)
  13. os.chdir("./" + repo)
  14. com.cmd("git checkout master")
  15. com.cmd("git remote update origin --prune")
  16. com.cmd("git pull origin --tags")
  17. os.chdir("..")
  18. # Get the list of related minor version branches
  19. #clone("lvgl")
  20. os.chdir("lvgl")
  21. cmd = "git branch --remotes | grep origin/release/v8"
  22. branches, error = subprocess.Popen(cmd, shell=True, executable="/bin/bash", stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  23. branches = str(branches)
  24. branches = branches.replace("b'", "")
  25. branches = branches.replace("'", "")
  26. branches = branches.replace("origin/", "")
  27. branches = branches.replace(" ", " ")
  28. branches = branches.replace("\\n", "")
  29. branches = branches.split(" ")
  30. branches = list(filter(len, branches))
  31. commits = []
  32. with open('../commits.txt') as f:
  33. for line in f:
  34. commits.insert(0, line)
  35. print(commits)
  36. for br in branches:
  37. com.cmd("git checkout " + br)
  38. print("Applying commits")
  39. for c in commits:
  40. h = c.split(" ")
  41. com.cmd("git cherry-pick " + h[0])
  42. ver = com.get_lvgl_version(br)
  43. ver_new = ver.copy()
  44. ver_new[2] = str(int(ver_new[2]) + 1)
  45. print("Updating branch '" + br + "' from '" + com.ver_format(ver) + "' to '" + com.ver_format(ver_new) + "'")
  46. com.update_version(ver_new)
  47. com.cmd("git tag -a " + com.ver_format(ver_new) + "-m \"Release " + com.ver_format(ver_new) + "\"")
  48. if push:
  49. com.cmd("git push origin " + br + "--tags")
  50. com.cmd("git checkout master")
  51. ver = com.get_lvgl_version("master")
  52. ver = com.get_lvgl_version(br)
  53. ver_new[2] = str(int(ver_new[2]) + 1)
  54. t = com.ver_format(ver_new) + "-dev"
  55. com.cmd("git tag -a " + t + " -m \"Start " + t + "\"")
  56. if push:
  57. com.cmd("git push origin master --tags")