commit.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright (c) 2011 The Chromium OS Authors.
  2. #
  3. # See file CREDITS for list of people who contributed to this
  4. # project.
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. # MA 02111-1307 USA
  20. #
  21. import re
  22. # Separates a tag: at the beginning of the subject from the rest of it
  23. re_subject_tag = re.compile('([^:\s]*):\s*(.*)')
  24. class Commit:
  25. """Holds information about a single commit/patch in the series.
  26. Args:
  27. hash: Commit hash (as a string)
  28. Variables:
  29. hash: Commit hash
  30. subject: Subject line
  31. tags: List of maintainer tag strings
  32. changes: Dict containing a list of changes (single line strings).
  33. The dict is indexed by change version (an integer)
  34. cc_list: List of people to aliases/emails to cc on this commit
  35. """
  36. def __init__(self, hash):
  37. self.hash = hash
  38. self.subject = None
  39. self.tags = []
  40. self.changes = {}
  41. self.cc_list = []
  42. def AddChange(self, version, info):
  43. """Add a new change line to the change list for a version.
  44. Args:
  45. version: Patch set version (integer: 1, 2, 3)
  46. info: Description of change in this version
  47. """
  48. if not self.changes.get(version):
  49. self.changes[version] = []
  50. self.changes[version].append(info)
  51. def CheckTags(self):
  52. """Create a list of subject tags in the commit
  53. Subject tags look like this:
  54. propounder: fort: Change the widget to propound correctly
  55. Here the tags are propounder and fort. Multiple tags are supported.
  56. The list is updated in self.tag.
  57. Returns:
  58. None if ok, else the name of a tag with no email alias
  59. """
  60. str = self.subject
  61. m = True
  62. while m:
  63. m = re_subject_tag.match(str)
  64. if m:
  65. tag = m.group(1)
  66. self.tags.append(tag)
  67. str = m.group(2)
  68. return None
  69. def AddCc(self, cc_list):
  70. """Add a list of people to Cc when we send this patch.
  71. Args:
  72. cc_list: List of aliases or email addresses
  73. """
  74. self.cc_list += cc_list