svn

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 8 Imported by: 1

README

svn

Go reference

This package provides client and server implementations of the SVN protocol in Go.

This is a work in progress, and it is in a very early stage: some operations already work, but not completely.

Documentation

Overview

Package svn provides client and server implementations of the SVN protocol.

Index

Constants

View Source
const SvnClient = "GoSVN/0.0.0"

SvnClient is the SVN client string to send to servers.

View Source
const SvnVersion = 2

SvnVersion is the SVN protocol version implemented in this package.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(item Item, v any) error

Unmarshal parses an Item and copies it to the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an error.

Unmarshal uses the inverse of the encodings that Marshal uses, allocating slices and pointers as necessary, with the following additional rules:

To unmarshal an Item into a pointer, Unmarshal unmarshals the Item into the value pointed at by the pointer. If the pointer is nil, Unmarshal allocates a new value for it to point to.

To unmarshal a list Item into a struct, Unmarshal matches the values in the same order as they are declared in the struct. If there are extra fields in the struct, they are ignored.

To unmarshal an Item into an interface value, Unmarshal stores one of these in the interface value:

  • int, for numbers
  • string, for words or strings
  • []any, for lists

To unmarshal a list into a slice, Unmarshal resets the slice length to zero and then appends each element to the slice. As a special case, to unmarshal an empty list into a slice, Unmarshal replaces the slice with a new empty slice.

Types

type Client

type Client struct {
	Info ReposInfo
	// contains filtered or unexported fields
}

A Client is a SVN client. Its zero value is not usable: you will have to create it and connect it to a server using Connect.

func Connect

func Connect(address string) (*Client, error)

Connect creates a Client and establishes a connection to a SVN server, using the given address to find out know how to connect to it.

Right now, it works only with "file" and "svn+ssh" URLs, invoking "svnserve -t" (locally or remotely) to connect to a server

func (*Client) GetFile

func (c *Client) GetFile(path string, rev *int, wantProps bool, wantContent bool) ([]PropList, []byte, error)

GetFile sends a "get-file" command, asking for the contents of a file.

func (*Client) GetLatestRev

func (c *Client) GetLatestRev() (int, error)

GetLatestRev sends a "get-latest-rev" command, asking for the latest revision number in the repository.

func (*Client) List

func (c *Client) List(path string, rev *int, depth string, fields []string) ([]Dirent, error)

List sends a "list" command, asking for list of files.

func (*Client) Stat

func (c *Client) Stat(path string, rev *int) (Stat, error)

Stat sends a "stat" command, asking for the status of a path in a revision. "rev" can be nil or a pointer to an integer.

type Dirent

type Dirent struct {
	Path        string
	Kind        string
	Size        uint64
	HasProps    bool
	CreatedRev  uint
	CreatedDate string
	LastAuthor  string
}

Dirent is the response for the "list" command (asking for list of files).

type Error

type Error struct {
	AprErr  int
	Message string `svn:",xxx"`
	File    string `svn:",xxx"`
	Line    int
}

Error is the reprensentation of a "failure" command response. It also implements the error interface.

func (Error) Error

func (e Error) Error() string

type Item

type Item struct {
	// Type specifies the type of item, and which of the next fields is used
	// to represent it.
	Type   ItemType
	Number uint
	Text   string
	List   []Item
}

Item represents a syntactic element in the SVN protocol.

func Marshal

func Marshal(v any) (Item, error)

Marshal converts v into an Item.

Marshal traverses the value v recursively.

Floating point and integer values encode as numbers.

String values encode as words.

Bool values encode as words "true" or "false".

Array, slice and struct values encode as lists, except that []byte values encode as strings.

func ParseResponse

func ParseResponse(i Item) (Item, error)

ParseResponse expects an item following the prototype of "command response" and returns the list of params if the type is "success". It returns error otherwise.

func (Item) String

func (i Item) String() string

String returns a string representation of the Item.

type ItemType

type ItemType int

An ItemType is the type of an Item.

const (
	InvalidType ItemType = iota
	WordType
	NumberType
	StringType
	ListType
)

type Itemizer

type Itemizer struct {
	// contains filtered or unexported fields
}

An Itemizer returns a stream of SVN Items.

func NewItemizer

func NewItemizer(r io.Reader) *Itemizer

NewItemizer returns a new SVN Itemizer for the given Reader.

func (*Itemizer) Item

func (i *Itemizer) Item() (Item, error)

Item returns the next Item from the Itemizer

type LogEntry added in v0.1.0

type LogEntry struct {
	Changed []struct {
		Path string
		Mode string
	}
	Rev     uint
	Author  string
	Date    string
	Message string
}

LogEntry is every one of the responses for the "log" command.

type PropList

type PropList struct {
	Name  string
	Value string
}

PropList is one of the responses for the "get-file" command (asking for the contents of a file).

type ReposInfo

type ReposInfo struct {
	UUID         string
	URL          string
	Capabilities []string
}

ReposInfo contains the general information in a repo. It is filled after the initial connection.

type Server

type Server struct {
	ReposInfo    ReposInfo
	Greet        func(version int, capabilities []string, url string, raclient string, client *string) (ReposInfo, error)
	GetLatestRev func() (int, error)
	Stat         func(path string, rev *uint) (Dirent, error)
	CheckPath    func(path string, rev *uint) (string, error)
	List         func(path string, rev *uint, depth string, fields []string, pattern []string) ([]Dirent, error)
	GetFile      func(path string, rev *uint, wantProps bool, wantContents bool) (uint, []PropList, []byte, error)
	Log          func(paths []string, startRev uint, endRev uint, changedPaths bool) ([]LogEntry, error)
	Update       func(rev *uint, target string, recurse bool)
	SetPath      func(path string, rev uint, startEmpty bool)
	FinishReport func() ([]Item, error)
}

A Server defines parameters for running a SVN server.

func (*Server) Serve

func (s *Server) Serve(r io.Reader, w io.Writer) error

Serve sends and receives SVN messages against a client, issuing calls to the respective functions when a message is received.

Serve returns if there is an error, or after the end of the connection.

type Stat

type Stat struct {
	Kind        string
	Size        uint64
	HasProps    bool
	CreatedRev  uint
	CreatedDate string
	LastAuthor  string
}

Stat is the response for a "stat" command (asking for the status of a path in a revision).

type Token

type Token struct {
	Type   TokenType
	Number uint
	Text   string
}

A Token describes a token in a SVN conversation. There are only 5 types of tokens: word, number, string, left and right parenthesis.

func (Token) String

func (t Token) String() string

String returns a string representation of the Token.

type TokenType

type TokenType int

A TokenType is the type of a Token.

const (
	// ErrorToken means that an error occurred during tokenization.
	ErrorToken TokenType = iota
	WordToken
	NumberToken
	StringToken
	LeftParenToken
	RightParenToken
)

type Tokenizer

type Tokenizer struct {
	// contains filtered or unexported fields
}

A Tokenizer returns a stream of SVN Tokens.

func NewTokenizer

func NewTokenizer(r io.Reader) *Tokenizer

NewTokenizer returns a new SVN Tokenizer for the given Reader.

func (*Tokenizer) Err

func (t *Tokenizer) Err() error

Err returns the first error that was encountered by the Tokenizer.

func (*Tokenizer) Scan

func (t *Tokenizer) Scan() bool

Scan advances the Tokenizer to the next token, which will then be available through the Token method. It returns false when the scan stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning.

func (*Tokenizer) Token

func (t *Tokenizer) Token() Token

Token returns the most recent token generated by a call to Scan.

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL