pkg

package
v0.0.0-...-f237d81 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FetchRefSpec = "+refs/heads/*:refs/remotes/%s/*"
	PushRefSpec  = "refs/heads/*:refs/heads/*"
)

default RefSpecs

View Source
const (
	Sep   byte = 0
	Space byte = ' '
)
View Source
const (
	OBJ_COMMIT pkObjectType
	OBJ_TREE
	OBJ_BLOB
	OBJ_TAG

	OBJ_OFS_DELTA
	OBJ_REF_DELTA
)
View Source
const RFC2822 = "Mon Jan 2 15:04:05 2006 -0700"
View Source
const TIME_FORMAT = "Mon Jan 2 15:04:05 2006 -0700"

Time format used in formatting commit time

Variables

View Source
var (
	IOWriteErr    = &OpErr{Context: "Could not write to the specified writer: "}
	PermissionErr = &OpErr{Context: "Permission denied: "}
	FormatErr     = &OpErr{Context: "Bad Formatting: "}
	CopyErr       = &OpErr{Context: "Could not copy data: "}
	NotDefinedErr = &OpErr{Context: "Value not defined"}
	IOCreateErr   = &OpErr{Context: "Could not create file/ directory:"}
	IoReadErr     = &OpErr{Context: "Could not read file:"}
	Incomplete    = &OpErr{Context: "Object Incomplete"}
)
View Source
var (
	GenericNetErr = &PackErr{Context: "Pack File Error"}
)
View Source
var HeadNotINitErr = fmt.Errorf("Head not yet initialized")

Functions

func ArgsIncomplete

func ArgsIncomplete() error

func CheckCRC

func CheckCRC(data []byte) bool

the crc32IEEE polynomial: X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0

func Init

func Init(ctx context.Context, name string) error

#####PORCELAINS##### Porcelains are generally small and neat methods that rely heavily on plumbers to do the dirty work, and sometimes helprs too. Its an unfair world, but it is what it is Check: https://stackoverflow.com/questions/35894613/how-to-disallow-access-to-a-file-for-one-user/35895436#35895436 on file permissions Init creates a directory for your repo and initializes the hidden .git directory

func IsGit

func IsGit() (bool, error)

great, now I can remove every damn wkdir, I think. TsGit checks if this is a working git directory. simply: is there a ".git" directory inside iu

Types

type Blob

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

func (*Blob) Hash

func (blob *Blob) Hash(wkdir string) (Sha1, error)

func (*Blob) String

func (c *Blob) String() string

func (*Blob) Type

func (c *Blob) Type() string

type Comm

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

func (*Comm) Encode

func (c *Comm) Encode(w io.Writer) error

func (*Comm) Hash

func (c *Comm) Hash(wkdir string) (Sha1, error)

func (*Comm) String

func (c *Comm) String() string

func (*Comm) Type

func (c *Comm) Type() string

type Config

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

func InitCinfig

func InitCinfig(path string) (*Config, error)

type Got

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

func NewGot

func NewGot() *Got

NewGot takes care of initializing our git object comeback for refs

func (*Got) Add

func (got *Got) Add(ctx context.Context, all bool, args ...string) error

Add updates the index using the current content found in the working tree, to prepare the content staged for the next commit. provide full paths please comebck: move parsing problems to cmd

func (*Got) Branches

func (got *Got) Branches() (io.Reader, error)

func (*Got) CatFile

func (got *Got) CatFile(ctx context.Context, prefix string, mode int) (io.Reader, error)

CatFile displays the file info using the git logger (set as os.Stdout). It uses flags to determine what it displays

func (*Got) Checkout

func (got *Got) Checkout(ctx context.Context, name string) error

func (*Got) Commit

func (got *Got) Commit(ctx context.Context, msg string, all bool) (string, error)

https://github.com/git/git/blob/master/Documentation/technical/http-protocol.txt https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt Commit first writes the tree from the set of staged objects we have no commit-tree method comeback to fix the method. we need a way to writ the committed changes to stdout comeback `all` determines whether all known files (already in index) is automatically committed

func (*Got) Delete

func (g *Got) Delete(path []string, where int) error

