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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tree-prune.py
===================================================================
--- utils/tree-prune.py (revision 0)
+++ utils/tree-prune.py (revision 0)
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+""" A tool for listing branches with closed and abandoned issues."""
+
+import os
+import sys
+
+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.
+ import git_cl
+except ImportError:
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+ import git_cl
+
+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.
+
+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.
+ """Get list of all local git branches."""
+ result = []
+ 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.
+ 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.
+ result.append(Branch(branch_name))
+ 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.
+
+
+class Branch(git_cl.Changelist):
+ def __init__(self, name):
+ 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.
+ self._issue_status = None
+
+ def GetStatus(self):
+ if not self._issue_status:
+ 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.
+ try:
+ issue_properties = self.RpcServer().get_issue_properties(
+ self.GetIssue(), None)
+ if issue_properties['closed']:
+ self._issue_status = 'closed'
+ else:
+ self._issue_status = 'pending'
+ except urllib2.HTTPError, e:
+ if e.code == 404:
+ self._issue_status = 'abandoned'
+ else:
+ self._issue_status = 'no-issue'
+ return self._issue_status
+
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.
+def main(argv):
+ branches = GetBranches()
+ filtered = { 'closed' : [],
+ 'pending' : [],
+ 'abandoned' : [],
+ 'no-issue' : []}
+
+ for branch in branches:
+ filtered[branch.GetStatus()].append(branch)
+
+ print "# Branches with closed issues"
+ for branch in filtered['closed']:
+ print "git branch -D %s # Issue %s is closed." % (branch.GetBranch(),
+ branch.GetIssue())
+
+ print "\n# Pending Branches"
+ for branch in filtered['pending']:
+ print "# Branch %s - Issue %s" % (branch.GetBranch(), branch.GetIssue())
+
+
M-A Ruel 2012/03/13 14:16:02 remove extra line
groby-ooo-7-16 2012/03/14 20:39:51 Done.
+ print "\n# Branches with abandoned issues"
+ for branch in filtered['abandoned']:
+ print "# Branch %s - was issue %s" % (
+ branch.GetBranch(), branch.GetIssue())
+
+ print "\n# Branches without associated issues"
+ for branch in filtered['no-issue']:
+ print "# Branch %s" % (branch.GetBranch())
+
+ return 0
+
M-A Ruel 2012/03/13 14:16:02 add line
groby-ooo-7-16 2012/03/14 20:39:51 Done.
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
Property changes on: utils/tree-prune.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
« 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