commit.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright (c) 2011 The Chromium OS Authors.
  2. #
  3. # SPDX-License-Identifier: GPL-2.0+
  4. #
  5. import re
  6. # Separates a tag: at the beginning of the subject from the rest of it
  7. re_subject_tag = re.compile('([^:\s]*):\s*(.*)')
  8. class Commit:
  9. """Holds information about a single commit/patch in the series.
  10. Args:
  11. hash: Commit hash (as a string)
  12. Variables:
  13. hash: Commit hash
  14. subject: Subject line
  15. tags: List of maintainer tag strings
  16. changes: Dict containing a list of changes (single line strings).
  17. The dict is indexed by change version (an integer)
  18. cc_list: List of people to aliases/emails to cc on this commit
  19. notes: List of lines in the commit (not series) notes
  20. """
  21. def __init__(self, hash):
  22. self.hash = hash
  23. self.subject = None
  24. self.tags = []
  25. self.changes = {}
  26. self.cc_list = []
  27. self.signoff_set = set()
  28. self.notes = []
  29. def AddChange(self, version, info):
  30. """Add a new change line to the change list for a version.
  31. Args:
  32. version: Patch set version (integer: 1, 2, 3)
  33. info: Description of change in this version
  34. """
  35. if not self.changes.get(version):
  36. self.changes[version] = []
  37. self.changes[version].append(info)
  38. def CheckTags(self):
  39. """Create a list of subject tags in the commit
  40. Subject tags look like this:
  41. propounder: fort: Change the widget to propound correctly
  42. Here the tags are propounder and fort. Multiple tags are supported.
  43. The list is updated in self.tag.
  44. Returns:
  45. None if ok, else the name of a tag with no email alias
  46. """
  47. str = self.subject
  48. m = True
  49. while m:
  50. m = re_subject_tag.match(str)
  51. if m:
  52. tag = m.group(1)
  53. self.tags.append(tag)
  54. str = m.group(2)
  55. return None
  56. def AddCc(self, cc_list):
  57. """Add a list of people to Cc when we send this patch.
  58. Args:
  59. cc_list: List of aliases or email addresses
  60. """
  61. self.cc_list += cc_list
  62. def CheckDuplicateSignoff(self, signoff):
  63. """Check a list of signoffs we have send for this patch
  64. Args:
  65. signoff: Signoff line
  66. Returns:
  67. True if this signoff is new, False if we have already seen it.
  68. """
  69. if signoff in self.signoff_set:
  70. return False
  71. self.signoff_set.add(signoff)
  72. return True