lib_patch.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # See utils/checkpackagelib/readme.txt before editing this file.
  2. # The format of the patch files is tested during the build, so below check
  3. # functions don't need to check for things already checked by running
  4. # "make package-dirclean package-patch".
  5. import re
  6. from base import _CheckFunction
  7. from lib import NewlineAtEof # noqa: F401
  8. class ApplyOrder(_CheckFunction):
  9. APPLY_ORDER = re.compile("/\d{1,4}-[^/]*$")
  10. def before(self):
  11. if not self.APPLY_ORDER.search(self.filename):
  12. return ["{}:0: use name <number>-<description>.patch "
  13. "({}#_providing_patches)"
  14. .format(self.filename, self.url_to_manual)]
  15. class NumberedSubject(_CheckFunction):
  16. NUMBERED_PATCH = re.compile("Subject:\s*\[PATCH\s*\d+/\d+\]")
  17. def before(self):
  18. self.git_patch = False
  19. self.lineno = 0
  20. self.text = None
  21. def check_line(self, lineno, text):
  22. if text.startswith("diff --git"):
  23. self.git_patch = True
  24. return
  25. if self.NUMBERED_PATCH.search(text):
  26. self.lineno = lineno
  27. self.text = text
  28. def after(self):
  29. if self.git_patch and self.text:
  30. return ["{}:{}: generate your patches with 'git format-patch -N'"
  31. .format(self.filename, self.lineno),
  32. self.text]
  33. class Sob(_CheckFunction):
  34. SOB_ENTRY = re.compile("^Signed-off-by: .*$")
  35. def before(self):
  36. self.found = False
  37. def check_line(self, lineno, text):
  38. if self.found:
  39. return
  40. if self.SOB_ENTRY.search(text):
  41. self.found = True
  42. def after(self):
  43. if not self.found:
  44. return ["{}:0: missing Signed-off-by in the header "
  45. "({}#_format_and_licensing_of_the_package_patches)"
  46. .format(self.filename, self.url_to_manual)]