From 466e57767784a635f159e9bfcf5b03de6b5ed35d Mon Sep 17 00:00:00 2001 From: skywarth Date: Fri, 27 Sep 2024 15:04:07 +0300 Subject: [PATCH 1/3] feat: option for excluding renames and move operations for last update date --- src/mkdocs_git_revision_date_localized_plugin/plugin.py | 1 + src/mkdocs_git_revision_date_localized_plugin/util.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mkdocs_git_revision_date_localized_plugin/plugin.py b/src/mkdocs_git_revision_date_localized_plugin/plugin.py index f0360c9..0f3611e 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/src/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -43,6 +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)) ) def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]: diff --git a/src/mkdocs_git_revision_date_localized_plugin/util.py b/src/mkdocs_git_revision_date_localized_plugin/util.py index 1cbb474..cc8d6d1 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/util.py +++ b/src/mkdocs_git_revision_date_localized_plugin/util.py @@ -92,8 +92,15 @@ 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", n=1, no_show_signature=True + realpath, date="unix", format="%at", diff_filter=diff_filter_param, n=1, no_show_signature=True, follow=follow_param ) except (InvalidGitRepositoryError, NoSuchPathError) as err: if self.config.get('fallback_to_build_date'): From f848ea1e43ba61e131c26b5146bfb74cf14d9456 Mon Sep 17 00:00:00 2001 From: skywarth Date: Mon, 30 Sep 2024 00:31:44 +0300 Subject: [PATCH 2/3] feat: reverted previous changes about exclude option, new option for follow introduced, added additional parameter for revision changes, diff-filter "r" is added for both creation and revision commit histories --- .../plugin.py | 2 +- .../util.py | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/mkdocs_git_revision_date_localized_plugin/plugin.py b/src/mkdocs_git_revision_date_localized_plugin/plugin.py index 0f3611e..0b966b0 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/src/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -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]: diff --git a/src/mkdocs_git_revision_date_localized_plugin/util.py b/src/mkdocs_git_revision_date_localized_plugin/util.py index cc8d6d1..ced0f3c 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/util.py +++ b/src/mkdocs_git_revision_date_localized_plugin/util.py @@ -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 @@ -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( From 36b2159e63dea1f7d9eb1759a8ecdc5ecd215c03 Mon Sep 17 00:00:00 2001 From: skywarth Date: Sat, 12 Oct 2024 23:38:13 +0100 Subject: [PATCH 3/3] chore: rename option, add documentation --- docs/options.md | 8 ++++++++ src/mkdocs_git_revision_date_localized_plugin/plugin.py | 2 +- src/mkdocs_git_revision_date_localized_plugin/util.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/options.md b/docs/options.md index 98c9f99..3eabf8c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -133,6 +133,14 @@ export ENABLED_GIT_REVISION_DATE=false mkdocs serve ``` +## `enable_git_follow` + +Default is `true`. When enabled it will issue `--follow` option for git history tracing; meaning it will also track file's previous history for rename and move operations. + +When disabled (by setting it to `false`), each file's history will only consist of its current name and path, it's history from the previous paths or names will not be included. + +When enabled (by setting it to `true`), history tracking with `--follow` will be enabled and history will include the file's history from rename and other paths. + ## `strict` Default is `true`. When enabled, the logs will show warnings when something is wrong but a fallback has been used. When disabled, the logger will use the INFO level instead. diff --git a/src/mkdocs_git_revision_date_localized_plugin/plugin.py b/src/mkdocs_git_revision_date_localized_plugin/plugin.py index 0b966b0..4b7fef2 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/src/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -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)), - ("version_history_follow_enabled", config_options.Type(bool, default=True)) + ("enable_git_follow", config_options.Type(bool, default=True)) ) def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]: diff --git a/src/mkdocs_git_revision_date_localized_plugin/util.py b/src/mkdocs_git_revision_date_localized_plugin/util.py index ced0f3c..275f6b5 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/util.py +++ b/src/mkdocs_git_revision_date_localized_plugin/util.py @@ -80,7 +80,7 @@ def get_git_commit_timestamp( realpath = os.path.realpath(path) git = self._get_repo(realpath) - follow_option=self.config.get('version_history_follow_enabled') + follow_option=self.config.get('enable_git_follow') if is_first_commit: # diff_filter="A" will select the commit that created the file