Browse Source

add git-branchp, curl_time

raylu 9 years ago
parent
commit
8163025aee
2 changed files with 46 additions and 0 deletions
  1. 8 0
      curl_time
  2. 38 0
      git-branchp

+ 8 - 0
curl_time

@@ -0,0 +1,8 @@
+    time_namelookup: %{time_namelookup}\n
+       time_connect: %{time_connect}\n
+    time_appconnect: %{time_appconnect}\n
+   time_pretransfer: %{time_pretransfer}\n
+      time_redirect: %{time_redirect}\n
+ time_starttransfer: %{time_starttransfer}\n
+                     -----\n
+         time_total: %{time_total}\n

+ 38 - 0
git-branchp

@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+# vim: set noet sw=4 ts=4:
+
+import subprocess
+import sys
+import time
+
+force = len(sys.argv) == 2 and sys.argv[1] == '-f'
+
+output = subprocess.check_output(['git', 'branch', '--merged', 'origin/master', '-a'], universal_newlines=True)
+branches = []
+for line in output.split('\n'):
+	if not line.startswith('  ') or ' -> ' in line:
+		continue
+	line = line[2:]
+	if line.startswith('remotes/origin/'):
+		line = line[8:]
+	branches.append(line)
+
+day_seconds = 24 * 60 * 60
+now = time.time()
+cutoff = now - 30 * day_seconds
+for branch in branches:
+	if branch == 'origin/master':
+		continue
+	output = subprocess.check_output(['git', 'show', branch, '-s', '--format=%at %ct'], universal_newlines=True)
+	if not output.endswith('\n'):
+		raise Exception()
+	timestamp = max(map(int, output[:-1].split(' ', 2)))
+	if timestamp > cutoff:
+		print('ignoring', branch)
+		continue
+
+	print('deleting %s (%.1f days old)' % (branch, (now - timestamp) / day_seconds))
+	if branch.startswith('origin/'):
+		subprocess.check_call(['git', 'push', 'origin', ':' + branch[7:]])
+	else:
+		subprocess.check_call(['git', 'branch', '-d', branch])