Commit 10dacbf0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Suppress errors from shallow clone detection

They are just noise.
parent 15dcdbd4
...@@ -125,14 +125,8 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) { ...@@ -125,14 +125,8 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
return return
} }
isShallowClone, err = scanDeepen(bytes.NewReader(buffer.Bytes())) isShallowClone = scanDeepen(bytes.NewReader(buffer.Bytes()))
body = io.MultiReader(buffer, r.Body) body = io.MultiReader(buffer, r.Body)
if err != nil {
// Do not pass on the error: our failure to parse the
// request body should not abort the request.
helper.LogError(r, fmt.Errorf("parseBody (non-fatal): %v", err))
}
} else { } else {
body = r.Body body = r.Body
} }
......
...@@ -18,19 +18,16 @@ func pktFlush(w io.Writer) error { ...@@ -18,19 +18,16 @@ func pktFlush(w io.Writer) error {
return err return err
} }
func scanDeepen(body io.Reader) (bool, error) { func scanDeepen(body io.Reader) bool {
hasDeepen := false
scanner := bufio.NewScanner(body) scanner := bufio.NewScanner(body)
scanner.Split(pktLineSplitter) scanner.Split(pktLineSplitter)
for scanner.Scan() { for scanner.Scan() {
if bytes.HasPrefix(scanner.Bytes(), []byte("deepen")) { if bytes.HasPrefix(scanner.Bytes(), []byte("deepen")) && scanner.Err() == nil {
hasDeepen = true return true
break
} }
} }
return hasDeepen, scanner.Err() return false
} }
func pktLineSplitter(data []byte, atEOF bool) (advance int, token []byte, err error) { func pktLineSplitter(data []byte, atEOF bool) (advance int, token []byte, err error) {
......
...@@ -16,10 +16,7 @@ func TestSuccessfulScanDeepen(t *testing.T) { ...@@ -16,10 +16,7 @@ func TestSuccessfulScanDeepen(t *testing.T) {
} }
for _, example := range examples { for _, example := range examples {
hasDeepen, err := scanDeepen(bytes.NewReader([]byte(example.input))) hasDeepen := scanDeepen(bytes.NewReader([]byte(example.input)))
if err != nil {
t.Fatalf("error scanning %q: %v", example.input, err)
}
if hasDeepen != example.output { if hasDeepen != example.output {
t.Fatalf("scanDeepen %q: expected %v, got %v", example.input, example.output, hasDeepen) t.Fatalf("scanDeepen %q: expected %v, got %v", example.input, example.output, hasDeepen)
...@@ -35,14 +32,7 @@ func TestFailedScanDeepen(t *testing.T) { ...@@ -35,14 +32,7 @@ func TestFailedScanDeepen(t *testing.T) {
} }
for _, example := range examples { for _, example := range examples {
hasDeepen, err := scanDeepen(bytes.NewReader([]byte(example))) if scanDeepen(bytes.NewReader([]byte(example))) == true {
if err == nil {
t.Fatalf("expected error scanning %q", example)
}
t.Log(err)
if hasDeepen == true {
t.Fatalf("scanDeepen %q: expected result to be false, got true", example) t.Fatalf("scanDeepen %q: expected result to be false, got true", example)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment