diff options
author | Alberto Cortés <alcortesm@gmail.com> | 2016-10-26 17:56:26 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-10-26 15:56:26 +0000 |
commit | 73fa9ef25a8af9c8337a4cf34a67cfe208f1a7c5 (patch) | |
tree | 66886d9b47e373b748c1bceafe1885e6f47868dd /formats/packp/advrefs/advrefs.go | |
parent | f3ab3a6c73015b5ae9b2a4756dc646e1211cedb9 (diff) | |
download | go-git-73fa9ef25a8af9c8337a4cf34a67cfe208f1a7c5.tar.gz |
Use advrefs in gituploadpackinfo (#92)
* add advrefs encoder and parser
* modify advrefs encoder to resemble json encoder
* turn advrefs parser into a decoder
* clean code
* improve documentation
* improve documentation
* clean code
* upgrade to new pktline.Add and add Flush const to easy integration
* gometalinter
* Use packp/advrefs for GitUploadPackInfo parsing
- GitUploadPackInfo now uses packp/advrefs instead of parsing the
message by itself.
- Capabilities has been moved from clients/common to packp to avoid a
circular import.
- Cleaning of advrefs_test code.
- Add support for prefix encoding and decoding in advrefs.
* clean advrefs test code
* clean advrefs test code
* clean advrefs test code
* gometalinter
* add pktline encoder
* change pktline.EncodeFlush to pktline.Flush
* make scanner tests use the encoder instead of Pktlines
* check errors on flush and clean constants
* ubstitute the PktLines type with a pktline.Encoder
* use pktline.Encoder in all go-git
* add example of pktline.Encodef()
* add package overview
* documentation
* support symbolic links other than HEAD
* simplify decoding of shallows
* packp: fix mcuadros comments
- all abbreviates removed (by visual inspection, some may remain)
- all empty maps are initialized using make
- simplify readRef with a switch
- make decodeShallow malformed error more verbose
- add pktline.Encoder.encodeLine
- remove infamous panic in checkPayloadLength by refactoring out
the whole function
Diffstat (limited to 'formats/packp/advrefs/advrefs.go')
-rw-r--r-- | formats/packp/advrefs/advrefs.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/formats/packp/advrefs/advrefs.go b/formats/packp/advrefs/advrefs.go new file mode 100644 index 0000000..ab4bcf5 --- /dev/null +++ b/formats/packp/advrefs/advrefs.go @@ -0,0 +1,58 @@ +// Package advrefs implements encoding and decoding advertised-refs +// messages from a git-upload-pack command. +package advrefs + +import ( + "gopkg.in/src-d/go-git.v4/core" + "gopkg.in/src-d/go-git.v4/formats/packp" +) + +const ( + hashSize = 40 + head = "HEAD" + noHead = "capabilities^{}" +) + +var ( + sp = []byte(" ") + null = []byte("\x00") + eol = []byte("\n") + peeled = []byte("^{}") + shallow = []byte("shallow ") + noHeadMark = []byte(" capabilities^{}\x00") +) + +// AdvRefs values represent the information transmitted on an +// advertised-refs message. Values from this type are not zero-value +// safe, use the New function instead. +// +// When using this messages over (smart) HTTP, you have to add a pktline +// before the whole thing with the following payload: +// +// '# service=$servicename" LF +// +// Moreover, some (all) git HTTP smart servers will send a flush-pkt +// just after the first pkt-line. +// +// To accomodate both situations, the Prefix field allow you to store +// any data you want to send before the actual pktlines. It will also +// be filled up with whatever is found on the line. +type AdvRefs struct { + Prefix [][]byte // payloads of the prefix + Head *core.Hash + Capabilities *packp.Capabilities + References map[string]core.Hash + Peeled map[string]core.Hash + Shallows []core.Hash +} + +// New returns a pointer to a new AdvRefs value, ready to be used. +func New() *AdvRefs { + return &AdvRefs{ + Prefix: [][]byte{}, + Capabilities: packp.NewCapabilities(), + References: make(map[string]core.Hash), + Peeled: make(map[string]core.Hash), + Shallows: []core.Hash{}, + } +} |