prune.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright (C) 2008 The Android Open Source Project
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from __future__ import print_function
  17. from color import Coloring
  18. from command import PagedCommand
  19. class Prune(PagedCommand):
  20. common = True
  21. helpSummary = "Prune (delete) already merged topics"
  22. helpUsage = """
  23. %prog [<project>...]
  24. """
  25. def Execute(self, opt, args):
  26. all_branches = []
  27. for project in self.GetProjects(args):
  28. all_branches.extend(project.PruneHeads())
  29. if not all_branches:
  30. return
  31. class Report(Coloring):
  32. def __init__(self, config):
  33. Coloring.__init__(self, config, 'status')
  34. self.project = self.printer('header', attr='bold')
  35. out = Report(all_branches[0].project.config)
  36. out.project('Pending Branches')
  37. out.nl()
  38. project = None
  39. for branch in all_branches:
  40. if project != branch.project:
  41. project = branch.project
  42. out.nl()
  43. out.project('project %s/' % project.relpath)
  44. out.nl()
  45. print('%s %-33s ' % (
  46. branch.name == project.CurrentBranch and '*' or ' ',
  47. branch.name), end='')
  48. if not branch.base_exists:
  49. print('(ignoring: tracking branch is gone: %s)' % (branch.base,))
  50. else:
  51. commits = branch.commits
  52. date = branch.date
  53. print('(%2d commit%s, %s)' % (
  54. len(commits),
  55. len(commits) != 1 and 's' or ' ',
  56. date))