diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-12-25 20:02:10 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-12-25 20:02:10 -0500 |
commit | de796fbcedd4edb3ea97b39d4fd05cbdcc168baa (patch) | |
tree | e007af30944f144973438c1ae89d8b74b7b7a1ed /textproto | |
parent | 2bcfdda7c623f16b71e92d5a6458c669e6ca8ce3 (diff) | |
parent | 92cdee8f4cda65c0495dd39df51f2d199da17253 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'textproto')
-rw-r--r-- | textproto/catblob.go | 29 | ||||
-rw-r--r-- | textproto/doc.go | 24 | ||||
-rw-r--r-- | textproto/fastimport.go | 25 |
3 files changed, 78 insertions, 0 deletions
diff --git a/textproto/catblob.go b/textproto/catblob.go index 678b842..6836689 100644 --- a/textproto/catblob.go +++ b/textproto/catblob.go @@ -1,3 +1,18 @@ +// Copyright (C) 2017-2018 Luke Shumaker <lukeshu@lukeshu.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + package textproto import ( @@ -7,16 +22,22 @@ import ( "strconv" ) +// CatBlobReader is a low-level parser of an fast-import auxiliary +// "cat-blob" stream. type CatBlobReader struct { r *bufio.Reader } +// NewCatBlobReader creates a new CatBlobReader parser. func NewCatBlobReader(r io.Reader) *CatBlobReader { return &CatBlobReader{ r: bufio.NewReader(r), } } +// ReadLine reads a response from the stream; with special handling +// for responses to "cat-blob" commands, which contain multiple +// newline characters. func (cbr *CatBlobReader) ReadLine() (line string, err error) { for len(line) <= 1 { line, err = cbr.r.ReadString('\n') @@ -52,21 +73,29 @@ func (cbr *CatBlobReader) ReadLine() (line string, err error) { return } +// CatBlobWriter is a low-level marshaller for an auxiliary cat-blob +// stream. type CatBlobWriter struct { w io.Writer } +// NewCatBlobWriter creates a new CatBlobWriter marshaller. func NewCatBlobWriter(w io.Writer) *CatBlobWriter { return &CatBlobWriter{ w: w, } } +// WriteLine writes a response (to a command OTHER THAN "cat-blob") to +// the stream; arguments are handled similarly to fmt.Println. +// +// Use WriteBlob instead to write responses to "cat-blob" commands. func (cbw *CatBlobWriter) WriteLine(a ...interface{}) error { _, err := fmt.Fprintln(cbw.w, a...) return err } +// WriteBlob writes a response to a "cat-blob" command to the stream. func (cbw *CatBlobWriter) WriteBlob(sha1 string, data string) error { err := cbw.WriteLine(sha1, "blob", len(data)) if err != nil { diff --git a/textproto/doc.go b/textproto/doc.go new file mode 100644 index 0000000..82154a1 --- /dev/null +++ b/textproto/doc.go @@ -0,0 +1,24 @@ +// Copyright (C) 2017-2018 Luke Shumaker <lukeshu@lukeshu.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +// Package textproto implements low-level details of the fast-import +// format. +// +// This package deals with parsing and marshalling idiosyncratic +// datatypes used by the format (Ident tuples, 18-bit Mode numbers, +// oddly-quoted Path strings), and abstracting over special-case +// commands that break the "line-based" nature of the format (the +// "data" command, responses to the "cat-blob" command). +package textproto diff --git a/textproto/fastimport.go b/textproto/fastimport.go index c845f7f..b43c378 100644 --- a/textproto/fastimport.go +++ b/textproto/fastimport.go @@ -1,3 +1,18 @@ +// Copyright (C) 2017-2018 Luke Shumaker <lukeshu@lukeshu.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + package textproto import ( @@ -8,6 +23,7 @@ import ( "strings" ) +// FIReader is a low-level parser of a fast-import stream. type FIReader struct { r *bufio.Reader @@ -15,12 +31,16 @@ type FIReader struct { err error } +// NewFIReader creates a new FIReader parser. func NewFIReader(r io.Reader) *FIReader { return &FIReader{ r: bufio.NewReader(r), } } +// ReadLine reads a "line" from the stream; with special handling for +// the "data" command, which isn't really a single line, but rather +// contains arbitrary binary data. func (fir *FIReader) ReadLine() (line string, err error) { for len(line) <= 1 { line, err = fir.r.ReadString('\n') @@ -58,21 +78,26 @@ func (fir *FIReader) ReadLine() (line string, err error) { return } +// FIWriter is a low-level marshaller of a fast-import stream. type FIWriter struct { w io.Writer } +// NewFIWriter creates a new FIWriter marshaller. func NewFIWriter(w io.Writer) *FIWriter { return &FIWriter{ w: w, } } +// WriteLine writes an ordinary line to the stream; arguments are +// handled similarly to fmt.Println. func (fiw *FIWriter) WriteLine(a ...interface{}) error { _, err := fmt.Fprintln(fiw.w, a...) return err } +// WriteData writes a 'data' command to the stream. func (fiw *FIWriter) WriteData(data string) error { err := fiw.WriteLine("data", len(data)) if err != nil { |