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

Unified 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, 8 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: git_utils/git-tree-prune
===================================================================
--- git_utils/git-tree-prune (revision 197697)
+++ git_utils/git-tree-prune (working copy)
@@ -30,7 +30,7 @@
class Branch(git_cl.Changelist):
- def __init__(self, name, upstream):
+ def __init__(self, name, upstream=None):
git_cl.Changelist.__init__(self, branchref=name)
self._upstream = upstream
self._distance = None
@@ -52,23 +52,36 @@
else:
self._issue_status = 'no-issue'
if (self._issue_status != 'pending'
+ and self._upstream
and not self.GetDistance()[0]
and not self._upstream.startswith("origin/")):
self._issue_status = 'empty'
return self._issue_status
def GetDistance(self):
+ if self._upstream is None:
+ return None;
if not self._distance:
self._distance = [get_change_count(self._upstream, self.GetBranch()),
get_change_count(self.GetBranch(), self._upstream)]
return self._distance
def GetDistanceInfo(self):
+ if not self._upstream:
+ return "<No upstream branch>"
formatted_dist = ", ".join(["%s %d" % (x,y)
for (x,y) in zip(["ahead","behind"], self.GetDistance()) if y])
return "[%s%s]" % (
self._upstream, ": " + formatted_dist if formatted_dist else "")
+def print_branches(title, fmt, branches):
+ if branches:
+ print title
+ for branch in branches:
+ print fmt.format(branch=branch.GetBranch(),
+ issue=branch.GetIssue(),
+ distance=branch.GetDistanceInfo())
+
def main():
parser = optparse.OptionParser(usage=sys.modules['__main__'].__doc__)
options, args = parser.parse_args()
@@ -85,29 +98,23 @@
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_branches("# Branches with closed issues",
+ "git branch -D {branch} # Issue {issue} is closed.",
+ filtered['closed'])
+ print_branches("\n# Empty branches",
+ "git branch -D {branch} # Empty.",
+ filtered['empty'])
+ print_branches("\n# Pending Branches",
+ "# Branch {branch} - Issue {issue} - {distance}",
+ filtered['pending']);
+ print_branches("\n# Branches with abandoned issues",
+ "# Branch {branch} - was issue {issue} - {distance}",
+ filtered['abandoned'])
- print "# Empty branches"
- for branch in filtered['empty']:
- print "git branch -D %s # Empty." % (branch.GetBranch())
+ print_branches("\n# Branches without associated issues",
+ "# Branch {branch} - {distance}",
+ filtered['no-issue'])
- print "\n# Pending Branches"
- for branch in filtered['pending']:
- print "# Branch %s - Issue %s - %s" % (
- branch.GetBranch(), branch.GetIssue(), branch.GetDistanceInfo())
-
- print "\n# Branches with abandoned issues"
- for branch in filtered['abandoned']:
- print "# Branch %s - was issue %s - %s" % (
- branch.GetBranch(), branch.GetIssue(), branch.GetDistanceInfo())
-
- print "\n# Branches without associated issues"
- for branch in filtered['no-issue']:
- print "# Branch %s - %s" % (branch.GetBranch(), branch.GetDistanceInfo())
-
return 0
« 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