sbr

package
v0.0.0-...-d195741 Latest Latest
Warning

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

Go to latest
Published: May 27, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	SbrFile = ".sbr"
)

Variables

View Source
var (
	ErrNoSbrfile = errors.New("Not in an 'sbr' workspace")
)

Functions

func Diff

func Diff(src, dest []Sub) (insertion, deletion []Sub, update []Delta)

Diff compute the changes to be applied to 'src', in order to became dest.

func Equals

func Equals(src, dest []Sub) bool

func Patch

func Patch(d *Sub, delta Delta) (changed bool, err error)

Apply changes described in 'x' to d

func Sort

func Sort(sbrs []Sub)

Sort a slice of Sub according to the natural order.

func UpdateAll

func UpdateAll(subs []Sub, upd ...Delta) (changed bool, err error)

func WriteTo

func WriteTo(w io.Writer, sbr []Sub)

Types

type Checkouter

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

Checkouter holds all methods to change the workspace content

func NewCheckouter

func NewCheckouter(workspace *Workspace, w io.Writer) *Checkouter

NewCheckouter creates a checkouter. logs are reported into w

func (*Checkouter) Checkout

func (ch *Checkouter) Checkout() (digest []byte, err error)

Checkout the current workspace

it's a Pull Top and clone/prune/pull each subrepositories

func (*Checkouter) Prune

func (ch *Checkouter) Prune(d Sub) (err error)

Prune a Sub

func (*Checkouter) PullAll

func (ch *Checkouter) PullAll() (err error)

func (*Checkouter) PullTop

func (ch *Checkouter) PullTop() (err error)

PullTop launches a git pull --ff-only on the Wd top git

func (*Checkouter) SetFastForwardOnly

func (c *Checkouter) SetFastForwardOnly(ffo bool)

func (*Checkouter) SetPrune

func (c *Checkouter) SetPrune(prune bool)

func (*Checkouter) SetRebase

func (c *Checkouter) SetRebase(rebase bool)

func (*Checkouter) UpdateBranch

func (ch *Checkouter) UpdateBranch(delta Delta) (updated bool, err error)

Update branch on actual git repo if needed

func (*Checkouter) UpdateRemote

func (ch *Checkouter) UpdateRemote(delta Delta) (updated bool, err error)

Update remote updates the remote origin

func (*Checkouter) UpdateRepository

func (ch *Checkouter) UpdateRepository(delta Delta) (updated bool, err error)

Update a repository according to changes described in delta

type Delta

type Delta struct {
	Old Sub
	New Sub
}

func (*Delta) Empty

func (d *Delta) Empty() bool

Empty return true if both old and new are equals

func (Delta) Rel

func (d Delta) Rel() string

func (Delta) String

func (s Delta) String() string

type Sub

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

Sub type contains all the information about a sub.

func New

func New(rel, remote, branch string) Sub

func ReadFrom

func ReadFrom(r io.Reader) (sbr []Sub, err error)

ReadFrom read subrepository definitions fom reader

the initial currentBranch is 'master'

Example

ExampleWorkspace_ReadFrom test several version of a .sbr that all should be readable and generate the same "normalized" version.

//this is a normalize sample of .sbr
normalized := `"src/github.com/ericaro/mrepo" "git@github.com:ericaro/mrepo.git"
"mdev"
"src/github.com/ericaro/mrepo_dev" "git@github.com:ericaro/mrepo.git"
"src/github.com/ericaro/mrepo_dev2" "git@github.com:ericaro/mrepo2.git"
"mprod"
"src/github.com/ericaro/mrepo_prod" "git@github.com:ericaro/mrepo.git"
"src/github.com/ericaro/mrepoa" "git@github.com:ericaro/mrepoa.git"
`
//this is a human-edited version, that should be identical
humanized := `
"src/github.com/ericaro/mrepo" "git@github.com:ericaro/mrepo.git"
"toto"
"src/github.com/ericaro/mrepo_prod" "git@github.com:ericaro/mrepo.git" "mprod"
"src/github.com/ericaro/mrepo_dev" "git@github.com:ericaro/mrepo.git" "mdev"
"src/github.com/ericaro/mrepo_dev2" "git@github.com:ericaro/mrepo2.git" "mdev"
"mprod"
"src/github.com/ericaro/mrepoa" "git@github.com:ericaro/mrepoa.git"
`
//and this is a human edited legacy version (order is messy)
legacy := `
"src/github.com/ericaro/mrepo" "git@github.com:ericaro/mrepo.git" "master"
"src/github.com/ericaro/mrepo_prod" "git@github.com:ericaro/mrepo.git" "mprod"
"src/github.com/ericaro/mrepo_dev" "git@github.com:ericaro/mrepo.git" "mdev"
"src/github.com/ericaro/mrepo_dev2" "git@github.com:ericaro/mrepo2.git" "mdev"
"src/github.com/ericaro/mrepoa" "git@github.com:ericaro/mrepoa.git" "mprod"
`
// all shall give the same normalize form
normalizer := func(sbr string) string {
	sbrs, _ := ReadFrom(strings.NewReader(sbr))
	buf := new(bytes.Buffer)
	WriteTo(buf, sbrs)
	return buf.String()
}

if n := normalizer(normalized); n != normalized {
	fmt.Printf("normalization should be invariant:\n%q\n%q\n", n, normalized)
}
if n := normalizer(humanized); n != normalized {
	fmt.Printf("humanized should lead to same result:\n%q\n%q\n", n, normalized)
}
if n := normalizer(legacy); n != normalized {
	fmt.Printf("humanized should lead to same result:\n%q\n%q\n", n, normalized)
}
fmt.Printf("Ok\n")
Output:

Ok

func ReadFromBranch

func ReadFromBranch(currentBranch string, r io.Reader) (sbr []Sub, err error)

ReadFromBranch read subrepository definitions from reader

func RemoveAll

func RemoveAll(sources []Sub, del ...Sub) (res []Sub, changed bool)

RemoveAll subrepositories from 'd'

func (Sub) Branch

func (d Sub) Branch() string

Branch returns this project's branch.

func (Sub) Less

func (d Sub) Less(x Sub) bool

Less represent the natural order for Sub branch first then rel.

func (Sub) Rel

func (d Sub) Rel() string

Rel returns this project's relative path.

func (Sub) Remote

func (d Sub) Remote() string

Remote returns this project's remote.

func (Sub) String

func (d Sub) String() string

type Workspace

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

func FindWorkspace

func FindWorkspace(root string, oserr error) (w *Workspace, err error)

FindWorkspace get the current working dir and search for a .sbr file upwards

FindWorkspace(os.Getwd() )

func NewWorkspace

func NewWorkspace(wd string) *Workspace

NewWorkspace creates a new Workspace for a working dir.

func (*Workspace) Read

func (x *Workspace) Read() (sbrs []Sub, err error)

Read returns the []Sub, as declared in the .sbr file

func (*Workspace) Sbrfile

func (x *Workspace) Sbrfile() string

Sbrfile return the workspace sbr file name.

func (*Workspace) Scan

func (x *Workspace) Scan() (sbrs []Sub, err error)

Scan the working dir and return subrepositories found

func (*Workspace) ScanRel

func (x *Workspace) ScanRel() []string

ScanRel extract only the path of the subrepositories (faster than the whole dependency)

func (*Workspace) Version

func (wk *Workspace) Version() (version []byte, err error)

Version compute the workspace version (the sha1 of all sha1)

func (*Workspace) Wd

func (x *Workspace) Wd() string

Wd return the current working directory for this workspace.

Jump to

Keyboard shortcuts

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