commit.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.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