Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions deepmodeling_sphinx/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@

import os
import subprocess
import warnings
from typing import Any, Dict, Iterator

from sphinx.application import Sphinx
from sphinx.util.docutils import SphinxDirective


def _is_shallow_repository() -> bool:
"""Return whether the current repository is shallow."""
return (
subprocess.check_output(["git", "rev-parse", "--is-shallow-repository"])
.decode("utf-8")
.strip()
== "true"
)


def _fetch_full_history() -> None:
"""Fetch complete history without downloading blob contents when possible."""
try:
subprocess.check_call(["git", "fetch", "--unshallow", "--filter=blob:none"])
except subprocess.CalledProcessError:
warnings.warn(
"Unable to fetch the complete git history with --filter=blob:none. "
"The generated author list may be incomplete.",
RuntimeWarning,
stacklevel=2,
)


def git_shortlog() -> str:
"""Return git-shortlog output as a string.

Expand All @@ -16,16 +40,8 @@ def git_shortlog() -> str:
str
Git-shortlog output.
"""
if os.environ.get("READTHEDOCS", None) == "True":
# check if it shallow clone
output_git_rev_parse = (
subprocess.check_output(["git", "rev-parse", "--is-shallow-repository"])
.decode("utf-8")
.strip()
)
if output_git_rev_parse == "true":
# fetch full history
subprocess.check_output(["git", "fetch", "--unshallow"])
if os.environ.get("READTHEDOCS", None) == "True" and _is_shallow_repository():
_fetch_full_history()
return subprocess.check_output(["git", "shortlog", "HEAD", "-s"]).decode("utf-8")


Expand Down