Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cd1374

Browse files
committed
Add option to display only commits newer than specified in days
1 parent 15edbb3 commit 1cd1374

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

GitViper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
parser.add_argument("-ln", "--log-number", type=int, default='5', help="specifiy the number of logs that will be shown")
2727
parser.add_argument("-tm", "--show-time", action='store_true', help="show time needed for each category")
2828
parser.add_argument("-inv", "--show-only", action='store_true', help="only show the given categories instead of hiding them")
29+
parser.add_argument("-d", "--max-days-old", type=int, default='0', help="specifiy the number of days to consider for the commit log")
2930

3031
args = parser.parse_args()
3132
#pprint(vars(args))
@@ -74,7 +75,7 @@ def finalize_category(category_is_visible):
7475
if args.hide_branches == args.show_only:
7576
finalize_category(gitviper.list_branches())
7677
if args.hide_logs == args.show_only:
77-
finalize_category(gitviper.list_logs(args.log_number))
78+
finalize_category(gitviper.list_logs(args.log_number, args.max_days_old))
7879
if args.hide_stash == args.show_only:
7980
finalize_category(gitviper.list_stash())
8081
if args.hide_status == args.show_only:

gitviper/log.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def __init__(self, date, relative_date, author, message):
2020
self.message = message
2121

2222

23-
def list_logs(num):
23+
def list_logs(num, max_days_old):
2424
if show_logs():
25-
log(num)
25+
log(num, max_days_old)
2626

2727
return True
2828

@@ -36,7 +36,7 @@ def show_logs():
3636

3737
return True
3838

39-
def log(max_commit_count):
39+
def log(max_commit_count, max_days_old):
4040
branch = connection.repo.active_branch
4141
num_commits = len(list(connection.repo.iter_commits(branch)))
4242
commits = list(connection.repo.iter_commits(branch, max_count = max_commit_count))
@@ -103,7 +103,19 @@ def log(max_commit_count):
103103

104104
max_col_widths[2] = msg_length
105105

106+
last_day_age = 0
106107
for commit in commit_arrays:
108+
# only print commits when maximum of days old
109+
if max_days_old > 0:
110+
if utilities.is_date_older_than_days(commit.date, max_days_old):
111+
break
112+
113+
# detect new day
114+
if last_day_age != utilities.age_in_days(commit.date):
115+
last_day_age = utilities.age_in_days(commit.date)
116+
print(CYAN + str("-" * int(w.x)) + RESET)
117+
118+
# actually print commit entries
107119
text = CYAN + commit.relative_date.ljust(max_col_widths[0]) + RESET
108120

109121
if multi_author:

0 commit comments

Comments
 (0)