fix: the sort order of commits is unstable #210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
sort.SliceStable
instead ofsort.Slice
to sort commits.Closes #209
What does this do / why do we need it?
This change uses
sort.SliceStable
to sort commits: https://pkg.go.dev/sort#SliceStableCurrent implementation uses
sort.Slice
, but it's an unstable sort as described in godoc: https://pkg.go.dev/sort#SliceThis results the order of logs indefinite. Especially the order differs when you change
.options.header.pattern
and the extracted log set changes. I want the order of logs always same. Please refer #209 for an example.How this PR fixes the problem?
sort.SliceStable
is a stable sort and the original order is preserved for same priority elements (for example, logs with the same scope). "the original order" is expected to be the commit order.What should your reviewer look out for in this PR?
This change results the log order changed. That means the order of logs in previous releases changes when a developer runs
git-chglog
with this fix for a new release.Please consider whether this is acceptable. If not, I'll introduce a new cli option or configuration option.
(Anyway, the log order can change when the implementation of
sort.Slice
in golang is changed...)Check lists
Additional Comments (if any)
There are other lines using
sort.Slice
. I believe they don't need to be changed tosort.SliceStable
as their sort key is expected to be unique (e.g. Title).Which issue(s) does this PR fix?
fixes #209