-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- pyproject.toml - xkcd style. - argparse.
- Loading branch information
Showing
6 changed files
with
61 additions
and
75 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
[project] | ||
name = "git-lines-graph" | ||
version = "2.0.0" | ||
description = "Git commit lines graph" | ||
readme = "README.md" | ||
requires-python = ">=3.9" | ||
dependencies = [ | ||
"gitpython>=3.1.43", | ||
"matplotlib>=3.9.2", | ||
"pandas>=2.2.2", | ||
] | ||
|
||
[project.scripts] | ||
git-lines-graph = "git_lines_graph:main" | ||
|
||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project.urls] | ||
Repository = "https://github.com/danielfleischer/git-commits-lines-graph" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import argparse | ||
import os | ||
|
||
import git | ||
import matplotlib as mpl | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("git_dir", type=str, help="Git directory") | ||
parser.add_argument("-b", "--branch", type=str, default=None, help="Branch to browse") | ||
|
||
args = parser.parse_args() | ||
git_dir = args.git_dir | ||
branch = args.branch | ||
|
||
try: | ||
repo = git.repo.Repo(git_dir) | ||
except git.exc.InvalidGitRepositoryError as e: | ||
print("Not a valid git project: {}".format(git_dir)) | ||
exit() | ||
|
||
data = [] | ||
for i in reversed(list(repo.iter_commits(rev=branch))): | ||
diff = i.stats.total | ||
data.append([i.committed_datetime.isoformat(), diff["insertions"], diff["deletions"]]) | ||
|
||
data = pd.DataFrame(data, columns=["date", "add", "remove"]) | ||
data["delta"] = data["add"] - data["remove"] | ||
data["total"] = data.delta.cumsum() | ||
data.date = pd.to_datetime(data.date) | ||
data.set_index(["date"], inplace=True) | ||
|
||
with plt.xkcd(): | ||
plt.figure("Code Lines Progress in project {}".format(os.path.basename(git_dir))) | ||
plt.ylabel("# of lines") | ||
ax = data["total"].plot() | ||
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter("{x:,.0f}")) | ||
plt.show() |