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

Fix a few lint issues #78

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 10 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
-
name: Install libgit2-dev
run: sudo apt-get install -y libgit2-dev
name: Install deps
run: sudo apt-get install -y pkg-config cmake
-
name: Checkout
uses: actions/checkout@v3
Expand All @@ -29,10 +29,14 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
-
name: Set the right libgit2 version
name: Building
run: |
sed -i -e 's/v34/v31/g' go.mod splitter/*.go
go mod tidy
go mod vendor
rm -rf vendor/github.com/libgit2/git2go
git clone https://github.com/libgit2/git2go vendor/github.com/libgit2/git2go/v34
cd vendor/github.com/libgit2/git2go/v34 && git checkout v34.0.0 && git submodule update --init && make install-static
-
name: Test
run: go test -v ./...
run: |
export PKG_CONFIG_PATH=/home/runner/work/lite/lite/vendor/github.com/libgit2/git2go/v34/static-build/build
go test -v ./...
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p *prefixesFlag) Set(value string) error {
for _, prefix := range []*splitter.Prefix(*p) {
// FIXME: to should be normalized (xxx vs xxx/ for instance)
if prefix.To == to {
return fmt.Errorf("Cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to)
return fmt.Errorf("cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to)
}
}

Expand Down
2 changes: 1 addition & 1 deletion splitter/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newCache(branch string, config *Config) (*cache, error) {
return err1
})
if err != nil {
return nil, fmt.Errorf("Impossible to create bucket: %s", err)
return nil, fmt.Errorf("impossible to create bucket: %s", err)
}

return c, nil
Expand Down
18 changes: 13 additions & 5 deletions splitter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@ func Split(config *Config, result *Result) error {

// Validate validates the configuration
func (config *Config) Validate() error {
if !git.ReferenceIsValidName(config.Origin) {
return fmt.Errorf("The origin is not a valid Git reference")
ok, err := git.ReferenceNameIsValid(config.Origin)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("the origin is not a valid Git reference")
}

if config.Target != "" && !git.ReferenceIsValidName(config.Target) {
return fmt.Errorf("The target is not a valid Git reference")
ok, err = git.ReferenceNameIsValid(config.Target)
if err != nil {
return err
}
if config.Target != "" && !ok {
return fmt.Errorf("the target is not a valid Git reference")
}

git, ok := supportedGitVersions[config.GitVersion]
if !ok {
return fmt.Errorf(`The git version can only be one of "<1.8.2", "<2.8.0", or "latest"`)
return fmt.Errorf(`the git version can only be one of "<1.8.2", "<2.8.0", or "latest"`)
}
config.Git = git

Expand Down
6 changes: 3 additions & 3 deletions splitter/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func roundDuration(d, r time.Duration) time.Duration {
}
neg := d < 0
if neg {
d = -d
d -= d
}
if m := d % r; m+m < r {
d = d - m
d -= m
} else {
d = d + r - m
d += r - m
}
if neg {
return -d
Expand Down
18 changes: 9 additions & 9 deletions splitter/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *state) split() error {

revWalk, err := s.walker()
if err != nil {
return fmt.Errorf("Impossible to walk the repository: %s", err)
return fmt.Errorf("impossible to walk the repository: %s", err)
}
defer revWalk.Free()

Expand Down Expand Up @@ -163,12 +163,12 @@ func (s *state) split() error {
func (s *state) walker() (*git.RevWalk, error) {
revWalk, err := s.repo.Walk()
if err != nil {
return nil, fmt.Errorf("Impossible to walk the repository: %s", err)
return nil, fmt.Errorf("impossible to walk the repository: %s", err)
}

err = s.pushRevs(revWalk)
if err != nil {
return nil, fmt.Errorf("Impossible to determine split range: %s", err)
return nil, fmt.Errorf("impossible to determine split range: %s", err)
}

revWalk.Sorting(git.SortTopological | git.SortReverse)
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *state) mergeTrees(t1, t2 *git.Tree) (*git.Tree, error) {
defer index.Free()

if index.HasConflicts() {
return nil, fmt.Errorf("Cannot split as there is a merge conflict between two paths")
return nil, fmt.Errorf("cannot split as there is a merge conflict between two paths")
}

oid, err := index.WriteTreeTo(s.repo)
Expand Down Expand Up @@ -373,7 +373,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
continue
}

if 0 == ptree.Cmp(tree.Id()) {
if ptree.Cmp(tree.Id()) == 0 {
// an identical parent could be used in place of this rev.
identical = parent
} else {
Expand All @@ -384,7 +384,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
// eliminate duplicates
isNew := true
for _, gp := range gotParents {
if 0 == gp.Cmp(parent) {
if gp.Cmp(parent) == 0 {
isNew = false
break
}
Expand All @@ -405,15 +405,15 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
if s.config.Git > 2 && nil != identical && nil != nonIdentical {
revWalk, err := s.repo.Walk()
if err != nil {
return nil, false, fmt.Errorf("Impossible to walk the repository: %s", err)
return nil, false, fmt.Errorf("impossible to walk the repository: %s", err)
}

s.repoMu.Lock()
defer s.repoMu.Unlock()

err = revWalk.PushRange(fmt.Sprintf("%s..%s", identical, nonIdentical))
if err != nil {
return nil, false, fmt.Errorf("Impossible to determine split range: %s", err)
return nil, false, fmt.Errorf("impossible to determine split range: %s", err)
}

err = revWalk.Iterate(func(rev *git.Commit) bool {
Expand Down Expand Up @@ -494,7 +494,7 @@ func (s *state) updateTarget() error {
}

if nil == s.result.Head() {
return fmt.Errorf("Unable to create branch %s as it is empty (no commits were split)", s.config.Target)
return fmt.Errorf("unable to create branch %s as it is empty (no commits were split)", s.config.Target)
}

obj, ref, err := s.repo.RevparseExt(s.config.Target)
Expand Down
2 changes: 1 addition & 1 deletion splitter/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func normalizeOriginBranch(repo *git.Repository, origin string) (string, error)

obj, ref, err := repo.RevparseExt(origin)
if err != nil {
return "", fmt.Errorf("Bad revision for origin: %s", err)
return "", fmt.Errorf("bad revision for origin: %s", err)
}
if obj != nil {
obj.Free()
Expand Down
Loading