commit.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. change_id: the Change-Id: tag that was stripped from this commit
  20. and can be used to generate the Message-Id.
  21. """
  22. def __init__(self, hash):
  23. self.hash = hash
  24. self.subject = None
  25. self.tags = []
  26. self.changes = {}
  27. self.cc_list = []
  28. self.signoff_set = set()
  29. self.notes = []
  30. self.change_id = None
  31. def AddChange(self, version, info):
  32. """Add a new change line to the change list for a version.
  33. Args:
  34. version: Patch set version (integer: 1, 2, 3)
  35. info: Description of change in this version
  36. """
  37. if not self.changes.get(version):
  38. self.changes[version] = []
  39. self.changes[version].append(info)
  40. def CheckTags(self):
  41. """Create a list of subject tags in the commit
  42. Subject tags look like this:
  43. propounder: fort: Change the widget to propound correctly
  44. Here the tags are propounder and fort. Multiple tags are supported.
  45. The list is updated in self.tag.
  46. Returns:
  47. None if ok, else the name of a tag with no email alias
  48. """
  49. str = self.subject
  50. m = True
  51. while m:
  52. m = re_subject_tag.match(str)
  53. if m:
  54. tag = m.group(1)
  55. self.tags.append(tag)
  56. str = m.group(2)
  57. return None
  58. def AddCc(self, cc_list):
  59. """Add a list of people to Cc when we send this patch.
  60. Args:
  61. cc_list: List of aliases or email addresses
  62. """
  63. self.cc_list += cc_list
  64. def CheckDuplicateSignoff(self, signoff):
  65. """Check a list of signoffs we have send for this patch
  66. Args:
  67. signoff: Signoff line
  68. Returns:
  69. True if this signoff is new, False if we have already seen it.
  70. """
  71. if signoff in self.signoff_set:
  72. return False
  73. self.signoff_set.add(signoff)
  74. return True