Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

perf: improve git history processing for changelog generation#972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall 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
83 changes: 44 additions & 39 deletionssemantic_release/changelog/release_history.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,6 +41,13 @@ def from_git_history(
unreleased:dict[str,list[ParseResult]]=defaultdict(list)
released:dict[Version,Release]= {}

# Performance optimization: create a mapping of tag sha to version
# so we can quickly look up the version for a given commit based on sha
tag_sha_2_version_lookup= {
tag.commit.hexsha: (tag,version)
fortag,versioninall_git_tags_and_versions
}

# Strategy:
# Loop through commits in history, parsing as we go.
# Add these commits to `unreleased` as a key-value mapping
Expand All@@ -54,7 +61,7 @@ def from_git_history(
is_commit_released=False
the_version:Version|None=None

forcommitinrepo.iter_commits():
forcommitinrepo.iter_commits("HEAD",topo_order=True):
# mypy will be happy if we make this an explicit string
commit_message=str(commit.message)

Expand All@@ -64,46 +71,44 @@ def from_git_history(
)
log.debug("commit has type %s",commit_type)

fortag,versioninall_git_tags_and_versions:
iftag.commit==commit:
# we have found the latest commit introduced by this tag
# so we create a new Release entry
log.debug("found commit %s for tag %s",commit.hexsha,tag.name)
is_commit_released=True
the_version=version

# tag.object is a Commit if the tag is lightweight, otherwise
# it is a TagObject with additional metadata about the tag
ifisinstance(tag.object,TagObject):
tagger=tag.object.tagger
committer=tag.object.tagger.committer()
_tz=timezone(
timedelta(seconds=-1*tag.object.tagger_tz_offset)
)
tagged_date=datetime.fromtimestamp(
tag.object.tagged_date,tz=_tz
)
else:
# For some reason, sometimes tag.object is a Commit
tagger=tag.object.author
committer=tag.object.author
_tz=timezone(
timedelta(seconds=-1*tag.object.author_tz_offset)
)
tagged_date=datetime.fromtimestamp(
tag.object.committed_date,tz=_tz
)

release=Release(
tagger=tagger,
committer=committer,
tagged_date=tagged_date,
elements=defaultdict(list),
version=the_version,
log.debug("checking if commit %s matches any tags",commit.hexsha)
t_v=tag_sha_2_version_lookup.get(commit.hexsha,None)

ift_visNone:
log.debug("no tags correspond to commit %s",commit.hexsha)
else:
# Unpack the tuple (overriding the current version)
tag,the_version=t_v
# we have found the latest commit introduced by this tag
# so we create a new Release entry
log.debug("found commit %s for tag %s",commit.hexsha,tag.name)
is_commit_released=True

# tag.object is a Commit if the tag is lightweight, otherwise
# it is a TagObject with additional metadata about the tag
ifisinstance(tag.object,TagObject):
tagger=tag.object.tagger
committer=tag.object.tagger.committer()
_tz=timezone(timedelta(seconds=-1*tag.object.tagger_tz_offset))
tagged_date=datetime.fromtimestamp(tag.object.tagged_date,tz=_tz)
else:
# For some reason, sometimes tag.object is a Commit
tagger=tag.object.author
committer=tag.object.author
_tz=timezone(timedelta(seconds=-1*tag.object.author_tz_offset))
tagged_date=datetime.fromtimestamp(
tag.object.committed_date,tz=_tz
)

released.setdefault(the_version,release)
break
release=Release(
tagger=tagger,
committer=committer,
tagged_date=tagged_date,
elements=defaultdict(list),
version=the_version,
)

released.setdefault(the_version,release)

ifany(pat.match(commit_message)forpatinexclude_commit_patterns):
log.debug(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp