prune.py 1.8 KB

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