Documentation ¶
Overview ¶
Package blame contains blaming functionality for files in the repo.
Blaming a file is finding what commit was the last to modify each of the lines in the file, therefore the output of a blaming operation is usualy a slice of commits, one commit per line in the file.
This package also provides a pretty print function to output the results of a blame in a similar format to the git-blame command.
Package revlist allows to create the revision history of a file, this is, the list of commits in the past that affect the file.
The general idea is to traverse the git commit graph backward, flattening the graph into a linear history, and skipping commits that are irrelevant for the particular file.
There is no single answer for this operation. The git command "git-revlist" returns different histories depending on its arguments and some internal heuristics.
The current implementation tries to get something similar to what you whould get using git-revlist. See the failing tests for some insight about how the current implementation and git-revlist differs.
Another way to get the revision history for a file is: git log --follow -p -- file
Index ¶
- Constants
- Variables
- func SortCommits(l []*Commit)
- type Blame
- type Blob
- type Commit
- func (c *Commit) Blame(path string) (*Blame, error)
- func (c *Commit) Decode(o core.Object) error
- func (c *Commit) File(path string) (file *File, err error)
- func (c *Commit) NumParents() int
- func (c *Commit) Parents() *CommitIter
- func (c *Commit) References(path string) ([]*Commit, error)
- func (c *Commit) String() string
- func (c *Commit) Tree() *Tree
- type CommitIter
- type File
- type Hash
- type Remote
- func (r *Remote) Capabilities() *common.Capabilities
- func (r *Remote) Connect() error
- func (r *Remote) DefaultBranch() string
- func (r *Remote) Fetch(req *common.GitUploadPackRequest) (io.ReadCloser, error)
- func (r *Remote) FetchDefaultBranch() (io.ReadCloser, error)
- func (r *Remote) Info() *common.GitUploadPackInfo
- func (r *Remote) Ref(refName string) (core.Hash, error)
- func (r *Remote) Refs() map[string]core.Hash
- type Repository
- type Signature
- type Tree
- type TreeEntry
- type TreeIter
Constants ¶
const (
DefaultRemoteName = "origin"
)
Variables ¶
New errors defined by this package.
Functions ¶
Types ¶
type Blob ¶
Blob is used to store file data - it is generally a file.
func (*Blob) Decode ¶
Decode transform an core.Object into a Blob struct
type Commit ¶
type Commit struct { Hash core.Hash Author Signature Committer Signature Message string // contains filtered or unexported fields }
Commit points to a single tree, marking it as what the project looked like at a certain point in time. It contains meta-information about that point in time, such as a timestamp, the author of the changes since the last commit, a pointer to the previous commit(s), etc. http://schacon.github.io/gitbook/1_the_git_object_model.html
func (*Commit) Blame ¶
Blame returns the last commit that modified each line of a file in a repository.
The file to blame is identified by the input arguments: repo, commit and path. The output is a slice of commits, one for each line in the file.
Blaming a file is a two step process:
- Create a linear history of the commits affecting a file. We use revlist.New for that.
Then build a graph with a node for every line in every file in the history of the file.
Each node (line) holds the commit where it was introduced or last modified. To achieve that we use the FORWARD algorithm described in Zimmermann, et al. "Mining Version Archives for Co-changed Lines", in proceedings of the Mining Software Repositories workshop, Shanghai, May 22-23, 2006.
Each node is asigned a commit: Start by the nodes in the first commit. Assign that commit as the creator of all its lines.
Then jump to the nodes in the next commit, and calculate the diff between the two files. Newly created lines get assigned the new commit as its origin. Modified lines also get this new commit. Untouched lines retain the old commit.
All this work is done in the assignOrigin function which holds all the internal relevant data in a "blame" struct, that is not exported.
TODO: ways to improve the efficiency of this function:
Improve revlist
Improve how to traverse the history (example a backward traversal will be much more efficient)
TODO: ways to improve the function in general:
Add memoization between revlist and assign.
It is using much more memory than needed, see the TODOs below.
func (*Commit) Decode ¶
Decode transform an core.Object into a Blob struct
func (*Commit) File ¶
File returns the file with the specified "path" in the commit and a nil error if the file exists. If the file does not exists, it returns a nil file and the ErrFileNotFound error.
func (*Commit) NumParents ¶
NumParents returns the number of parents in a commit.
func (*Commit) Parents ¶
func (c *Commit) Parents() *CommitIter
func (*Commit) References ¶
References returns a References for the file at "path", the commits are sorted in commit order. It stops searching a branch for a file upon reaching the commit were the file was created.
Caveats:
- Moves and copies are not currently supported.
- Cherry-picks are not detected unless there are no commits between them and therefore can appear repeated in the list. (see git path-id for hints on how to fix this).
type CommitIter ¶
type CommitIter struct {
// contains filtered or unexported fields
}
func NewCommitIter ¶
func NewCommitIter(r *Repository) *CommitIter
func (*CommitIter) Close ¶
func (i *CommitIter) Close()
func (*CommitIter) Next ¶
func (i *CommitIter) Next() (*Commit, error)
type File ¶
File represents git file objects.
func (*File) Contents ¶
Contents returns the contents of a file as a string.
type Remote ¶
type Remote struct { Endpoint common.Endpoint Auth common.AuthMethod // contains filtered or unexported fields }
func NewAuthenticatedRemote ¶
func NewAuthenticatedRemote(url string, auth common.AuthMethod) (*Remote, error)
NewAuthenticatedRemote returns a new Remote using the given AuthMethod, using as client http.DefaultClient
func NewRemote ¶
NewRemote returns a new Remote, using as client http.DefaultClient
func (*Remote) Capabilities ¶
func (r *Remote) Capabilities() *common.Capabilities
Capabilities returns the remote capabilities
func (*Remote) DefaultBranch ¶
DefaultBranch returns the name of the remote's default branch
func (*Remote) Fetch ¶
func (r *Remote) Fetch(req *common.GitUploadPackRequest) (io.ReadCloser, error)
Fetch returns a reader using the request
func (*Remote) FetchDefaultBranch ¶
func (r *Remote) FetchDefaultBranch() (io.ReadCloser, error)
FetchDefaultBranch returns a reader for the default branch
func (*Remote) Info ¶
func (r *Remote) Info() *common.GitUploadPackInfo
Info returns the git-upload-pack info
func (*Remote) Ref ¶
Ref returns the Hash pointing the given refName
type Repository ¶
type Repository struct { Remotes map[string]*Remote Storage *core.RAWObjectStorage URL string }
func NewPlainRepository ¶
func NewPlainRepository() *Repository
NewPlainRepository creates a new repository without remotes
func NewRepository ¶
func NewRepository(url string, auth common.AuthMethod) (*Repository, error)
NewRepository creates a new repository setting remote as default remote
func (*Repository) Commit ¶
func (r *Repository) Commit(h core.Hash) (*Commit, error)
Commit return the commit with the given hash
func (*Repository) Commits ¶
func (r *Repository) Commits() *CommitIter
Commits decode the objects into commits
func (*Repository) Pull ¶
func (r *Repository) Pull(remoteName, branch string) error
type Signature ¶
Signature represents an action signed by a person
func (*Signature) Decode ¶
Decode decodes a byte slice into a signature
type Tree ¶
Tree is basically like a directory - it references a bunch of other trees and/or blobs (i.e. files and sub-directories)
func (*Tree) Decode ¶
Decode transform an core.Object into a Tree struct
type TreeEntry ¶
TreeEntry represents a file
type TreeIter ¶
type TreeIter struct {
// contains filtered or unexported fields
}
func NewTreeIter ¶
func NewTreeIter(r *Repository) *TreeIter
func (*TreeIter) Close ¶
func (i *TreeIter) Close()
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Go-git needs the packfile and the refs of the repo.
|
Go-git needs the packfile and the refs of the repo. |
ssh
Package ssh implements a ssh client for go-git.
|
Package ssh implements a ssh client for go-git. |
Package diff implements line oriented diffs, similar to the ancient Unix diff command.
|
Package diff implements line oriented diffs, similar to the ancient Unix diff command. |
formats
|
|