all repos

mugit @ 43dfa274f440e76ab536b78d9263c0820c0be970

🐮 git server that your cow will love

mugit/internal/git/gitx/protocol.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
git: refactor gitserver again; and rename, 3 months ago
1
package gitx
2
3
import (
4
	"fmt"
5
	"io"
6
)
7
8
// PackLine writes a pkt-line formatted string.
9
func PackLine(w io.Writer, s string) error {
10
	_, err := fmt.Fprintf(w, "%04x%s", len(s)+4, s)
11
	return err
12
}
13
14
// PackFlush writes a flush packet.
15
func PackFlush(w io.Writer) error {
16
	_, err := fmt.Fprint(w, "0000")
17
	return err
18
}
19
20
// PackError writes an ERR packet for protocol-level errors.
21
// Git displays this as: fatal: remote error: <msg>
22
func PackError(w io.Writer, msg string) error {
23
	return PackLine(w, "ERR "+msg)
24
}