prune.py 1.9 KB

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