OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """This module uprevs a given package's ebuild to the next revision.""" | 7 """This module uprevs a given package's ebuild to the next revision.""" |
8 | 8 |
9 | 9 |
10 import fileinput | 10 import fileinput |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 # ======================= End Global Helper Functions ======================== | 216 # ======================= End Global Helper Functions ======================== |
217 | 217 |
218 | 218 |
219 def Clean(tracking_branch): | 219 def Clean(tracking_branch): |
220 """Cleans up uncommitted changes. | 220 """Cleans up uncommitted changes. |
221 | 221 |
222 Args: | 222 Args: |
223 tracking_branch: The tracking branch we want to return to after the call. | 223 tracking_branch: The tracking branch we want to return to after the call. |
224 """ | 224 """ |
225 _SimpleRunCommand('git reset HEAD --hard') | 225 _SimpleRunCommand('git reset HEAD --hard') |
226 _SimpleRunCommand('git checkout %s' % tracking_branch) | 226 branch = GitBranch(STABLE_BRANCH_NAME, tracking_branch) |
227 if branch.Exists(): | |
228 branch.Checkout(branch) | |
229 branch.Delete() | |
227 | 230 |
228 | 231 |
229 def PushChange(stable_branch, tracking_branch): | 232 def PushChange(stable_branch, tracking_branch): |
230 """Pushes commits in the stable_branch to the remote git repository. | 233 """Pushes commits in the stable_branch to the remote git repository. |
231 | 234 |
232 Pushes locals commits from calls to CommitChange to the remote git | 235 Pushes locals commits from calls to CommitChange to the remote git |
233 repository specified by current working directory. | 236 repository specified by current working directory. |
234 | 237 |
235 Args: | 238 Args: |
236 stable_branch: The local branch with commits we want to push. | 239 stable_branch: The local branch with commits we want to push. |
(...skipping 28 matching lines...) Expand all Loading... | |
265 else: | 268 else: |
266 _SimpleRunCommand('git push') | 269 _SimpleRunCommand('git push') |
267 | 270 |
268 break | 271 break |
269 except: | 272 except: |
270 if push_try < num_retries: | 273 if push_try < num_retries: |
271 Warning('Failed to push change, performing retry (%s/%s)' % ( | 274 Warning('Failed to push change, performing retry (%s/%s)' % ( |
272 push_try + 1, num_retries)) | 275 push_try + 1, num_retries)) |
273 else: | 276 else: |
274 raise | 277 raise |
275 | 278 |
scottz
2011/01/27 05:33:38
extra new line?
| |
276 | 279 |
280 | |
277 class GitBranch(object): | 281 class GitBranch(object): |
278 """Wrapper class for a git branch.""" | 282 """Wrapper class for a git branch.""" |
279 | 283 |
280 def __init__(self, branch_name, tracking_branch): | 284 def __init__(self, branch_name, tracking_branch): |
281 """Sets up variables but does not create the branch.""" | 285 """Sets up variables but does not create the branch.""" |
282 self.branch_name = branch_name | 286 self.branch_name = branch_name |
283 self.tracking_branch = tracking_branch | 287 self.tracking_branch = tracking_branch |
284 | 288 |
285 def CreateBranch(self): | 289 def CreateBranch(self): |
286 """Creates a new git branch or replaces an existing one.""" | 290 self.Checkout(self) |
287 if self.Exists(): | |
288 self.Delete() | |
289 self._Checkout(self.branch_name) | |
290 | 291 |
291 def _Checkout(self, target, create=True): | 292 def Checkout(self, target): |
292 """Function used internally to create and move between branches.""" | 293 """Function used to check out to another GitBranch.""" |
293 if create: | 294 if target.branch_name == self.tracking_branch or target.Exists(): |
294 git_cmd = 'git checkout -b %s %s' % (target, self.tracking_branch) | 295 git_cmd = 'git checkout %s' % target.branch_name |
295 else: | 296 else: |
296 git_cmd = 'git checkout %s' % target | 297 git_cmd = 'git checkout -b %s %s' % (target.branch_name, |
298 target.tracking_branch) | |
297 _SimpleRunCommand(git_cmd) | 299 _SimpleRunCommand(git_cmd) |
298 | 300 |
299 def Exists(self): | 301 def Exists(self): |
300 """Returns True if the branch exists.""" | 302 """Returns True if the branch exists.""" |
301 branch_cmd = 'git branch' | 303 branch_cmd = 'git branch' |
302 branches = _SimpleRunCommand(branch_cmd) | 304 branches = _SimpleRunCommand(branch_cmd) |
303 return self.branch_name in branches.split() | 305 return self.branch_name in branches.split() |
304 | 306 |
305 def Delete(self): | 307 def Delete(self): |
306 """Deletes the branch and returns the user to the master branch. | 308 """Deletes the branch and returns the user to the master branch. |
307 | 309 |
308 Returns True on success. | 310 Returns True on success. |
309 """ | 311 """ |
310 self._Checkout(self.tracking_branch, create=False) | 312 tracking_branch = GitBranch(self.tracking_branch, self.tracking_branch) |
313 self.Checkout(tracking_branch) | |
311 delete_cmd = 'git branch -D %s' % self.branch_name | 314 delete_cmd = 'git branch -D %s' % self.branch_name |
312 _SimpleRunCommand(delete_cmd) | 315 _SimpleRunCommand(delete_cmd) |
313 | 316 |
314 | 317 |
315 class EBuild(object): | 318 class EBuild(object): |
316 """Wrapper class for information about an ebuild.""" | 319 """Wrapper class for information about an ebuild.""" |
317 | 320 |
318 def __init__(self, path): | 321 def __init__(self, path): |
319 """Sets up data about an ebuild from its path.""" | 322 """Sets up data about an ebuild from its path.""" |
320 from portage.versions import pkgsplit | 323 from portage.versions import pkgsplit |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) | 566 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) |
564 worker.CommitChange(message) | 567 worker.CommitChange(message) |
565 revved_packages.append(ebuild.package) | 568 revved_packages.append(ebuild.package) |
566 new_package_atoms.append('=%s' % new_package) | 569 new_package_atoms.append('=%s' % new_package) |
567 except (OSError, IOError): | 570 except (OSError, IOError): |
568 Warning('Cannot rev %s\n' % ebuild.package, | 571 Warning('Cannot rev %s\n' % ebuild.package, |
569 'Note you will have to go into %s ' | 572 'Note you will have to go into %s ' |
570 'and reset the git repo yourself.' % overlay) | 573 'and reset the git repo yourself.' % overlay) |
571 raise | 574 raise |
572 | 575 |
573 if revved_packages: | 576 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms) |
574 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms) | 577 if gflags.FLAGS.drop_file: |
575 if gflags.FLAGS.drop_file: | 578 fh = open(gflags.FLAGS.drop_file, 'w') |
576 fh = open(gflags.FLAGS.drop_file, 'w') | 579 fh.write(' '.join(revved_packages)) |
577 fh.write(' '.join(revved_packages)) | 580 fh.close() |
578 fh.close() | |
579 else: | |
580 work_branch.Delete() | |
581 | 581 |
582 | 582 |
583 if __name__ == '__main__': | 583 if __name__ == '__main__': |
584 main(sys.argv) | 584 main(sys.argv) |
OLD | NEW |