@@ -27,13 +27,14 @@ class Util:
2727 This helps find git and calculate relevant dates.
2828 """
2929
30- def __init__ (self , config = {} ):
30+ def __init__ (self , config : Dict , mkdocs_dir : str ):
3131 """Initialize utility class."""
3232 self .config = config
3333 self .repo_cache = {}
3434
3535 ignore_commits_file = self .config .get ("ignored_commits_file" )
36- self .ignored_commits = self .parse_git_ignore_revs (ignore_commits_file ) if ignore_commits_file else []
36+ ignore_commits_filepath = os .path .join (mkdocs_dir , ignore_commits_file ) if ignore_commits_file else None
37+ self .ignored_commits = self .parse_git_ignore_revs (ignore_commits_filepath ) if ignore_commits_file else []
3738
3839 def _get_repo (self , path : str ) -> Git :
3940 if not os .path .isdir (path ):
@@ -66,6 +67,7 @@ def get_git_commit_timestamp(
6667 int: commit date in unix timestamp, starts with the most recent commit.
6768 """
6869 commit_timestamp = ""
70+ n_ignored_commits = 0
6971
7072 # Determine the logging level
7173 # Only log warnings when plugin is set to strict.
@@ -111,14 +113,17 @@ def get_git_commit_timestamp(
111113 ).split ("\n " )
112114
113115 # process the commits for the file in reverse-chronological order. Ignore any commit that is on the
114- # ignored list. If the line is empty, we've reached the end and need to use the fallback behavior
116+ # ignored list. If the line is empty, we've reached the end and need to use the fallback behavior.
115117 for line in lines :
116118 if not line :
117119 commit_timestamp = ""
118120 break
119121 commit , commit_timestamp = line .split (" " )
120122 if not any (commit .startswith (x ) for x in self .ignored_commits ):
121123 break
124+ else :
125+ n_ignored_commits += 1
126+
122127
123128 except (InvalidGitRepositoryError , NoSuchPathError ) as err :
124129 if self .config .get ('fallback_to_build_date' ):
@@ -165,10 +170,13 @@ def get_git_commit_timestamp(
165170 # create timestamp
166171 if commit_timestamp == "" :
167172 commit_timestamp = time .time ()
168- log (
173+ msg = (
169174 "[git-revision-date-localized-plugin] '%s' has no git logs, using current timestamp"
170175 % path
171176 )
177+ if n_ignored_commits :
178+ msg += f" (ignored { n_ignored_commits } commits)"
179+ log (msg )
172180
173181 return int (commit_timestamp )
174182
@@ -222,10 +230,17 @@ def parse_git_ignore_revs(filename: str) -> List[str]:
222230 Whitespace, blanklines and comments starting with # are all ignored.
223231 """
224232 result = []
225- with open (filename , "rt" ) as f :
226- for line in f :
227- line = line .split ("#" , 1 )[0 ].strip ()
228- if not line :
229- continue
230- result .append (line )
233+
234+ try :
235+ with open (filename , "rt" , encoding = 'utf-8' ) as f :
236+ for line in f :
237+ line = line .split ("#" , 1 )[0 ].strip ()
238+ if not line :
239+ continue
240+ result .append (line )
241+ except FileNotFoundError :
242+ logger .error (f"File not found: { filename } " )
243+ except Exception as e :
244+ logger .error (f"An error occurred while reading the file { filename } : { e } " )
245+
231246 return result
0 commit comments