commit.py 2.5 KB

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