prune.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 color import Coloring
  16. from command import PagedCommand
  17. class Prune(PagedCommand):
  18. common = True
  19. helpSummary = "Prune (delete) already merged topics"
  20. helpUsage = """
  21. %prog [<project>...]
  22. """
  23. def Execute(self, opt, args):
  24. all = []
  25. for project in self.GetProjects(args):
  26. all.extend(project.PruneHeads())
  27. if not all:
  28. return
  29. class Report(Coloring):
  30. def __init__(self, config):
  31. Coloring.__init__(self, config, 'status')
  32. self.project = self.printer('header', attr='bold')
  33. out = Report(all[0].project.config)
  34. out.project('Pending Branches')
  35. out.nl()
  36. project = None
  37. for branch in all:
  38. if project != branch.project:
  39. project = branch.project
  40. out.nl()
  41. out.project('project %s/' % project.relpath)
  42. out.nl()
  43. commits = branch.commits
  44. date = branch.date
  45. print '%s %-33s (%2d commit%s, %s)' % (
  46. branch.name == project.CurrentBranch and '*' or ' ',
  47. branch.name,
  48. len(commits),
  49. len(commits) != 1 and 's' or ' ',
  50. date)