本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.3KB

  1. package packp
  2. import (
  3. "fmt"
  4. )
  5. type stateFn func() stateFn
  6. const (
  7. // common
  8. hashSize = 40
  9. // advrefs
  10. head = "HEAD"
  11. noHead = "capabilities^{}"
  12. )
  13. var (
  14. // common
  15. sp = []byte(" ")
  16. eol = []byte("\n")
  17. eq = []byte{'='}
  18. // advertised-refs
  19. null = []byte("\x00")
  20. peeled = []byte("^{}")
  21. noHeadMark = []byte(" capabilities^{}\x00")
  22. // upload-request
  23. want = []byte("want ")
  24. shallow = []byte("shallow ")
  25. deepen = []byte("deepen")
  26. deepenCommits = []byte("deepen ")
  27. deepenSince = []byte("deepen-since ")
  28. deepenReference = []byte("deepen-not ")
  29. // shallow-update
  30. unshallow = []byte("unshallow ")
  31. // server-response
  32. ack = []byte("ACK")
  33. nak = []byte("NAK")
  34. // updreq
  35. shallowNoSp = []byte("shallow")
  36. )
  37. func isFlush(payload []byte) bool {
  38. return len(payload) == 0
  39. }
  40. // ErrUnexpectedData represents an unexpected data decoding a message
  41. type ErrUnexpectedData struct {
  42. Msg string
  43. Data []byte
  44. }
  45. // NewErrUnexpectedData returns a new ErrUnexpectedData containing the data and
  46. // the message given
  47. func NewErrUnexpectedData(msg string, data []byte) error {
  48. return &ErrUnexpectedData{Msg: msg, Data: data}
  49. }
  50. func (err *ErrUnexpectedData) Error() string {
  51. if len(err.Data) == 0 {
  52. return err.Msg
  53. }
  54. return fmt.Sprintf("%s (%s)", err.Msg, err.Data)
  55. }
上海开阖软件有限公司 沪ICP备12045867号-1