forked from tkrajina/git-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-recent
executable file
·75 lines (59 loc) · 2.55 KB
/
git-recent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2013 Tomo Krajina
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys as mod_sys
import argparse as mod_argparse
import time as mod_time
import gitutils as mod_gitutils
mod_gitutils.assert_in_git_repository()
parser = mod_argparse.ArgumentParser(
description='Show list of branches sorted by last commit time')
parser.add_argument('-r', '--remote', action='store_true',
default=False, help='Get remote branches')
parser.add_argument('-a', '--all', action='store_true',
default=False, help='Get all (local and remote) branches')
parser.add_argument('--no-merged', action='store_true',
default=False, help='Only *not* merged branches')
parser.add_argument('--merged', action='store_true',
default=False, help='Only merged branches')
parser.add_argument('entries', metavar='entries', type=int, default=1000, nargs='?',
help='Number of entries (negative number if you want the last N entries)')
args = parser.parse_args()
now = mod_time.time()
times_and_branches = []
branches = mod_gitutils.get_branches(args.remote, merged=args.merged, no_merged=args.no_merged, all=args.all)
for branch in branches:
cmd = 'log ' + branch + ' -1 --format=%at'
success, result = mod_gitutils.execute_git(cmd, output=False)
if not success:
mod_sys.stderr.write(cmd)
mod_sys.stderr.write(result)
if (not success) or (len(result.strip()) == 0):
print 'Cannot find the age of %s' % branch
else:
time_diff_seconds = int(now) - int(result)
time_diff_days = int((float(time_diff_seconds) / (60*60*24)) * 100) / 100.
times_and_branches.append((time_diff_seconds, '%10s days: %s' % (time_diff_days, branch), ))
times_and_branches.sort()
try:
entries = int(args.entries)
except:
entries = 1000
if entries > 0:
times_and_branches = times_and_branches[:entries]
if entries < 0:
times_and_branches = times_and_branches[entries:]
for _, branch in times_and_branches:
print branch