gitbundle

package module
v0.0.0-...-8ffb774 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 5 Imported by: 0

README

git-bundle Go Reference

A self-contained Golang package for parsing (and serializing) the Git Bundle Format v2 and v3, ex:

package main

import (
	"bufio"
	"log"
	"os"

	gitbundle "github.com/bored-engineer/git-bundle"
)

func main() {
	f, err := os.Open("<path to bundle file>")
	if err != nil {
		log.Fatalf("os.Open failed: %v", err)
	}
	defer f.Close()
	br := bufio.NewReader(f)

	bundle, err := gitbundle.Parse(br)
	if err != nil {
		log.Fatalf("gitbundle.Parse failed: %v", err)
	}
	for refname, objID := range bundle.References.Map() {
		log.Printf("%s: %s", refname, objID)
	}
}

When Parse returns, the *bufio.Reader position will be at the start of the git packfile section and can be directly read/passed to another package such as github.com/go-git/go-git/v5/plumbing/format/packfile package.

Similarly, when (*Bundle).WriteTo is used only the bundle header will be written to the provided io.Writer, appending the actual packfile contents is left as an exercise for the user.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	Version       string
	Capabilities  Capabilities
	Prerequisites Prerequisites
	References    References
}

Bundle represents a parsed git bundle

func Parse

func Parse(r *bufio.Reader) (*Bundle, error)

Parse parses a bundle from the given bufio.Reader

func (*Bundle) Append

func (b *Bundle) Append(buf []byte) []byte

Append appends the bundle to the given buffer

func (*Bundle) Bytes

func (b *Bundle) Bytes() []byte

Bytes returns the bundle as a byte slice

func (*Bundle) String

func (b *Bundle) String() string

String implements the fmt.Stringer interface

func (*Bundle) WriteTo

func (b *Bundle) WriteTo(w io.Writer) (int64, error)

WriteTo writes the bundle to the given io.Writer

type Capabilities

type Capabilities []Capability

"Capabilities", which are only in the v3 format, indicate functionality that the bundle requires to be read properly.

func (Capabilities) Append

func (cc Capabilities) Append(b []byte) []byte

Append appends the capabilities to the given buffer

func (Capabilities) Bytes

func (cc Capabilities) Bytes() []byte

Bytes returns the capabilities as a byte slice

func (Capabilities) Get

func (cc Capabilities) Get(key string) (value []byte, ok bool)

Get returns the value of the given key in the capabilities

func (Capabilities) Has

func (cc Capabilities) Has(key string) bool

Has returns true if the given key is present in the capabilities

func (Capabilities) String

func (cc Capabilities) String() string

String implements the fmt.Stringer interface

type Capability

type Capability struct {
	Key   string
	Value []byte
}

capability = "@" key ["=" value] LF key = 1*(ALPHA / DIGIT / "-") value = *(%01-09 / %0b-FF)

func ParseCapability

func ParseCapability(line []byte) (Capability, error)

ParseCapability parses a capability from a line of a bundle file

func (Capability) Append

func (c Capability) Append(b []byte) []byte

Append appends the capability line to the given buffer

func (Capability) Bytes

func (c Capability) Bytes() (line []byte)

Bytes returns the capability line as a byte slice

func (Capability) String

func (c Capability) String() string

String implements the fmt.Stringer interface

type ObjectID

type ObjectID string

obj-id = 40*(HEXDIGIT) HEXDIG = DIGIT / "a" / "b" / "c" / "d" / "e" / "f"

func (ObjectID) String

func (oid ObjectID) String() string

String implements the fmt.Stringer interface

func (ObjectID) Valid

func (oid ObjectID) Valid() bool

Valid returns true if the object ID is valid

type Prerequisite

type Prerequisite struct {
	ObjectID ObjectID
	Comment  string
}

prerequisite = "-" obj-id SP comment LF

func ParsePrerequisite

func ParsePrerequisite(line []byte) (Prerequisite, error)

ParsePrerequisite parses a prerequisite from a line of a bundle file

func (Prerequisite) Append

func (p Prerequisite) Append(b []byte) []byte

Append appends the prerequisite line to the given buffer

func (Prerequisite) Bytes

func (p Prerequisite) Bytes() []byte

Bytes returns the prerequisite line as a byte slice

func (Prerequisite) String

func (p Prerequisite) String() string

String implements the fmt.Stringer interface

type Prerequisites

type Prerequisites []Prerequisite

"Prerequisites" lists the objects that are NOT included in the bundle and the reader of the bundle MUST already have, in order to use the data in the bundle.

func (Prerequisites) Append

func (pp Prerequisites) Append(b []byte) []byte

Append appends the prerequisites to the given buffer

func (Prerequisites) Bytes

func (pp Prerequisites) Bytes() []byte

Bytes returns the prerequisites as a byte slice

func (Prerequisites) Map

func (pp Prerequisites) Map() map[ObjectID]string

Map converts the slice into a map by object id

func (Prerequisites) String

func (pp Prerequisites) String() string

String implements the fmt.Stringer interface

type Reference

type Reference struct {
	ObjectID ObjectID
	Name     string
}

reference = obj-id SP refname LF

func ParseReference

func ParseReference(line []byte) (Reference, error)

ParseReference parses a reference from a line of a bundle file

func (Reference) Append

func (r Reference) Append(b []byte) []byte

Append appends the reference line to the given buffer

func (Reference) Bytes

func (r Reference) Bytes() []byte

Bytes returns the reference line as a byte slice

func (Reference) String

func (r Reference) String() string

String implements the fmt.Stringer interface

type References

type References []Reference

References is a list of references

func (References) Append

func (rr References) Append(b []byte) []byte

Append appends the references to the given buffer

func (References) Bytes

func (rr References) Bytes() []byte

Bytes returns the references as a byte slice

func (References) Map

func (rr References) Map() map[string]ObjectID

Map converts the slice into a map by reference name

func (References) String

func (rr References) String() string

String implements the fmt.Stringer interface

Jump to

Keyboard shortcuts

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