summaryrefslogtreecommitdiff
path: root/parse_catblob.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-11-30 20:41:00 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-11-30 20:41:00 -0500
commite3b3c08e62f07c75426536c3407dfebc4b71405a (patch)
tree9add249423816b9bc93f40694d921330243d6725 /parse_catblob.go
parentdeb826c9c18f26652e565a013e2d00929c0b8a35 (diff)
use github.com/pkg/errors
Diffstat (limited to 'parse_catblob.go')
-rw-r--r--parse_catblob.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/parse_catblob.go b/parse_catblob.go
index 6d5bd87..c6f66c8 100644
--- a/parse_catblob.go
+++ b/parse_catblob.go
@@ -1,21 +1,22 @@
package libfastimport
import (
- "fmt"
"strconv"
"strings"
+
+ "github.com/pkg/errors"
)
func cbpGetMark(line string) (string, error) {
if len(line) != 41 {
- return "", fmt.Errorf("get-mark: short <sha1>\\n: %q", line)
+ return "", errors.Errorf("get-mark: short <sha1>\\n: %q", line)
}
if line[40] != '\n' {
- return "", fmt.Errorf("get-mark: malformed <sha1>\\n: %q", line)
+ return "", errors.Errorf("get-mark: malformed <sha1>\\n: %q", line)
}
for _, b := range line[:40] {
if !(('0' <= b && b <= '9') || ('a' <= b && b <= 'f')) {
- return "", fmt.Errorf("get-mark: malformed <sha1>: %q", line[:40])
+ return "", errors.Errorf("get-mark: malformed <sha1>: %q", line[:40])
}
}
return line[:40], nil
@@ -28,38 +29,38 @@ func cbpCatBlob(full string) (sha1 string, data string, err error) {
// <data> LF
if full[len(full)-1] != '\n' {
- return "", "", fmt.Errorf("cat-blob: missing trailing newline")
+ return "", "", errors.Errorf("cat-blob: missing trailing newline")
}
lf := strings.IndexByte(full, '\n')
if lf < 0 || lf == len(full)-1 {
- return "", "", fmt.Errorf("cat-blob: malformed header: %q", full)
+ return "", "", errors.Errorf("cat-blob: malformed header: %q", full)
}
head := full[:lf]
data = full[lf+1 : len(full)-1]
if len(head) < 40+6+1 {
- return "", "", fmt.Errorf("cat-blob: malformed header: %q", head)
+ return "", "", errors.Errorf("cat-blob: malformed header: %q", head)
}
sha1 = head[:40]
for _, b := range sha1 {
if !(('0' <= b && b <= '9') || ('a' <= b && b <= 'f')) {
- return "", "", fmt.Errorf("cat-blob: malformed <sha1>: %q", sha1)
+ return "", "", errors.Errorf("cat-blob: malformed <sha1>: %q", sha1)
}
}
if string(head[40:46]) != " blob " {
- return "", "", fmt.Errorf("cat-blob: malformed header: %q", head)
+ return "", "", errors.Errorf("cat-blob: malformed header: %q", head)
}
size, err := strconv.Atoi(head[46:])
if err != nil {
- return "", "", fmt.Errorf("cat-blob: malformed blob size: %v", err)
+ return "", "", errors.Wrap(err, "cat-blob: malformed blob size")
}
if size != len(data) {
- return "", "", fmt.Errorf("cat-blob: size header (%d) didn't match delivered size (%d)", size, len(data))
+ return "", "", errors.Errorf("cat-blob: size header (%d) didn't match delivered size (%d)", size, len(data))
}
return sha1, data, err
@@ -70,7 +71,7 @@ func cbpLs(line string) (mode Mode, dataref string, path Path, err error) {
// or
// 'missing' SP <path> LF
if line[len(line)-1] != '\n' {
- return 0, "", "", fmt.Errorf("ls: missing trailing newline")
+ return 0, "", "", errors.New("ls: missing trailing newline")
}
line = line[:len(line)-1]
@@ -80,11 +81,11 @@ func cbpLs(line string) (mode Mode, dataref string, path Path, err error) {
} else {
fields := strings.SplitN(line, " ", 3)
if len(fields) < 3 {
- return 0, "", "", fmt.Errorf("ls: malformed line: %q", line)
+ return 0, "", "", errors.Errorf("ls: malformed line: %q", line)
}
ht := strings.IndexByte(fields[2], '\t')
if ht < 0 {
- return 0, "", "", fmt.Errorf("ls: malformed line: %q", line)
+ return 0, "", "", errors.Errorf("ls: malformed line: %q", line)
}
strMode := fields[0]
//strType := fields[1]