-
Notifications
You must be signed in to change notification settings - Fork 534
Use advrefs in gituploadpackinfo #92
Use advrefs in gituploadpackinfo #92
Conversation
- 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.
type AdvRefs struct { | ||
Prefix [][]byte // payloads of the prefix | ||
Head *core.Hash | ||
Caps *packp.Capabilities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer long names over abbreviates, so Capabilities
looks better
return &AdvRefs{ | ||
Prefix: [][]byte{}, | ||
Caps: packp.NewCapabilities(), | ||
Refs: map[string]core.Hash{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer map initialization with a make
// Reads a ref-name | ||
func readRef(data []byte) (string, core.Hash, error) { | ||
chunks := bytes.Split(data, sp) | ||
if len(chunks) == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a switch?
// Keeps reading shallows until a flush-pkt is found | ||
func decodeShallow(p *Decoder) decoderStateFn { | ||
if !bytes.HasPrefix(p.line, shallow) { | ||
p.error("malformed shallow prefix") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add the line
to see what is going on?
return err | ||
} | ||
|
||
if bytes.Equal(p, Flush) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can go in a encodeLine
- 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
* 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
This patch modifies how GitUploadPackInfo values are created.
GitUploadPackInfo values are returned by a query to a git server to collect useful data about the server and the requested repository, such as the references and symbolic references of the repository.
The code to create a GitUploadPackInfo is as follows:
info := common.NewGitUploadPackInfo()
to create an empty GitUploadPackInfoinfo.Decode(r)
on a reader r from the server, to fill info with the contents of an advertised-refs message from the server.Here is an example of a typical advertised-ref message (after decoding it from the underlying pktline format):
You can read its full ABNF description in the doc.go file, included in this patch, also here.
Before this patch the
Decode
method do all the work of parsing the message from the server and extracting the references and symbolic references from it.After this patch, there is a new
packp
(pack protocol) package, with a pktline subpackage and an advrefs subpackage.The advrefs subpackage has encoding and decoding types for reading and writing advertised-refs messages.
The new GiyUploadPackInfo.Decode(), just uses an advrefs.Decoder to decode the server message into a struct, then builds the list of references from the struct.
Here are some of the changes you will find in this patch:
formats/packp/advrefs
formats/packp/pktline
, as it makes the package much more usable.clients/common
toformats/packp
to avoid a circular import and because it makes more sense.The old GitUploadPackInfo.Bytes() is now outdated (it never make to much sense anyway, as it was HTTP smart specific even though it was on the
clients/common
package). Now If you really want to send a advertised-refs message, you will build an AdvRefs and encode it to some stream. This is all explained with examples in the advrefs package. I have not remove the Bytes message though, as it was public and I didn't fully understand its purpose, so it is still there.