Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: git_utils/git-tree-prune

Issue 14602017: Allow branches without upstream. (Closed) Base URL: http://src.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Lists branches with closed and abandoned issues.""" 6 """Lists branches with closed and abandoned issues."""
7 7
8 import optparse 8 import optparse
9 import os 9 import os
10 import sys 10 import sys
(...skipping 12 matching lines...) Expand all
23 ["for-each-ref", 23 ["for-each-ref",
24 "--format=%(refname:short) %(upstream:short)", 24 "--format=%(refname:short) %(upstream:short)",
25 "refs/heads"]).splitlines()] 25 "refs/heads"]).splitlines()]
26 return [Branch(*b) for b in branches] 26 return [Branch(*b) for b in branches]
27 27
28 def get_change_count(start, end): 28 def get_change_count(start, end):
29 return int(git_cl.RunGit(["rev-list", "%s..%s" % (start, end), "--count" ])) 29 return int(git_cl.RunGit(["rev-list", "%s..%s" % (start, end), "--count" ]))
30 30
31 31
32 class Branch(git_cl.Changelist): 32 class Branch(git_cl.Changelist):
33 def __init__(self, name, upstream): 33 def __init__(self, name, upstream=None):
34 git_cl.Changelist.__init__(self, branchref=name) 34 git_cl.Changelist.__init__(self, branchref=name)
35 self._upstream = upstream 35 self._upstream = upstream
36 self._distance = None 36 self._distance = None
37 self._issue_status = None 37 self._issue_status = None
38 38
39 def GetStatus(self): 39 def GetStatus(self):
40 if not self._issue_status: 40 if not self._issue_status:
41 if self.GetIssue(): 41 if self.GetIssue():
42 try: 42 try:
43 issue_properties = self.RpcServer().get_issue_properties( 43 issue_properties = self.RpcServer().get_issue_properties(
44 self.GetIssue(), None) 44 self.GetIssue(), None)
45 if issue_properties['closed']: 45 if issue_properties['closed']:
46 self._issue_status = 'closed' 46 self._issue_status = 'closed'
47 else: 47 else:
48 self._issue_status = 'pending' 48 self._issue_status = 'pending'
49 except urllib2.HTTPError, e: 49 except urllib2.HTTPError, e:
50 if e.code == 404: 50 if e.code == 404:
51 self._issue_status = 'abandoned' 51 self._issue_status = 'abandoned'
52 else: 52 else:
53 self._issue_status = 'no-issue' 53 self._issue_status = 'no-issue'
54 if (self._issue_status != 'pending' 54 if (self._issue_status != 'pending'
55 and self._upstream
55 and not self.GetDistance()[0] 56 and not self.GetDistance()[0]
56 and not self._upstream.startswith("origin/")): 57 and not self._upstream.startswith("origin/")):
57 self._issue_status = 'empty' 58 self._issue_status = 'empty'
58 return self._issue_status 59 return self._issue_status
59 60
60 def GetDistance(self): 61 def GetDistance(self):
62 if self._upstream is None:
63 return None;
61 if not self._distance: 64 if not self._distance:
62 self._distance = [get_change_count(self._upstream, self.GetBranch()), 65 self._distance = [get_change_count(self._upstream, self.GetBranch()),
63 get_change_count(self.GetBranch(), self._upstream)] 66 get_change_count(self.GetBranch(), self._upstream)]
64 return self._distance 67 return self._distance
65 68
66 def GetDistanceInfo(self): 69 def GetDistanceInfo(self):
70 if not self._upstream:
71 return "<No upstream branch>"
67 formatted_dist = ", ".join(["%s %d" % (x,y) 72 formatted_dist = ", ".join(["%s %d" % (x,y)
68 for (x,y) in zip(["ahead","behind"], self.GetDistance()) if y]) 73 for (x,y) in zip(["ahead","behind"], self.GetDistance()) if y])
69 return "[%s%s]" % ( 74 return "[%s%s]" % (
70 self._upstream, ": " + formatted_dist if formatted_dist else "") 75 self._upstream, ": " + formatted_dist if formatted_dist else "")
71 76
77 def print_branches(title, fmt, branches):
78 if branches:
79 print title
80 for branch in branches:
81 print fmt.format(branch=branch.GetBranch(),
82 issue=branch.GetIssue(),
83 distance=branch.GetDistanceInfo())
84
72 def main(): 85 def main():
73 parser = optparse.OptionParser(usage=sys.modules['__main__'].__doc__) 86 parser = optparse.OptionParser(usage=sys.modules['__main__'].__doc__)
74 options, args = parser.parse_args() 87 options, args = parser.parse_args()
75 if args: 88 if args:
76 parser.error('Unsupported arg: %s' % args) 89 parser.error('Unsupported arg: %s' % args)
77 90
78 branches = get_branches() 91 branches = get_branches()
79 filtered = { 'closed' : [], 92 filtered = { 'closed' : [],
80 'empty' : [], 93 'empty' : [],
81 'pending' : [], 94 'pending' : [],
82 'abandoned' : [], 95 'abandoned' : [],
83 'no-issue' : []} 96 'no-issue' : []}
84 97
85 for branch in branches: 98 for branch in branches:
86 filtered[branch.GetStatus()].append(branch) 99 filtered[branch.GetStatus()].append(branch)
87 100
88 print "# Branches with closed issues" 101 print_branches("# Branches with closed issues",
89 for branch in filtered['closed']: 102 "git branch -D {branch} # Issue {issue} is closed.",
90 print "git branch -D %s # Issue %s is closed." % (branch.GetBranch(), 103 filtered['closed'])
91 branch.GetIssue()) 104 print_branches("\n# Empty branches",
105 "git branch -D {branch} # Empty.",
106 filtered['empty'])
107 print_branches("\n# Pending Branches",
108 "# Branch {branch} - Issue {issue} - {distance}",
109 filtered['pending']);
110 print_branches("\n# Branches with abandoned issues",
111 "# Branch {branch} - was issue {issue} - {distance}",
112 filtered['abandoned'])
92 113
93 print "# Empty branches" 114 print_branches("\n# Branches without associated issues",
94 for branch in filtered['empty']: 115 "# Branch {branch} - {distance}",
95 print "git branch -D %s # Empty." % (branch.GetBranch()) 116 filtered['no-issue'])
96
97 print "\n# Pending Branches"
98 for branch in filtered['pending']:
99 print "# Branch %s - Issue %s - %s" % (
100 branch.GetBranch(), branch.GetIssue(), branch.GetDistanceInfo())
101
102 print "\n# Branches with abandoned issues"
103 for branch in filtered['abandoned']:
104 print "# Branch %s - was issue %s - %s" % (
105 branch.GetBranch(), branch.GetIssue(), branch.GetDistanceInfo())
106
107 print "\n# Branches without associated issues"
108 for branch in filtered['no-issue']:
109 print "# Branch %s - %s" % (branch.GetBranch(), branch.GetDistanceInfo())
110 117
111 return 0 118 return 0
112 119
113 120
114 if __name__ == '__main__': 121 if __name__ == '__main__':
115 sys.exit(main()) 122 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698