From 7675ebe9567bd7cae4306f484e3677bf88ba8b55 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Nov 2017 16:25:35 -0500 Subject: rename files --- ezfiw.go | 28 ++++++++++++++++++++++ git-fast-import.go | 69 ------------------------------------------------------ read.go | 59 ---------------------------------------------- read_catblob.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ read_fastimport.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++ util.go | 28 ---------------------- 6 files changed, 156 insertions(+), 156 deletions(-) create mode 100644 ezfiw.go delete mode 100644 git-fast-import.go delete mode 100644 read.go create mode 100644 read_catblob.go create mode 100644 read_fastimport.go delete mode 100644 util.go diff --git a/ezfiw.go b/ezfiw.go new file mode 100644 index 0000000..0143f48 --- /dev/null +++ b/ezfiw.go @@ -0,0 +1,28 @@ +package libfastimport + +import ( + "strconv" +) + +type ezfiw struct { + fiw *FIWriter + err error +} + +func (e *ezfiw) WriteLine(a ...interface{}) { + if e.err == nil { + e.err = e.fiw.WriteLine(a...) + } +} + +func (e *ezfiw) WriteData(data []byte) { + if e.err == nil { + e.err = e.fiw.WriteData(data) + } +} + +func (e *ezfiw) WriteMark(idnum int) { + if e.err == nil { + e.err = e.fiw.WriteLine("mark", ":"+strconv.Itoa(idnum)) + } +} diff --git a/git-fast-import.go b/git-fast-import.go deleted file mode 100644 index ed5cb14..0000000 --- a/git-fast-import.go +++ /dev/null @@ -1,69 +0,0 @@ -package libfastimport - -import ( - "fmt" - "bytes" - "strconv" -) - -func CatBlobParseGetMark(dat []byte) (string, error) { - if len(dat) != 41 { - return "", fmt.Errorf("get-mark: short \\n: %q", string(dat)) - } - if dat[40] != '\n' { - return "", fmt.Errorf("get-mark: malformed \\n: %q", string(dat)) - } - for _, b := range dat[:40] { - if !(('0' <= b && b <= '9') || ('a' <= b && b <= 'f')) { - return "", fmt.Errorf("get-mark: malformed : %q", string(dat[:40])) - } - } - return string(dat[:40]), nil -} - -func CatBlobParseCatBlob(full []byte) (sha1 string, data []byte, err error) { - // The format is: - // - // SP 'blob' SP LF - // LF - - lf := bytes.IndexByte(full, '\n') - if lf < 0 || lf == len(full)-1 { - return "", nil, fmt.Errorf("cat-blob: malformed header: %q", string(full)) - } - head := full[:lf] - data = full[lf+1:len(full)-1] - - if len(head) < 40+6+1 { - return "", nil, fmt.Errorf("cat-blob: malformed header: %q", string(head)) - } - - sha1 = string(head[:40]) - for _, b := range sha1 { - if !(('0' <= b && b <= '9') || ('a' <= b && b <= 'f')) { - return "", nil, fmt.Errorf("cat-blob: malformed : %q", sha1) - } - } - - if string(head[40:46]) != " blob " { - return "", nil, fmt.Errorf("cat-blob: malformed header: %q", head) - } - - size, err := strconv.Atoi(string(head[46:])) - if err != nil { - return "", nil, fmt.Errorf("cat-blob: malformed blob size: %v", err) - } - - if size != len(data) { - return "", nil, fmt.Errorf("cat-blob: size header (%d) didn't match delivered size (%d)", size, len(data)) - } - - return sha1, data, err -} - -func CatBlobParseLs(dataref string, path string) error { - // SP ('blob' | 'tree' | 'commit') SP HT LF - // or - // 'missing' SP LF - return nil // TODO -} diff --git a/read.go b/read.go deleted file mode 100644 index ea10885..0000000 --- a/read.go +++ /dev/null @@ -1,59 +0,0 @@ -package libfastimport - -type UnsupportedCommand string - -func (e UnsupportedCommand) Error() string { - return "Unsupported command: "+string(e) -} - -type Parser struct { - fir *FIReader - - cmd chan Cmd -} - -func (p *Parser) GetCmd() (Cmd, error) { - for p.cmd == nil { - slice, err := p.fir.ReadSlice() - if err != nil { - return nil, err - } - err = p.putSlice(slice) - if err != nil { - return nil, err - } - } - return <-p.cmd, nil -} - -func (p *Parser) putSlice(slice []byte) error { - if len(slice) < 1 { - return UnsupportedCommand(slice) - } - switch slice[0] { - case '#': // comment - case 'b': // blob - case 'c': - if len(slice) < 2 { - return UnsupportedCommand(slice) - } - switch slice[1] { - case 'o': // commit - case 'h': // checkpoint - case 'a': // cat-blob - default: - return UnsupportedCommand(slice) - } - case 'd': // done - case 'f': // feature - case 'g': // get-mark - case 'l': // ls - case 'o': // option - case 'p': // progress - case 'r': // reset - case 't': // tag - default: - return UnsupportedCommand(slice) - } - return nil // TODO -} diff --git a/read_catblob.go b/read_catblob.go new file mode 100644 index 0000000..ed5cb14 --- /dev/null +++ b/read_catblob.go @@ -0,0 +1,69 @@ +package libfastimport + +import ( + "fmt" + "bytes" + "strconv" +) + +func CatBlobParseGetMark(dat []byte) (string, error) { + if len(dat) != 41 { + return "", fmt.Errorf("get-mark: short \\n: %q", string(dat)) + } + if dat[40] != '\n' { + return "", fmt.Errorf("get-mark: malformed \\n: %q", string(dat)) + } + for _, b := range dat[:40] { + if !(('0' <= b && b <= '9') || ('a' <= b && b <= 'f')) { + return "", fmt.Errorf("get-mark: malformed : %q", string(dat[:40])) + } + } + return string(dat[:40]), nil +} + +func CatBlobParseCatBlob(full []byte) (sha1 string, data []byte, err error) { + // The format is: + // + // SP 'blob' SP LF + // LF + + lf := bytes.IndexByte(full, '\n') + if lf < 0 || lf == len(full)-1 { + return "", nil, fmt.Errorf("cat-blob: malformed header: %q", string(full)) + } + head := full[:lf] + data = full[lf+1:len(full)-1] + + if len(head) < 40+6+1 { + return "", nil, fmt.Errorf("cat-blob: malformed header: %q", string(head)) + } + + sha1 = string(head[:40]) + for _, b := range sha1 { + if !(('0' <= b && b <= '9') || ('a' <= b && b <= 'f')) { + return "", nil, fmt.Errorf("cat-blob: malformed : %q", sha1) + } + } + + if string(head[40:46]) != " blob " { + return "", nil, fmt.Errorf("cat-blob: malformed header: %q", head) + } + + size, err := strconv.Atoi(string(head[46:])) + if err != nil { + return "", nil, fmt.Errorf("cat-blob: malformed blob size: %v", err) + } + + if size != len(data) { + return "", nil, fmt.Errorf("cat-blob: size header (%d) didn't match delivered size (%d)", size, len(data)) + } + + return sha1, data, err +} + +func CatBlobParseLs(dataref string, path string) error { + // SP ('blob' | 'tree' | 'commit') SP HT LF + // or + // 'missing' SP LF + return nil // TODO +} diff --git a/read_fastimport.go b/read_fastimport.go new file mode 100644 index 0000000..ea10885 --- /dev/null +++ b/read_fastimport.go @@ -0,0 +1,59 @@ +package libfastimport + +type UnsupportedCommand string + +func (e UnsupportedCommand) Error() string { + return "Unsupported command: "+string(e) +} + +type Parser struct { + fir *FIReader + + cmd chan Cmd +} + +func (p *Parser) GetCmd() (Cmd, error) { + for p.cmd == nil { + slice, err := p.fir.ReadSlice() + if err != nil { + return nil, err + } + err = p.putSlice(slice) + if err != nil { + return nil, err + } + } + return <-p.cmd, nil +} + +func (p *Parser) putSlice(slice []byte) error { + if len(slice) < 1 { + return UnsupportedCommand(slice) + } + switch slice[0] { + case '#': // comment + case 'b': // blob + case 'c': + if len(slice) < 2 { + return UnsupportedCommand(slice) + } + switch slice[1] { + case 'o': // commit + case 'h': // checkpoint + case 'a': // cat-blob + default: + return UnsupportedCommand(slice) + } + case 'd': // done + case 'f': // feature + case 'g': // get-mark + case 'l': // ls + case 'o': // option + case 'p': // progress + case 'r': // reset + case 't': // tag + default: + return UnsupportedCommand(slice) + } + return nil // TODO +} diff --git a/util.go b/util.go deleted file mode 100644 index 0143f48..0000000 --- a/util.go +++ /dev/null @@ -1,28 +0,0 @@ -package libfastimport - -import ( - "strconv" -) - -type ezfiw struct { - fiw *FIWriter - err error -} - -func (e *ezfiw) WriteLine(a ...interface{}) { - if e.err == nil { - e.err = e.fiw.WriteLine(a...) - } -} - -func (e *ezfiw) WriteData(data []byte) { - if e.err == nil { - e.err = e.fiw.WriteData(data) - } -} - -func (e *ezfiw) WriteMark(idnum int) { - if e.err == nil { - e.err = e.fiw.WriteLine("mark", ":"+strconv.Itoa(idnum)) - } -} -- cgit v1.2.3