func (*Got) DeleteBranch

func (got *Got) DeleteBranch(ctx context.Context, name string) error

func (*Got) Diff

func (g *Got) Diff(cached bool, output, arg string) error

comeback

func (*Got) FatalErr

func (git *Got) FatalErr(err error)

comback remove os.Exit(). program should only exit at main.main. here, I want to return an error value that directly causes the program to exit at the main function with a non-zero code / |||The Got panic error handler |||| /// FatalErr is a convenience function for errors that will cause the program to exit

func (*Got) Fetch

func (g *Got) Fetch(ctx context.Context, remote string) error

comeback

func (*Got) FindObject

func (got *Got) FindObject(prefix string) (string, error)

FindObject takes a sha1 prefix. It returns the path to the object file. It doesn't care t open it another method does that we want to have findObject such that even though we do not have a full 20 byte string, we can still find the path to the file it is unlikely to find two blobs with the same sha1 prefix, but if such happens, we return an error and expect the user to provide a longer string

func (*Got) GotErr

func (got *Got) GotErr(err error)

func (*Got) HashObject

func (got *Got) HashObject(data []byte, ty string, w bool) ([]byte, error)

func (*Got) Log

func (g *Got) Log(rdr io.Reader) error

func (*Got) LsFiles

func (got *Got) LsFiles(ctx context.Context, stage, cached, deleted, modified, others bool) error

LsFiles prints to stdOut the state of staged files, i.e. the index files After a Commit, it is clean comeback

func (*Got) LsRemote

func (got *Got) LsRemote()

after refs and capabilities discovery, client may send the flush packet to tell the server it has ended

func (*Got) LsTree

func (got *Got) LsTree(ctx context.Context, path string) (io.Reader, error)

comeback

func (*Got) Merge

func (got *Got) Merge(ctx context.Context, comm string) error

func (*Got) NewBranch

func (got *Got) NewBranch(ctx context.Context, name string) error

comeback to implement

func (*Got) Object

func (got *Got) Object(sha string, ty ObjectType) (GotObject, error)

func (*Got) OpenRead

func (g *Got) OpenRead(id string) (io.Reader, error)

/READING and WRITING Objects

func (*Got) OpenWrite

func (g *Got) OpenWrite() error

func (*Got) Pull

func (got *Got) Pull(ctx context.Context, remote string, rebase bool) error

comeback

func (*Got) Push

func (got *Got) Push(ctx context.Context, url string) (string, error)

discover references available in the remote repo first the remote repo has no workspace. It basically contains what is in the .git directory.

func (*Got) ReadObject

func (got *Got) ReadObject(prefix string) (string, string, []byte, error)

ReadObject bulds on findObject. First, it finds the object, but it does more, it attempts to read it and assert that it contains valid git object files apart from that, it tries to understand what kind of git object it is

func (*Got) ReadObjectStream

func (got *Got) ReadObjectStream(prefix string) (string, string, io.Reader, error)

func (*Got) ReadTree

func (got *Got) ReadTree(treeish string) error

comeback

func (*Got) RemoteAdd

func (got *Got) RemoteAdd(ctx context.Context, name string) error

comeback

func (*Got) RemoteRm

func (got *Got) RemoteRm(ctx context.Context, name string) error

comeback

func (*Got) Rm

func (g *Got) Rm(ctx context.Context, cached bool, args []string) error

Rm remove files matching pathspec from the index, or from the working tree and the index It will not remove a file from just your working directory provide full paths please

func (*Got) ShowConf

func (g *Got) ShowConf(path []string, where int) (io.Reader, error)

comeback

func (*Got) Status

func (got *Got) Status(ctx context.Context) io.Reader

func (*Got) UpErr

func (git *Got) UpErr(err error) error

UpErr prints to the logger before returning

func (*Got) UpIndexEntries

func (got *Got) UpIndexEntries(entries []*IdxEntry) error

write the index file, given a slice of index this is the function that stages files IndexEntry file integers in git are written in NE.

func (*Got) UpdateConf

func (g *Got) UpdateConf(path []string, value string, where int) error

comeback

func (*Got) UpdateIndex

