total-contributions: Fix bug that replaced a repo's whole history with nothing.

When using a start date before the first commit to a repo, we should
include the repo's entire history (up to the end date) in our totals.

Instead, we were using a range like "..{upper_version}", which in Git
revision-range syntax means the start of the range is HEAD -- so the
range was empty.

Fix that by leaving out the ".." when we want no left endpoint.
This commit is contained in:
Greg Price
2023-05-19 17:23:59 -07:00
committed by Tim Abbott
parent 0c8fef2fc8
commit c4cc27cd20

View File

@@ -27,9 +27,9 @@ def add_log(committer_dict: Dict[str, int], input: List[str]) -> None:
committer_dict[committer_name] += commit_count
def retrieve_log(repo: str, lower_version: str, upper_version: str) -> List[str]:
def retrieve_log(repo: str, revisions: str) -> List[str]:
return subprocess.check_output(
["git", "shortlog", "-s", lower_version + ".." + upper_version],
["git", "shortlog", "-s", revisions],
cwd=find_path(repo),
text=True,
).splitlines()
@@ -47,15 +47,21 @@ def process_repo(
lower_version: str,
upper_version: str,
) -> None:
if not lower_version:
revisions = upper_version
revisions_display = f"(start)..{upper_version[0:12]}"
else:
revisions = f"{lower_version}..{upper_version}"
revisions_display = f"{lower_version[0:12]}..{upper_version[0:12]}"
commit_count = len(
subprocess.check_output(
["git", "log", "--pretty=oneline", f"{lower_version}..{upper_version}"],
["git", "log", "--pretty=oneline", revisions],
cwd=find_path(repo_short),
text=True,
).splitlines()
)
repo_log = retrieve_log(repo_short, lower_version, upper_version)
print(f"{commit_count} commits from {repo_full}: {lower_version[0:12]}..{upper_version[0:12]}")
repo_log = retrieve_log(repo_short, revisions)
print(f"{commit_count} commits from {repo_full}: {revisions_display}")
add_log(out_dict, repo_log)