From 129020467c62d77d02a41ab8007b9478b1dc1951 Mon Sep 17 00:00:00 2001 From: Ray Burgemeestre Date: Tue, 14 Jan 2025 10:09:34 +0100 Subject: [PATCH 1/2] Add new --show-dates CLI flag --- bin/git-bc-show-eligible | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/git-bc-show-eligible b/bin/git-bc-show-eligible index 795d469..87cca37 100755 --- a/bin/git-bc-show-eligible +++ b/bin/git-bc-show-eligible @@ -5,6 +5,7 @@ from __future__ import unicode_literals import subprocess import argparse +import datetime import pygit2 import sys import re @@ -58,6 +59,8 @@ def main(): parser.add_argument('target_branch', metavar='TARGET_BRANCH', help='Name for the target branch', default='HEAD', nargs='?') parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit') + parser.add_argument('--show-dates', action='store_true', help='Show dates in %Y-%m-%d %H:%M:%S') + parser.add_argument('--all', action='store_true', help='Show commits from all users') top = find_toplevel() @@ -104,6 +107,14 @@ def main(): groups = [] current_group = [] for commit in find_unpicked(repo, from_commit, to_commit, since_commit, args.all): + formatted_date = '' + if args.show_dates: + timestamp = commit.commit_time # commit timestamp + offset = commit.commit_time_offset # timezone offset in minutes + commit_date = datetime.datetime.utcfromtimestamp(timestamp) + commit_date += datetime.timedelta(minutes=offset) + formatted_date = commit_date.strftime('%Y-%m-%d %H:%M:%S') + ' - ' + author_info = '' if args.all: author_info = author_format_str % (commit.author.name, commit.author.email) @@ -112,7 +123,7 @@ def main(): indent = commit_msg in seen seen += commit.message - commit_string = (commit_format_str % (str(commit.id), commit_msg, author_info)) + commit_string = formatted_date + (commit_format_str % (str(commit.id), commit_msg, author_info)) if indent: current_group.append(commit_string) From f9554356ea4d448dd7912f0f047a6104a2172429 Mon Sep 17 00:00:00 2001 From: Ray Burgemeestre Date: Tue, 14 Jan 2025 10:10:23 +0100 Subject: [PATCH 2/2] Reorder imports and add --always-colors flag --- bin/git-bc-show-eligible | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/git-bc-show-eligible b/bin/git-bc-show-eligible index 87cca37..b0d59e5 100755 --- a/bin/git-bc-show-eligible +++ b/bin/git-bc-show-eligible @@ -3,12 +3,12 @@ from __future__ import unicode_literals -import subprocess import argparse import datetime import pygit2 -import sys import re +import subprocess +import sys def find_toplevel(): try: @@ -62,6 +62,7 @@ def main(): parser.add_argument('--show-dates', action='store_true', help='Show dates in %Y-%m-%d %H:%M:%S') parser.add_argument('--all', action='store_true', help='Show commits from all users') + parser.add_argument('--always-colors', action='store_true', help='Always force colored output') top = find_toplevel() @@ -99,7 +100,7 @@ def main(): author_format_str = ' | %s <%s>' commit_format_str = '%s %s%s' - if sys.stdout.isatty(): + if sys.stdout.isatty() or args.always_colors: author_format_str = ' \033[31m| %s <%s>\033[0m' commit_format_str = '\033[33m%s\033[0m %s%s'