Skip to content

Commit 7635788

Browse files
committed
Add git commits per date functionality
1 parent 22858cb commit 7635788

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ project's version. Not Yet Implemented means it does not exist yet:
6969
| **All Contributors (Sorted by Name)** | Completed ✔️ | Displays all contributors sorted alphabetically. |
7070
| **New Contributors (Sorted by Email)** | Completed ✔️ | Lists new contributors sorted by their email addresses. |
7171
| **Git Commits per Author** | Completed ✔️ | Counts commits made by each author. |
72-
| **Git Commits per Date** | Stubbed 🛠️ | Counts commits based on the date. |
72+
| **Git Commits per Date** | Completed ✔️ | Counts commits based on the date. |
7373
| **Git Commits per Month** | Stubbed 🛠️ | Counts commits based on the monthly. |
7474
| **Git Commits per Year** | Stubbed 🛠️ | Counts commits based on the year. |
7575
| **Git Commits per Weekday** | Stubbed 🛠️ | Counts commits based on the weekday. |

git_py_stats/list_cmds.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,48 @@ def git_commits_per_date() -> None:
390390
Displays commits grouped by date.
391391
"""
392392

393-
cmd = ['git', 'log', '--date=short', '--pretty=format:%cd']
393+
# Customizable vars in the future
394+
mailmap = "--use-mailmap"
395+
merges = "--no-merges"
396+
#log_options
397+
#pathspec
398+
399+
# Since can be hardcoded for now. It'll be based on the earliest commit
400+
# in the repo
401+
earliest_commit_date = run_git_command(['git', 'log', '--reverse', '--format=%ad'])
402+
if earliest_commit_date:
403+
# Take the first line as the earliest commit date
404+
first_commit_date = earliest_commit_date.split('\n')[0]
405+
since = f"--since='{first_commit_date}'"
406+
else:
407+
# If no commits, set since to an empty string
408+
since = ''
409+
410+
# Until will be current system's date and time
411+
now = datetime.now(timezone.utc).astimezone()
412+
until_formatted = now.strftime('%a, %d %b %Y %H:%M:%S %Z')
413+
until = f"--until='{until_formatted}'"
414+
415+
# Original command
416+
# git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" \
417+
# --date=short --format='%ad' $_log_options $_pathspec | sort | uniq -c
418+
cmd = ['git', '-c', 'log.showSignature=false', 'log', mailmap, merges,
419+
since, until, '--date=short', '--pretty=format:%ad']
420+
421+
# Print out the commit count and date in YYYY-MM-DD format
394422
output = run_git_command(cmd)
395423
if output:
396424
dates = output.split('\n')
397425
counter = collections.Counter(dates)
398-
print("Git commits per date:")
426+
print("Git commits per date:\n")
427+
428+
# Need to figure out the max count for width alignment purposes
429+
max_count = max(counter.values())
430+
count_width = len(str(max_count))
431+
432+
# Can now display this to the terminal
399433
for date, count in sorted(counter.items()):
400-
print(f"{date}: {count} commits")
434+
print(f"\t{count:>{count_width}} {date}")
401435
else:
402436
print('No commits found.')
403437

@@ -414,7 +448,7 @@ def git_commits_per_month() -> None:
414448
counter = collections.Counter(months)
415449
print("Git commits per month:")
416450
for month, count in sorted(counter.items()):
417-
print(f"{month}: {count} commits")
451+
print(f"{month} {count} commits")
418452
else:
419453
print('No commits found.')
420454

0 commit comments

Comments
 (0)