Skip to content

Commit

Permalink
Merge pull request #43 from alta/ydnar/deterministic
Browse files Browse the repository at this point in the history
Scan packages in deterministic order
  • Loading branch information
ydnar authored Mar 12, 2021
2 parents e70592d + 6db82a6 commit 7392ff8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.3.1]
## [Unreleased]

### Fixed
- Scan Go packages in a deterministic order (FIFO) to fix a flaky recurrence of a bug related to the fix for [#40](https://github.com/alta/protopatch/issues/40).

## [v0.3.1] — 2021-03-11

### Fixed
- [#40](https://github.com/alta/protopatch/issues/40): enum values renamed with `go.lint` are now usable when imported into another proto file.

## [v0.3.0]
## [v0.3.0] — 2021-01-04

### Added
- [#37](https://github.com/alta/protopatch/pull/32): new file-level `go.lint` option. When specified, `protoc-gen-go-patch` will attempt to fix generated Go names to their idiomatic equivalents, e.g. `Id``ID`, `Url``URL`, etc. It will also eliminate stutter from enum values, e.g. `Foo_FOO_UNKNOWN``FooUnknown`. Thanks to [@Green7](https://github.com/Green7) for the initial implementation in [#22](https://github.com/alta/protopatch/pull/22).
Expand Down
5 changes: 4 additions & 1 deletion patch/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Patcher struct {
fset *token.FileSet
filesByName map[string]*ast.File
info *types.Info
packages []*Package
packagesByPath map[string]*Package
packagesByName map[string]*Package
renames map[protogen.GoIdent]string
Expand Down Expand Up @@ -543,7 +544,8 @@ func (p *Patcher) checkPackages() error {
pkg.Reset()
}

for _, pkg := range p.packagesByName {
// Iterate packages deterministically
for _, pkg := range p.packages {
if len(pkg.files) == 0 {
continue
}
Expand Down Expand Up @@ -615,6 +617,7 @@ func (p *Patcher) getPackage(path, name string, create bool) *Package {
name = pkg.pkg.Name() // Get real name
p.packagesByPath[path] = pkg
p.packagesByName[name] = pkg
p.packages = append(p.packages, pkg)
return pkg
}

Expand Down

0 comments on commit 7392ff8

Please sign in to comment.