Skip to content

Commit

Permalink
feat: reverted previous changes about exclude option, new option for …
Browse files Browse the repository at this point in the history
…follow introduced, added additional parameter for revision changes, diff-filter "r" is added for both creation and revision commit histories
  • Loading branch information
skywarth committed Sep 29, 2024
1 parent 466e577 commit f848ea1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/mkdocs_git_revision_date_localized_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GitRevisionDateLocalizedPlugin(BasePlugin):
("enable_creation_date", config_options.Type(bool, default=False)),
("enabled", config_options.Type(bool, default=True)),
("strict", config_options.Type(bool, default=True)),
("last_update_exclude_renames", config_options.Type(bool, default=False))
("version_history_follow_enabled", config_options.Type(bool, default=True))
)

def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]:
Expand Down
16 changes: 7 additions & 9 deletions src/mkdocs_git_revision_date_localized_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ def get_git_commit_timestamp(
realpath = os.path.realpath(path)
git = self._get_repo(realpath)

follow_option=self.config.get('version_history_follow_enabled')

if is_first_commit:
# diff_filter="A" will select the commit that created the file
commit_timestamp = git.log(
realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True, follow=True
realpath, date="unix", format="%at", diff_filter="Ar", no_show_signature=True, follow=follow_option
)
# A file can be created multiple times, through a file renamed.
# Commits are ordered with most recent commit first
Expand All @@ -92,16 +94,12 @@ def get_git_commit_timestamp(
commit_timestamp = commit_timestamp.split()[-1]
else:
# Latest commit touching a specific file
if self.config.get('last_update_exclude_renames'):
# We can remove if-else statement and do a one-liner as well
diff_filter_param = "r"
follow_param = True
else:
diff_filter_param = ""
follow_param = False
commit_timestamp = git.log(
realpath, date="unix", format="%at", diff_filter=diff_filter_param, n=1, no_show_signature=True, follow=follow_param
realpath, date="unix", format="%at",
diff_filter="r", n=1, no_show_signature=True, follow=follow_option,
ignore_all_space=True, ignore_blank_lines=True
)

except (InvalidGitRepositoryError, NoSuchPathError) as err:
if self.config.get('fallback_to_build_date'):
log(
Expand Down

0 comments on commit f848ea1

Please sign in to comment.