commit.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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*(.*)')
  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: Change the widget to propound correctly
  55. Multiple tags are supported. The list is updated in self.tag
  56. Returns:
  57. None if ok, else the name of a tag with no email alias
  58. """
  59. str = self.subject
  60. m = True
  61. while m:
  62. m = re_subject_tag.match(str)
  63. if m:
  64. tag = m.group(1)
  65. self.tags.append(tag)
  66. str = m.group(2)
  67. return None
  68. def AddCc(self, cc_list):
  69. """Add a list of people to Cc when we send this patch.
  70. Args:
  71. cc_list: List of aliases or email addresses
  72. """
  73. self.cc_list += cc_list