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

Side by Side Diff: utils/tree-prune.py

Issue 9657005: Added depot_tools/utils, added util to prune dead git branches (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« 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')
Property Changes:
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """ A tool for listing branches with closed and abandoned issues."""
7
8 import os
9 import sys
10
11 try:
M-A Ruel 2012/03/13 14:16:02 Using this instead; BASE_DIR = os.path.dirname(os
groby-ooo-7-16 2012/03/14 20:39:51 Done.
12 import git_cl
13 except ImportError:
14 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
15 import git_cl
16
17 import urllib2
M-A Ruel 2012/03/13 14:16:02 Keep it grouped with system lib imports
groby-ooo-7-16 2012/03/14 20:39:51 Done.
18
19 def GetBranches():
M-A Ruel 2012/03/13 14:16:02 use PEP-8 style function naming, namely; def get_
groby-ooo-7-16 2012/03/14 20:39:51 Done.
20 """Get list of all local git branches."""
21 result = []
22 for branch_name in git_cl.RunGit(["branch"]).split():
M-A Ruel 2012/03/13 14:16:02 splitlines()
groby-ooo-7-16 2012/03/14 20:39:51 Done.
23 if branch_name != '*':
M-A Ruel 2012/03/13 14:16:02 Use branch_name[3:] instead
groby-ooo-7-16 2012/03/14 20:39:51 Done.
24 result.append(Branch(branch_name))
25 return result
M-A Ruel 2012/03/13 14:16:02 So in the end, the function looks like this: retu
groby-ooo-7-16 2012/03/14 20:39:51 Done.
26
27
28 class Branch(git_cl.Changelist):
29 def __init__(self, name):
30 git_cl.Changelist.__init__(self, branchref = name)
M-A Ruel 2012/03/13 14:16:02 argument default values don't have space, e.g. br
groby-ooo-7-16 2012/03/14 20:39:51 Done.
31 self._issue_status = None
32
33 def GetStatus(self):
34 if not self._issue_status:
35 if self.GetIssue() is not None:
M-A Ruel 2012/03/13 14:16:02 if self.GetIssue():
groby-ooo-7-16 2012/03/14 20:39:51 Done.
36 try:
37 issue_properties = self.RpcServer().get_issue_properties(
38 self.GetIssue(), None)
39 if issue_properties['closed']:
40 self._issue_status = 'closed'
41 else:
42 self._issue_status = 'pending'
43 except urllib2.HTTPError, e:
44 if e.code == 404:
45 self._issue_status = 'abandoned'
46 else:
47 self._issue_status = 'no-issue'
48 return self._issue_status
49
M-A Ruel 2012/03/13 14:16:02 2 lines between file level symbols
groby-ooo-7-16 2012/03/14 20:39:51 Done.
50 def main(argv):
51 branches = GetBranches()
52 filtered = { 'closed' : [],
53 'pending' : [],
54 'abandoned' : [],
55 'no-issue' : []}
56
57 for branch in branches:
58 filtered[branch.GetStatus()].append(branch)
59
60 print "# Branches with closed issues"
61 for branch in filtered['closed']:
62 print "git branch -D %s # Issue %s is closed." % (branch.GetBranch(),
63 branch.GetIssue())
64
65 print "\n# Pending Branches"
66 for branch in filtered['pending']:
67 print "# Branch %s - Issue %s" % (branch.GetBranch(), branch.GetIssue())
68
69
M-A Ruel 2012/03/13 14:16:02 remove extra line
groby-ooo-7-16 2012/03/14 20:39:51 Done.
70 print "\n# Branches with abandoned issues"
71 for branch in filtered['abandoned']:
72 print "# Branch %s - was issue %s" % (
73 branch.GetBranch(), branch.GetIssue())
74
75 print "\n# Branches without associated issues"
76 for branch in filtered['no-issue']:
77 print "# Branch %s" % (branch.GetBranch())
78
79 return 0
80
M-A Ruel 2012/03/13 14:16:02 add line
groby-ooo-7-16 2012/03/14 20:39:51 Done.
81 if __name__ == '__main__':
82 sys.exit(main(sys.argv[1:]))
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