OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 the V8 project authors. All rights reserved. | 2 # Copyright 2013 the V8 project authors. All rights reserved. |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following | 10 # copyright notice, this list of conditions and the following |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 TEMP_BRANCH: "prepare-push-temporary-branch-created-by-script", | 44 TEMP_BRANCH: "prepare-push-temporary-branch-created-by-script", |
45 DOT_GIT_LOCATION: ".git", | 45 DOT_GIT_LOCATION: ".git", |
46 VERSION_FILE: "src/version.cc", | 46 VERSION_FILE: "src/version.cc", |
47 CHANGELOG_FILE: "ChangeLog", | 47 CHANGELOG_FILE: "ChangeLog", |
48 CHANGELOG_ENTRY_FILE: "/tmp/v8-push-to-trunk-tempfile-changelog-entry", | 48 CHANGELOG_ENTRY_FILE: "/tmp/v8-push-to-trunk-tempfile-changelog-entry", |
49 PATCH_FILE: "/tmp/v8-push-to-trunk-tempfile-patch-file", | 49 PATCH_FILE: "/tmp/v8-push-to-trunk-tempfile-patch-file", |
50 COMMITMSG_FILE: "/tmp/v8-push-to-trunk-tempfile-commitmsg", | 50 COMMITMSG_FILE: "/tmp/v8-push-to-trunk-tempfile-commitmsg", |
51 DEPS_FILE: "DEPS", | 51 DEPS_FILE: "DEPS", |
52 } | 52 } |
53 | 53 |
| 54 PUSH_MESSAGE_SUFFIX = " (based on bleeding_edge revision r%d)" |
| 55 PUSH_MESSAGE_RE = re.compile(r".* \(based on bleeding_edge revision r(\d+)\)$") |
| 56 |
54 | 57 |
55 class PushToTrunkOptions(CommonOptions): | 58 class PushToTrunkOptions(CommonOptions): |
56 @staticmethod | 59 @staticmethod |
57 def MakeForcedOptions(author, reviewer, chrome_path): | 60 def MakeForcedOptions(author, reviewer, chrome_path): |
58 """Convenience wrapper.""" | 61 """Convenience wrapper.""" |
59 class Options(object): | 62 class Options(object): |
60 pass | 63 pass |
61 options = Options() | 64 options = Options() |
62 options.s = 0 | 65 options.s = 0 |
63 options.l = None | 66 options.l = None |
| 67 options.b = None |
64 options.f = True | 68 options.f = True |
65 options.m = False | 69 options.m = False |
66 options.c = chrome_path | 70 options.c = chrome_path |
67 options.a = author | 71 options.a = author |
68 return PushToTrunkOptions(options) | 72 return PushToTrunkOptions(options) |
69 | 73 |
70 def __init__(self, options): | 74 def __init__(self, options): |
71 super(PushToTrunkOptions, self).__init__(options, options.m) | 75 super(PushToTrunkOptions, self).__init__(options, options.m) |
72 self.requires_editor = not options.f | 76 self.requires_editor = not options.f |
73 self.wait_for_lgtm = not options.f | 77 self.wait_for_lgtm = not options.f |
74 self.tbr_commit = not options.m | 78 self.tbr_commit = not options.m |
75 self.l = options.l | 79 self.l = options.l |
76 self.reviewer = options.reviewer | 80 self.reviewer = options.reviewer |
77 self.c = options.c | 81 self.c = options.c |
| 82 self.b = getattr(options, 'b', None) |
78 self.author = getattr(options, 'a', None) | 83 self.author = getattr(options, 'a', None) |
79 | 84 |
80 class Preparation(Step): | 85 class Preparation(Step): |
81 MESSAGE = "Preparation." | 86 MESSAGE = "Preparation." |
82 | 87 |
83 def RunStep(self): | 88 def RunStep(self): |
84 self.InitialEnvironmentChecks() | 89 self.InitialEnvironmentChecks() |
85 self.CommonPrepare() | 90 self.CommonPrepare() |
86 self.PrepareBranch() | 91 self.PrepareBranch() |
87 self.DeleteBranch(self.Config(TRUNKBRANCH)) | 92 self.DeleteBranch(self.Config(TRUNKBRANCH)) |
88 | 93 |
89 | 94 |
90 class FreshBranch(Step): | 95 class FreshBranch(Step): |
91 MESSAGE = "Create a fresh branch." | 96 MESSAGE = "Create a fresh branch." |
92 | 97 |
93 def RunStep(self): | 98 def RunStep(self): |
94 args = "checkout -b %s svn/bleeding_edge" % self.Config(BRANCHNAME) | 99 args = "checkout -b %s svn/bleeding_edge" % self.Config(BRANCHNAME) |
95 if self.Git(args) is None: | 100 if self.Git(args) is None: |
96 self.Die("Creating branch %s failed." % self.Config(BRANCHNAME)) | 101 self.Die("Creating branch %s failed." % self.Config(BRANCHNAME)) |
97 | 102 |
98 | 103 |
99 class DetectLastPush(Step): | 104 class DetectLastPush(Step): |
100 MESSAGE = "Detect commit ID of last push to trunk." | 105 MESSAGE = "Detect commit ID of last push to trunk." |
101 | 106 |
102 def RunStep(self): | 107 def RunStep(self): |
103 last_push = (self._options.l or | 108 last_push_trunk = self._options.l or self.FindLastTrunkPush() |
104 self.Git("log -1 --format=%H ChangeLog").strip()) | |
105 while True: | 109 while True: |
106 # Print assumed commit, circumventing git's pager. | 110 # Print assumed commit, circumventing git's pager. |
107 print self.Git("log -1 %s" % last_push) | 111 print self.Git("log -1 %s" % last_push_trunk) |
108 if self.Confirm("Is the commit printed above the last push to trunk?"): | 112 if self.Confirm("Is the commit printed above the last push to trunk?"): |
109 break | 113 break |
110 args = "log -1 --format=%H %s^ ChangeLog" % last_push | 114 args = ("log -1 --format=%%H %s^ --grep=\"%s\"" |
111 last_push = self.Git(args).strip() | 115 % (last_push_trunk, push_pattern)) |
112 self["last_push"] = last_push | 116 last_push_trunk = self.Git(args).strip() |
| 117 |
| 118 if self._options.b: |
| 119 # Read the bleeding edge revision of the last push from a command-line |
| 120 # option. |
| 121 last_push_bleeding_edge = self._options.b |
| 122 else: |
| 123 # Retrieve the bleeding edge revision of the last push from the text in |
| 124 # the push commit message. |
| 125 args = "log -1 --format=%%s %s" % last_push_trunk |
| 126 last_push_trunk_title = self.Git(args).strip() |
| 127 last_push_be_svn = PUSH_MESSAGE_RE.match(last_push_trunk_title).group(1) |
| 128 if not last_push_be_svn: |
| 129 self.Die("Could not retrieve bleeding edge revision for trunk push %s" |
| 130 % last_push_trunk) |
| 131 args = "svn find-rev r%s" % last_push_be_svn |
| 132 last_push_bleeding_edge = self.Git(args).strip() |
| 133 if not last_push_bleeding_edge: |
| 134 self.Die("Could not retrieve bleeding edge git hash for trunk push %s" |
| 135 % last_push_trunk) |
| 136 |
| 137 # TODO(machenbach): last_push_trunk points to the svn revision on trunk. |
| 138 # It is not used yet but we'll need it for retrieving the current version. |
| 139 self["last_push_trunk"] = last_push_trunk |
| 140 # TODO(machenbach): This currently points to the prepare push revision that |
| 141 # will be deprecated soon. After the deprecation it will point to the last |
| 142 # bleeding_edge revision that went into the last push. |
| 143 self["last_push_bleeding_edge"] = last_push_bleeding_edge |
113 | 144 |
114 | 145 |
115 class PrepareChangeLog(Step): | 146 class PrepareChangeLog(Step): |
116 MESSAGE = "Prepare raw ChangeLog entry." | 147 MESSAGE = "Prepare raw ChangeLog entry." |
117 | 148 |
118 def Reload(self, body): | 149 def Reload(self, body): |
119 """Attempts to reload the commit message from rietveld in order to allow | 150 """Attempts to reload the commit message from rietveld in order to allow |
120 late changes to the LOG flag. Note: This is brittle to future changes of | 151 late changes to the LOG flag. Note: This is brittle to future changes of |
121 the web page name or structure. | 152 the web page name or structure. |
122 """ | 153 """ |
(...skipping 14 matching lines...) Expand all Loading... |
137 # These version numbers are used again later for the trunk commit. | 168 # These version numbers are used again later for the trunk commit. |
138 self.ReadAndPersistVersion() | 169 self.ReadAndPersistVersion() |
139 self["date"] = self.GetDate() | 170 self["date"] = self.GetDate() |
140 self["version"] = "%s.%s.%s" % (self["major"], | 171 self["version"] = "%s.%s.%s" % (self["major"], |
141 self["minor"], | 172 self["minor"], |
142 self["build"]) | 173 self["build"]) |
143 output = "%s: Version %s\n\n" % (self["date"], | 174 output = "%s: Version %s\n\n" % (self["date"], |
144 self["version"]) | 175 self["version"]) |
145 TextToFile(output, self.Config(CHANGELOG_ENTRY_FILE)) | 176 TextToFile(output, self.Config(CHANGELOG_ENTRY_FILE)) |
146 | 177 |
147 args = "log %s..HEAD --format=%%H" % self["last_push"] | 178 args = "log %s..HEAD --format=%%H" % self["last_push_bleeding_edge"] |
148 commits = self.Git(args).strip() | 179 commits = self.Git(args).strip() |
149 | 180 |
150 # Cache raw commit messages. | 181 # Cache raw commit messages. |
151 commit_messages = [ | 182 commit_messages = [ |
152 [ | 183 [ |
153 self.Git("log -1 %s --format=\"%%s\"" % commit), | 184 self.Git("log -1 %s --format=\"%%s\"" % commit), |
154 self.Reload(self.Git("log -1 %s --format=\"%%B\"" % commit)), | 185 self.Reload(self.Git("log -1 %s --format=\"%%B\"" % commit)), |
155 self.Git("log -1 %s --format=\"%%an\"" % commit), | 186 self.Git("log -1 %s --format=\"%%an\"" % commit), |
156 ] for commit in commits.splitlines() | 187 ] for commit in commits.splitlines() |
157 ] | 188 ] |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 # Convert the ChangeLog entry to commit message format. | 315 # Convert the ChangeLog entry to commit message format. |
285 text = FileToText(self.Config(CHANGELOG_ENTRY_FILE)) | 316 text = FileToText(self.Config(CHANGELOG_ENTRY_FILE)) |
286 | 317 |
287 # Remove date and trailing white space. | 318 # Remove date and trailing white space. |
288 text = re.sub(r"^%s: " % self["date"], "", text.rstrip()) | 319 text = re.sub(r"^%s: " % self["date"], "", text.rstrip()) |
289 | 320 |
290 # Retrieve svn revision for showing the used bleeding edge revision in the | 321 # Retrieve svn revision for showing the used bleeding edge revision in the |
291 # commit message. | 322 # commit message. |
292 args = "svn find-rev %s" % self["prepare_commit_hash"] | 323 args = "svn find-rev %s" % self["prepare_commit_hash"] |
293 self["svn_revision"] = self.Git(args).strip() | 324 self["svn_revision"] = self.Git(args).strip() |
294 text = MSub(r"^(Version \d+\.\d+\.\d+)$", | 325 suffix = PUSH_MESSAGE_SUFFIX % int(self["svn_revision"]) |
295 ("\\1 (based on bleeding_edge revision r%s)" | 326 text = MSub(r"^(Version \d+\.\d+\.\d+)$", "\\1%s" % suffix, text) |
296 % self["svn_revision"]), | |
297 text) | |
298 | 327 |
299 # Remove indentation and merge paragraphs into single long lines, keeping | 328 # Remove indentation and merge paragraphs into single long lines, keeping |
300 # empty lines between them. | 329 # empty lines between them. |
301 def SplitMapJoin(split_text, fun, join_text): | 330 def SplitMapJoin(split_text, fun, join_text): |
302 return lambda text: join_text.join(map(fun, text.split(split_text))) | 331 return lambda text: join_text.join(map(fun, text.split(split_text))) |
303 strip = lambda line: line.strip() | 332 strip = lambda line: line.strip() |
304 text = SplitMapJoin("\n\n", SplitMapJoin("\n", strip, " "), "\n\n")(text) | 333 text = SplitMapJoin("\n\n", SplitMapJoin("\n", strip, " "), "\n\n")(text) |
305 | 334 |
306 if not text: | 335 if not text: |
307 self.Die("Commit message editing failed.") | 336 self.Die("Commit message editing failed.") |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 CleanUp, | 570 CleanUp, |
542 ] | 571 ] |
543 | 572 |
544 RunScript(step_classes, config, options, side_effect_handler) | 573 RunScript(step_classes, config, options, side_effect_handler) |
545 | 574 |
546 | 575 |
547 def BuildOptions(): | 576 def BuildOptions(): |
548 result = optparse.OptionParser() | 577 result = optparse.OptionParser() |
549 result.add_option("-a", "--author", dest="a", | 578 result.add_option("-a", "--author", dest="a", |
550 help=("Specify the author email used for rietveld.")) | 579 help=("Specify the author email used for rietveld.")) |
| 580 result.add_option("-b", "--last-bleeding-edge", dest="b", |
| 581 help=("Manually specify the git commit ID of the last " |
| 582 "bleeding edge revision that was pushed to trunk. " |
| 583 "This is used for the auto-generated ChangeLog " |
| 584 "entry.")) |
551 result.add_option("-c", "--chromium", dest="c", | 585 result.add_option("-c", "--chromium", dest="c", |
552 help=("Specify the path to your Chromium src/ " | 586 help=("Specify the path to your Chromium src/ " |
553 "directory to automate the V8 roll.")) | 587 "directory to automate the V8 roll.")) |
554 result.add_option("-f", "--force", dest="f", | 588 result.add_option("-f", "--force", dest="f", |
555 help="Don't prompt the user.", | 589 help="Don't prompt the user.", |
556 default=False, action="store_true") | 590 default=False, action="store_true") |
557 result.add_option("-l", "--last-push", dest="l", | 591 result.add_option("-l", "--last-push", dest="l", |
558 help=("Manually specify the git commit ID " | 592 help=("Manually specify the git commit ID " |
559 "of the last push to trunk.")) | 593 "of the last push to trunk.")) |
560 result.add_option("-m", "--manual", dest="m", | 594 result.add_option("-m", "--manual", dest="m", |
(...skipping 29 matching lines...) Expand all Loading... |
590 def Main(): | 624 def Main(): |
591 parser = BuildOptions() | 625 parser = BuildOptions() |
592 (options, args) = parser.parse_args() | 626 (options, args) = parser.parse_args() |
593 if not ProcessOptions(options): | 627 if not ProcessOptions(options): |
594 parser.print_help() | 628 parser.print_help() |
595 return 1 | 629 return 1 |
596 RunPushToTrunk(CONFIG, PushToTrunkOptions(options)) | 630 RunPushToTrunk(CONFIG, PushToTrunkOptions(options)) |
597 | 631 |
598 if __name__ == "__main__": | 632 if __name__ == "__main__": |
599 sys.exit(Main()) | 633 sys.exit(Main()) |
OLD | NEW |