Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign commits to versions following their commit graph (fixes #70) #72

Merged
merged 20 commits into from
Mar 14, 2024

Conversation

chme
Copy link
Contributor

@chme chme commented Mar 9, 2024

This is my attempt at fixing #70.

The solution in this PR is different from #70, but in my opinion, it makes the code easier to read and understand.
The first solution had some issues with certain commit graphs (especially, when there are more than one previous version).

I made the following assumptions:

  • A commit should only be listed in exactly one version. And this version is the oldest version.
  • The previous version is the one that is found when following the left branch of the commit graph (ignoring merges).

I'll need to test this a bit more (especially if the last assumption is OK), but wanted to open this PR to get an early feedback.

I removed the Version.next_version field. If it is better to keep it, I can reintroduce it.

One of the tests has an ugly sleep(1) in it. Unfortunately Git only has second precision and without the sleep, the comit order of git log is undetermined for commits that happen in the same second (and are not related).

And one final not, this PR is based on #71.

chme added 7 commits March 9, 2024 20:36
Before a commit was assigned the version/tag that happened next in the timeline. This leads to versions referencing commits that are not ancestors of it (and therefor not part of this version).

Instead the versions should contain only all commits that are ancestors, up until a new version is encountered.
Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions. I'm going to review the rest in my editor as I think I'll probably modify the code a bit. I'll add a review here once I'm confident about my changes 🙂

src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Show resolved Hide resolved
@pawamoy
Copy link
Owner

pawamoy commented Mar 11, 2024

I went ahead and applied the suggestions, I hope you don't mind 🙂
I've also pushed a fixup commit with the changes I was talking about. Basically, where you had a TODO about perfs, I changed the code to use a map of commits. This map is passed to each Commit object, so they can hydrate their parent commits from their hashes only, in a property. A commit's parent commits will therefore always be up-to-date when we modify its parent hashes directly.

Other changes are to maintain backward compatibility. The parse_commits method keeps returning the list of all commits, and we build the list of tag commits in the above layer by iterating on them.

Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more cosmetic changes.

src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/commit.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
pawamoy

This comment was marked as outdated.

src/git_changelog/build.py Outdated Show resolved Hide resolved
@pawamoy
Copy link
Owner

pawamoy commented Mar 11, 2024

OK, sorry for the spam haha, just two more comments for which I'd like to hear your opinion 😄
Thank you so much for this contribution, this is really, really great!

@chme
Copy link
Contributor Author

chme commented Mar 12, 2024

I added a commit, that changes how the previous version is found.

As you can see in the test case "test_two_release_branches" it is a bit odd / unexpected, that the previous version of "unreleased" was 1.1.0 (instead of 2.0.0). And even stranger, that version 2.0.0 did not have a previous version.

Thinking about it, in my opinion, it is best to use the highest semantic version, that is found in the commit graph.
If you want more test cases, let me know if there are specific scenarios you are interested in being covered by a test.

@pawamoy
Copy link
Owner

pawamoy commented Mar 12, 2024

As you can see in the test case "test_two_release_branches" it is a bit odd / unexpected, that the previous version of "unreleased" was 1.1.0 (instead of 2.0.0). And even stranger, that version 2.0.0 did not have a previous version.
Thinking about it, in my opinion, it is best to use the highest semantic version, that is found in the commit graph.

That is a good remark. I think I agree with you: all versions that are not already present in the changelog should be ordered semantically (semver) rather than chronologically (tag date). It's particularly important for the "compare with previous version" URL, since we probably only want to compare a version with its semantically previous one, not the chronologically previous one.

Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes.

src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
src/git_changelog/build.py Outdated Show resolved Hide resolved
@pawamoy
Copy link
Owner

pawamoy commented Mar 12, 2024

(If you can, try to avoid force-pushing, as it makes reviewing a bit more difficult 😉)

chme and others added 2 commits March 13, 2024 20:11
Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
@chme
Copy link
Contributor Author

chme commented Mar 13, 2024

I think, I addressed all review comments. Let me know, if there is something else to do for this MR.

Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@pawamoy pawamoy merged commit f191ed7 into pawamoy:main Mar 14, 2024
16 checks passed
@chme chme deleted the fix/assign-versions-3 branch March 17, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants