Skip to content
Snippets Groups Projects
Select Git revision
  • 28cf3de0f9e22124de614c7645ed4555ef76c9a1
  • master default protected
  • docs-release-checklist-037
  • release
  • release-v0.37.0
  • staging
  • reprovide-sweep
  • copilot/fix-859994d3-9d4e-4a8e-bea3-58b58c75a399
  • feat/boxo-retrieval-diagnostics
  • dependabot/github_actions/codecov/codecov-action-5.5.0
  • config-api-for-path
  • fix/panic-and-zombie-daemons
  • chore-golangci-v2
  • config-reprovider-test
  • release-v036
  • release-v0.36.0
  • telemetry-plugin
  • fix-editor-env-handling
  • fix-flush-files-rm
  • unixfs-percent-encoding-poc
  • fix/systemd-path
  • v0.37.0
  • v0.37.0-rc1
  • v0.36.0
  • v0.36.0-rc2
  • v0.36.0-rc1
  • v0.35.0
  • v0.35.0-rc2
  • v0.35.0-rc1
  • v0.34.1
  • v0.34.0
  • v0.34.0-rc2
  • v0.34.0-rc1
  • v0.33.2
  • v0.33.1
  • v0.33.0
  • v0.33.0-rc3
  • v0.33.0-rc2
  • v0.33.0-rc1
  • v0.32.1
  • v0.32.0
41 results

builder.go

Blame
  • repo.go 3.05 KiB
    // Package repository contains helper methods for working with a Git repo.
    package repository
    
    import (
    	"bytes"
    	"strings"
    
    	"github.com/MichaelMure/git-bug/util"
    )
    
    // Repo represents a source code repository.
    type Repo interface {
    	// GetPath returns the path to the repo.
    	GetPath() string
    
    	// GetUserName returns the name the the user has used to configure git
    	GetUserName() (string, error)
    
    	// GetUserEmail returns the email address that the user has used to configure git.
    	GetUserEmail() (string, error)
    
    	// GetCoreEditor returns the name of the editor that the user has used to configure git.
    	GetCoreEditor() (string, error)
    
    	// FetchRefs fetch git refs from a remote
    	FetchRefs(remote string, refSpec string) (string, error)
    
    	// PushRefs push git refs to a remote
    	PushRefs(remote string, refSpec string) (string, error)
    
    	// StoreData will store arbitrary data and return the corresponding hash
    	StoreData(data []byte) (util.Hash, error)
    
    	// ReadData will attempt to read arbitrary data from the given hash
    	ReadData(hash util.Hash) ([]byte, error)
    
    	// StoreTree will store a mapping key-->Hash as a Git tree
    	StoreTree(mapping []TreeEntry) (util.Hash, error)
    
    	// StoreCommit will store a Git commit with the given Git tree
    	StoreCommit(treeHash util.Hash) (util.Hash, error)
    
    	// StoreCommit will store a Git commit with the given Git tree
    	StoreCommitWithParent(treeHash util.Hash, parent util.Hash) (util.Hash, error)
    
    	// UpdateRef will create or update a Git reference
    	UpdateRef(ref string, hash util.Hash) error
    
    	// ListRefs will return a list of Git ref matching the given refspec
    	ListRefs(refspec string) ([]string, error)
    
    	// RefExist will check if a reference exist in Git
    	RefExist(ref string) (bool, error)
    
    	// CopyRef will create a new reference with the same value as another one
    	CopyRef(source string, dest string) error
    
    	// ListCommits will return the list of tree hashes of a ref, in chronological order
    	ListCommits(ref string) ([]util.Hash, error)
    
    	// ListEntries will return the list of entries in a Git tree
    	ListEntries(hash util.Hash) ([]TreeEntry, error)
    
    	// FindCommonAncestor will return the last common ancestor of two chain of commit
    	FindCommonAncestor(hash1 util.Hash, hash2 util.Hash) (util.Hash, error)
    
    	// GetTreeHash return the git tree hash referenced in a commit
    	GetTreeHash(commit util.Hash) (util.Hash, error)
    
    	LoadClocks() error
    
    	WriteClocks() error
    
    	CreateTimeIncrement() (util.LamportTime, error)
    
    	EditTimeIncrement() (util.LamportTime, error)
    
    	CreateWitness(time util.LamportTime) error
    
    	EditWitness(time util.LamportTime) error
    }
    
    func prepareTreeEntries(entries []TreeEntry) bytes.Buffer {
    	var buffer bytes.Buffer
    
    	for _, entry := range entries {
    		buffer.WriteString(entry.Format())
    	}
    
    	return buffer
    }
    
    func readTreeEntries(s string) ([]TreeEntry, error) {
    	splitted := strings.Split(s, "\n")
    
    	casted := make([]TreeEntry, len(splitted))
    	for i, line := range splitted {
    		if line == "" {
    			continue
    		}
    
    		entry, err := ParseTreeEntry(line)
    
    		if err != nil {
    			return nil, err
    		}
    
    		casted[i] = entry
    	}
    
    	return casted, nil
    }