func (got *Got) UpdateIndex(ctx context.Context, all, remove bool) error

comeback

func (*Got) VerifyPack

func (got *Got) VerifyPack(ctx context.Context, idx string) error

func (*Got) WkDir

func (got *Got) WkDir() string

func (*Got) WriteTree

func (got *Got) WriteTree(ctx context.Context) (string, error)

to write a tree, we need to stage the files first i.e. index them, then from the indexed files, we write the tree TODO: for now, we support only root-level files WriteTree just takes the current values in the index (i.e. the staged files) and writes as tree object

type GotObject

type GotObject interface {
	Hasher
	Type() string
}

type Hasher

type Hasher interface {
	Hash(wkdir string) (Sha1, error)
}

type Idx

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

we work only with version 2 https://github.com/git/git/blob/master/Documentation/technical/index-format.txt

func (*Idx) Append

func (i *Idx) Append(path string)

func (*Idx) Remove

func (i *Idx) Remove(path string) error

type IdxEntry

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

type InlineCmt

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

stands for comment lines and empty lines

type KV

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

type Line

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

if comment, k is empty. if sect, k is sect, v is subsect if it exists.

type LineType

type LineType = string

type ObjectErr

type ObjectErr struct {
	ErrSTring string
	// contains filtered or unexported fields
}

func (*ObjectErr) Error

func (e *ObjectErr) Error() string

func (*ObjectErr) SetInner

func (e *ObjectErr) SetInner(err error)

func (*ObjectErr) Unwrap

func (e *ObjectErr) Unwrap() error

type ObjectType

type ObjectType int

type OpErr

type OpErr struct {
	Context string
	// contains filtered or unexported fields
}

TODO: In doing this work, I have tried to do my best with error handling / Errors that do not belong directly to the Git struct Preference is to return these errors early after adding a context. the caller then decides what to do. Because this app is not robust, we mostly just panic

func (OpErr) AddContext

func (e OpErr) AddContext(s string) OpErr

func (*OpErr) Error

func (e *OpErr) Error() string

func (*OpErr) Unwrap

func (e *OpErr) Unwrap() error

func (OpErr) Wrap

func (e OpErr) Wrap(err error) OpErr

type Pack

type Pack struct {
	Sha     string
	Objects map[string]*pkObject
}

TODO: TRY USING SOMETHING LIKE THE ENCODER INTERFACE TO DESCRIBE THE FUNCTIONALITY OF THE PACK. CHECK HEX ENCODER

type PackErr

type PackErr struct {
	Context string
	Inner   error
}

func (*PackErr) Error

func (p *PackErr) Error() string

func (*PackErr) Unwrap

func (p *PackErr) Unwrap() error

type Ref

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

func InitRef

func InitRef(fullpath string, _type RefType) *Ref

initialize a ref this initializer does nothing except storing the values it expects a full path because it does not have access to the working directory

func RefFromSym

func RefFromSym(path string, _type RefType) (*Ref, error)

func (*Ref) ReadCont

func (r *Ref) ReadCont() ([]byte, error)

contents of refs are commits

func (*Ref) UpdateCont

func (r *Ref) UpdateCont(path string)

comeback

type RefType

type RefType int

type Section

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

type Sha1

type Sha1 = [20]byte

func HashObj

func HashObj(ty string, data []byte, base string) (Sha1, error)

general hashfunction

type Sign

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

func (*Sign) Format

func (s *Sign) Format() string

type Tag

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

func (*Tag) Hash

func (t *Tag) Hash(wkdir string) ([]byte, error)

func (*Tag) Type

func (t *Tag) Type() string

type Tree

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

tree [content size]\0[Entries having references to other trees and blobs] [mode] [file/folder name]\0[SHA-1 of referencing blob or tree]

func (*Tree) Encode

func (t *Tree) Encode(wtr io.WriteCloser) error

comeback check error in caller. if error exists, reverse write

func (*Tree) Find

func (t *Tree) Find(path string) (*item, error)

func (*Tree) Hash

func (t *Tree) Hash(wkdir string) (Sha1, error)

func (*Tree) Type

func (c *Tree) Type() string

type User

type User struct {
	Uname string
	Email string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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