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

add pre-commit hook & convenience script to add it. fix some vet errors. #2

Merged
merged 2 commits into from
Feb 14, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Exit on error.
set -e
Copy link
Contributor

Choose a reason for hiding this comment

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

nit set -x as well for diagnostic output


echo "Running go vet..."
Copy link
Contributor

Choose a reason for hiding this comment

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

no need with -x

go vet ./...

echo "Running tests..."
Copy link
Contributor

Choose a reason for hiding this comment

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

same

go test ./...

echo "Running gofmt..."
Copy link
Contributor

Choose a reason for hiding this comment

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

same

find . -name "*.go" | xargs gofmt -w
Copy link
Contributor

Choose a reason for hiding this comment

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

is there no go fmt equivalent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed there is. gofmt .

that was easy.

2 changes: 1 addition & 1 deletion gossip/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewFilter(N uint32, B uint32, maxFP float64) (*Filter, error) {
return nil, fmt.Errorf("number of bits (%d) must be a divisor of 8", B)
}
if maxFP <= 0 || maxFP >= 1 {
return nil, fmt.Errorf("max false positives must be 0 <= maxFP < 1:", maxFP)
return nil, fmt.Errorf("max false positives must be 0 <= maxFP < 1: %f", maxFP)
}
M, K := computeOptimalValues(N, maxFP)
maxCount := uint32((1 << B) - 1)
Expand Down
10 changes: 5 additions & 5 deletions gossip/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ func TestSlots(t *testing.T) {
// Increment a slot and verify.
f.incrementSlot(0, 1)
if f.getSlot(0) != 1 {
t.Error("slot value %d != 1", f.getSlot(0))
t.Errorf("slot value %d != 1", f.getSlot(0))
}
// Increment past max count.
f.incrementSlot(0, int32(f.MaxCount))
if f.getSlot(0) != f.MaxCount {
t.Error("slot value should be max %d != %d", f.getSlot(0), f.MaxCount)
t.Errorf("slot value should be max %d != %d", f.getSlot(0), f.MaxCount)
}
// Decrement once.
f.incrementSlot(0, -1)
if f.getSlot(0) != f.MaxCount-1 {
t.Error("slot value should be max %d != %d", f.getSlot(0), f.MaxCount-1)
t.Errorf("slot value should be max %d != %d", f.getSlot(0), f.MaxCount-1)
}
// Decrement past 0.
f.incrementSlot(0, -int32(f.MaxCount))
if f.getSlot(0) != 0 {
t.Error("slot value should be max %d != 0", f.getSlot(0))
t.Errorf("slot value should be max %d != 0", f.getSlot(0))
}
}

Expand Down Expand Up @@ -181,7 +181,7 @@ func TestFalsePositives(t *testing.T) {
empFP := float64(countFP) / float64(1000)
diff := math.Abs(probFP - empFP)
if diff/probFP > 0.50 {
t.Errorf("measured P(FP) > 50% different from expected %f vs. %f", diff, empFP)
t.Errorf("measured P(FP) > 50%% different from expected %f vs. %f", diff, empFP)
Copy link
Contributor

Choose a reason for hiding this comment

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

double percent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in order to print an actual % within a Printf/Errorf, it must be escaped – http://play.golang.org/p/5ml2NQOWtn

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right duh. didn't see you were trying to print a %-age value

}
}

Expand Down
8 changes: 8 additions & 0 deletions initrepo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Create symlinks to all git hooks in your own .git dir.
echo "### Creating symlinks to our git hooks..."
for f in $(ls -d githooks/*)
do ln -s ../../$f .git/hooks
done && ls -al .git/hooks | grep githooks
echo ""