Skip to content

Commit

Permalink
Use an additional layer of dict
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Apr 9, 2024
1 parent 647aa41 commit 4bb0f5e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/sphinx_last_updated_by_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def to_relpath(f: Path) -> str:
exclude_commits = set(
map(lambda h: h.encode('utf-8'), app.config.git_exclude_commits))

domaindata = env.get_domain('last-updated-by-git').data
domaindata = env.get_domain('last-updated-by-git').timestamps
for docname, data in domaindata.items():
if data is not None:
continue # No need to update this source file
Expand Down Expand Up @@ -235,7 +235,7 @@ def _html_page_context(app, pagename, templatename, context, doctree):
assert context['sourcename'] == ''
return

data = app.env.get_domain('last-updated-by-git').data[pagename]
data = app.env.get_domain('last-updated-by-git').timestamps[pagename]
if data is None:
# There was a problem with git, a warning has already been issued
timestamp = None
Expand Down Expand Up @@ -279,19 +279,20 @@ class LastUpdatedByGitDomain(Domain):
# bump this when the format of `self.data` changes
data_version = 0

@property
def timestamps(self):
return self.data.setdefault('timestamps', {})

def clear_doc(self, docname):
try:
del self.data[docname]
except KeyError:
# This might happen with generic document names like "index"
pass
self.timestamps.pop(docname, None)

def merge_domaindata(self, docnames, otherdata):
for docname in docnames:
self.data[docname] = otherdata[docname]
for k, v in otherdata.items():
if k in docnames:
self.timestamps[k] = v

def process_doc(self, env, docname, document):
self.data[docname] = None
self.timestamps[docname] = None


def setup(app):
Expand Down

0 comments on commit 4bb0f5e

Please sign in to comment.