-
Notifications
You must be signed in to change notification settings - Fork 535
remote: sideband support #156
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package sideband | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"io" | ||
|
@@ -15,22 +14,23 @@ var ErrMaxPackedExceeded = errors.New("max. packed size exceeded") | |
// Progress allows to read the progress information | ||
type Progress interface { | ||
io.Reader | ||
io.Writer | ||
} | ||
|
||
// Demuxer demultiplex the progress reports and error info interleaved with the | ||
// packfile itself. | ||
// | ||
// A sideband has three diferent channels the main one call PackData contains | ||
// A sideband has three different channels the main one, call PackData, contains | ||
// the packfile data, the ErrorMessage channel, that contains server errors and | ||
// the last one ProgressMessage channel containing information about the ongoing | ||
// tast happening in the server (optinal, can be suppressed sending NoProgress | ||
// task happening in the server (optional, can be suppressed sending NoProgress | ||
// or Quiet capabilities to the server) | ||
// | ||
// In order to demultiplex the data stream, method `Read` should be called to | ||
// retrieve the PackData channel, the incoming data from the ProgressMessage is | ||
// stored and can be read from `Progress` field, if any message is retrieved | ||
// from the ErrorMessage channel an error is returned and we can assume that the | ||
// conection has been closed. | ||
// written at `Progress` (if any), if any message is retrieved from the | ||
// ErrorMessage channel an error is returned and we can assume that the | ||
// connection has been closed. | ||
type Demuxer struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is confusing as the Demuxer type does not actually demultiplex the channels and it is not clear how are errors messages sent back to the user. Also a connection is mentioned in the comment, and some assumptions about it being closed, but it is not clear how this can be relevant for anything. I think a better comment would be something like this:
Although I am still not sure about the connection thing. I would rather use a real demuxer though or even simply a method that returns 3 readers (or even better, 3 scanners): one for each channel, treating them as equal, with the same usage semantics. This will have a much simpler API and will let the user decide how to use each channel. Another approach would be to use a single scanner, returning channel and data when read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this is not a PR of the sideband demux this was already merged. Your text doesn't explain that the Progress could be optional. I will review the text with the new phrase |
||
t Type | ||
r io.Reader | ||
|
@@ -39,7 +39,7 @@ type Demuxer struct { | |
max int | ||
pending []byte | ||
|
||
// Progress contains progress information | ||
// Progress is where the progress messages are stored | ||
Progress Progress | ||
} | ||
|
||
|
@@ -51,21 +51,19 @@ func NewDemuxer(t Type, r io.Reader) *Demuxer { | |
} | ||
|
||
return &Demuxer{ | ||
t: t, | ||
r: r, | ||
max: max, | ||
s: pktline.NewScanner(r), | ||
Progress: bytes.NewBuffer(nil), | ||
t: t, | ||
r: r, | ||
max: max, | ||
s: pktline.NewScanner(r), | ||
} | ||
} | ||
|
||
// Read reads up to len(p) bytes from the PackData channel into p, an error can | ||
// be return if an error happends when reading or if a message is sent in the | ||
// be return if an error happens when reading or if a message is sent in the | ||
// ErrorMessage channel. | ||
// | ||
// If a ProgressMessage is read, it won't be copied to b. Instead of this, it is | ||
// stored and can be read through the reader Progress. If the n value returned | ||
// is zero, err will be nil unless an error reading happens. | ||
// When a ProgressMessage is read, is not copy to b, instead of this is written | ||
// to the Progress | ||
func (d *Demuxer) Read(b []byte) (n int, err error) { | ||
var read, req int | ||
|
||
|
@@ -126,13 +124,17 @@ func (d *Demuxer) nextPackData() ([]byte, error) { | |
case PackData: | ||
return content[1:], nil | ||
case ProgressMessage: | ||
_, err := d.Progress.(io.Writer).Write(content[1:]) | ||
return nil, err | ||
if d.Progress != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is a optional argument, and not the most common behavior, so that's why is not part of the New method |
||
_, err := d.Progress.Write(content[1:]) | ||
return nil, err | ||
} | ||
case ErrorMessage: | ||
return nil, fmt.Errorf("unexpected error: %s", content[1:]) | ||
default: | ||
return nil, fmt.Errorf("unknown channel %s", content) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *Demuxer) getPending() (b []byte) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
English grammar and typos, consider this alternate version: