Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Use advrefs in gituploadpackinfo #92

Merged
merged 28 commits into from
Oct 26, 2016
Merged

Use advrefs in gituploadpackinfo #92

merged 28 commits into from
Oct 26, 2016

Conversation

alcortesm
Copy link
Contributor

@alcortesm alcortesm commented Oct 24, 2016

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:

  • call info := common.NewGitUploadPackInfo() to create an empty GitUploadPackInfo
  • call info.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):

00887217a7c7e582c46cec22a130adf4b9d7d950fba0 HEAD\x00multi_ack thin-pack
        side-band side-band-64k ofs-delta shallow no-progress include-tag
00441d3fcd5ced445d1abc402225c0b8a1299641f497 refs/heads/integration
003f7217a7c7e582c46cec22a130adf4b9d7d950fba0 refs/heads/master
003cb88d2441cac0977faf98efc80305012112238d9d refs/tags/v0.9
003c525128480b96c89e6418b1e40909bf6c5b2d580f refs/tags/v1.0
003fe92df48743b7bc7d26bcaabfddde0a1e20cae47c refs/tags/v1.0^{}
0000

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:

  • the new AdvRefs type, its decoder and encoder: package formats/packp/advrefs
  • a new pktlines encoder that substitute the old pktlines struct: package formats/packp/pktline, as it makes the package much more usable.
  • Capabilities has been moved from clients/common to formats/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.

@alcortesm alcortesm mentioned this pull request Oct 25, 2016
type AdvRefs struct {
Prefix [][]byte // payloads of the prefix
Head *core.Hash
Caps *packp.Capabilities
Copy link
Contributor

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{},
Copy link
Contributor

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 {
Copy link
Contributor

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")
Copy link
Contributor

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) {
Copy link
Contributor

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
@mcuadros mcuadros merged commit f861f30 into src-d:master Oct 26, 2016
@alcortesm alcortesm deleted the use-advrefs-in-gituploadpackinfo branch October 27, 2016 13:09
mcuadros pushed a commit that referenced this pull request Jan 31, 2017
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants