本文整理汇总了Golang中github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/go-vcs/vcs.CommitID函数的典型用法代码示例。如果您正苦于以下问题:Golang CommitID函数的具体用法?Golang CommitID怎么用?Golang CommitID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CommitID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeCommit
func (r *Repository) makeCommit(rec *hg_revlog.Rec) (*vcs.Commit, error) {
fb := hg_revlog.NewFileBuilder()
ce, err := hg_changelog.BuildEntry(rec, fb)
if err != nil {
return nil, err
}
addr, err := mail.ParseAddress(ce.Committer)
if err != nil {
// This occurs when the commit author specifier is
// malformed. Fall back to just using the whole committer
// string as the name.
addr = &mail.Address{
Name: ce.Committer,
Address: "",
}
}
var parents []vcs.CommitID
if !rec.IsStartOfBranch() {
if p := rec.Parent(); p != nil {
parents = append(parents, vcs.CommitID(hex.EncodeToString(rec.Parent().Id())))
}
if rec.Parent2Present() {
parents = append(parents, vcs.CommitID(hex.EncodeToString(rec.Parent2().Id())))
}
}
return &vcs.Commit{
ID: vcs.CommitID(ce.Id),
Author: vcs.Signature{addr.Name, addr.Address, pbtypes.NewTimestamp(ce.Date)},
Message: ce.Comment,
Parents: parents,
}, nil
}
示例2: getParents
func (r *Repository) getParents(revSpec vcs.CommitID) ([]vcs.CommitID, error) {
var parents []vcs.CommitID
cmd := exec.Command("hg", "parents", "-r", string(revSpec), "--template",
`{node}\x00{author|person}\x00{author|email}\x00{date|rfc3339date}\x00{desc}\x00{p1node}\x00{p2node}\x00`)
cmd.Dir = r.Dir
out, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("exec `hg parents` failed: %s. Output was:\n\n%s", err, out)
}
const partsPerCommit = 7 // number of \x00-separated fields per commit
allParts := bytes.Split(out, []byte{'\x00'})
numCommits := len(allParts) / partsPerCommit
for i := 0; i < numCommits; i++ {
parts := allParts[partsPerCommit*i : partsPerCommit*(i+1)]
if p1 := parts[0]; len(p1) > 0 && !bytes.Equal(p1, hgNullParentNodeID) {
parents = append(parents, vcs.CommitID(p1))
}
if p2 := parts[5]; len(p2) > 0 && !bytes.Equal(p2, hgNullParentNodeID) {
parents = append(parents, vcs.CommitID(p2))
}
if p3 := parts[6]; len(p3) > 0 && !bytes.Equal(p3, hgNullParentNodeID) {
parents = append(parents, vcs.CommitID(p3))
}
}
return parents, nil
}
示例3: Branches
func (r *Repository) Branches(_ vcs.BranchesOptions) ([]*vcs.Branch, error) {
r.editLock.RLock()
defer r.editLock.RUnlock()
refs, err := r.u.NewReferenceIterator()
if err != nil {
return nil, err
}
var bs []*vcs.Branch
for {
ref, err := refs.Next()
if isErrIterOver(err) {
break
}
if err != nil {
return nil, err
}
if ref.IsBranch() {
bs = append(bs, &vcs.Branch{Name: ref.Shorthand(), Head: vcs.CommitID(ref.Target().String())})
}
}
sort.Sort(vcs.Branches(bs))
return bs, nil
}
示例4: Tags
func (r *Repository) Tags() ([]*vcs.Tag, error) {
r.editLock.RLock()
defer r.editLock.RUnlock()
refs, err := r.u.NewReferenceIterator()
if err != nil {
return nil, err
}
var ts []*vcs.Tag
for {
ref, err := refs.Next()
if isErrIterOver(err) {
break
}
if err != nil {
return nil, err
}
if ref.IsTag() {
ts = append(ts, &vcs.Tag{Name: ref.Shorthand(), CommitID: vcs.CommitID(ref.Target().String())})
}
}
sort.Sort(vcs.Tags(ts))
return ts, nil
}
示例5: makeFileInfo
func (fs *gitFSLibGit2) makeFileInfo(path string, e *git2go.TreeEntry) (*util.FileInfo, error) {
switch e.Type {
case git2go.ObjectBlob:
return fs.fileInfo(e)
case git2go.ObjectTree:
return fs.dirInfo(e), nil
case git2go.ObjectCommit:
submod, err := fs.repo.LookupSubmodule(path)
if err != nil {
return nil, err
}
// TODO(sqs): add (*Submodule).Free to git2go and defer submod.Free()
// below when that method has been added.
//
// defer submod.Free()
return &util.FileInfo{
Name_: e.Name,
Mode_: vcs.ModeSubmodule,
Sys_: vcs.SubmoduleInfo{
URL: submod.Url(),
CommitID: vcs.CommitID(e.Id.String()),
},
}, nil
}
return nil, fmt.Errorf("unexpected object type %v while making file info (expected blob, tree, or commit)", e.Type)
}
示例6: TestRepository_ResolveRevision
func TestRepository_ResolveRevision(t *testing.T) {
setup()
defer teardown()
repoPath := "a.b/c"
repo_, _ := vcsclient.Repository(repoPath)
repo := repo_.(*repository)
want := vcs.CommitID("abcd")
var called bool
mux.HandleFunc(urlPath(t, RouteRepoRevision, repo, map[string]string{"RepoPath": repoPath, "RevSpec": "myrevspec"}), func(w http.ResponseWriter, r *http.Request) {
called = true
testMethod(t, r, "GET")
http.Redirect(w, r, urlPath(t, RouteRepoCommit, repo, map[string]string{"CommitID": "abcd"}), http.StatusFound)
})
commitID, err := repo.ResolveRevision("myrevspec")
if err != nil {
t.Errorf("Repository.ResolveRevision returned error: %v", err)
}
if !called {
t.Fatal("!called")
}
if commitID != want {
t.Errorf("Repository.ResolveRevision returned %+v, want %+v", commitID, want)
}
}
示例7: TestRepository_CrossRepoMergeBase
func TestRepository_CrossRepoMergeBase(t *testing.T) {
setup()
defer teardown()
repoPath := "a.b/c"
repo_, _ := vcsclient.Repository(repoPath)
repo := repo_.(*repository)
want := vcs.CommitID("abcd")
var called bool
mux.HandleFunc(urlPath(t, RouteRepoCrossRepoMergeBase, repo, map[string]string{"RepoPath": repoPath, "CommitIDA": "a", "BRepoPath": "x.com/y", "CommitIDB": "b"}), func(w http.ResponseWriter, r *http.Request) {
called = true
testMethod(t, r, "GET")
http.Redirect(w, r, urlPath(t, RouteRepoCommit, repo, map[string]string{"CommitID": "abcd"}), http.StatusFound)
})
bRepoPath := "x.com/y"
bRepo, _ := vcsclient.Repository(bRepoPath)
commitID, err := repo.CrossRepoMergeBase("a", bRepo, "b")
if err != nil {
t.Errorf("Repository.CrossRepoMergeBase returned error: %v", err)
}
if !called {
t.Fatal("!called")
}
if commitID != want {
t.Errorf("Repository.CrossRepoMergeBase returned %+v, want %+v", commitID, want)
}
}
示例8: MergeBase
func (r *Repository) MergeBase(a, b vcs.CommitID) (vcs.CommitID, error) {
r.editLock.RLock()
defer r.editLock.RUnlock()
cmd := exec.Command("git", "merge-base", "--", string(a), string(b))
cmd.Dir = r.Dir
out, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("exec %v failed: %s. Output was:\n\n%s", cmd.Args, err, out)
}
return vcs.CommitID(bytes.TrimSpace(out)), nil
}
示例9: ResolveRevision
func (r *Repository) ResolveRevision(spec string) (vcs.CommitID, error) {
cmd := exec.Command("hg", "identify", "--debug", "-i", "--rev="+spec)
cmd.Dir = r.Dir
out, err := cmd.CombinedOutput()
if err != nil {
out = bytes.TrimSpace(out)
if isUnknownRevisionError(string(out), spec) {
return "", vcs.ErrRevisionNotFound
}
return "", fmt.Errorf("exec `hg identify` failed: %s. Output was:\n\n%s", err, out)
}
return vcs.CommitID(bytes.TrimSpace(out)), nil
}
示例10: ResolveBranch
func (r *Repository) ResolveBranch(name string) (vcs.CommitID, error) {
r.editLock.RLock()
defer r.editLock.RUnlock()
b, err := r.u.LookupBranch(name, git2go.BranchLocal)
if err != nil {
if err.Error() == fmt.Sprintf("Cannot locate local branch '%s'", name) {
return "", vcs.ErrBranchNotFound
}
return "", err
}
return vcs.CommitID(b.Target().String()), nil
}
示例11: parseCommitIDInURL
func (r *repository) parseCommitIDInURL(urlStr string) (vcs.CommitID, error) {
url, err := url.Parse(urlStr)
if err != nil {
return "", err
}
var info muxpkg.RouteMatch
match := (*muxpkg.Router)(router).Match(&http.Request{Method: "GET", URL: url}, &info)
if !match || info.Vars["CommitID"] == "" {
return "", errors.New("failed to determine CommitID from URL")
}
return vcs.CommitID(info.Vars["CommitID"]), nil
}
示例12: mergeBaseHoldingEditLock
// mergeBaseHoldingEditLock performs a merge-base. Callers must hold
// the r.editLock (either as a reader or writer).
func (r *Repository) mergeBaseHoldingEditLock(a, b vcs.CommitID) (vcs.CommitID, error) {
ao, err := git2go.NewOid(string(a))
if err != nil {
return "", err
}
bo, err := git2go.NewOid(string(b))
if err != nil {
return "", err
}
mb, err := r.u.MergeBase(ao, bo)
if err != nil {
return "", err
}
return vcs.CommitID(mb.String()), nil
}
示例13: ResolveTag
func (r *Repository) ResolveTag(name string) (vcs.CommitID, error) {
r.editLock.RLock()
defer r.editLock.RUnlock()
// TODO(sqs): slow way to iterate through tags because git_tag_lookup is not
// in git2go yet
refs, err := r.u.NewReferenceIterator()
if err != nil {
return "", err
}
for {
ref, err := refs.Next()
if err != nil {
break
}
if ref.IsTag() && ref.Shorthand() == name {
return vcs.CommitID(ref.Target().String()), nil
}
}
return "", vcs.ErrTagNotFound
}
示例14: BlameFile
func (r *Repository) BlameFile(path string, opt *vcs.BlameOptions) ([]*vcs.Hunk, error) {
r.editLock.RLock()
defer r.editLock.RUnlock()
if opt == nil {
opt = &vcs.BlameOptions{}
}
if opt.OldestCommit != "" {
return nil, fmt.Errorf("OldestCommit not implemented")
}
if err := checkSpecArgSafety(string(opt.NewestCommit)); err != nil {
return nil, err
}
if err := checkSpecArgSafety(string(opt.OldestCommit)); err != nil {
return nil, err
}
args := []string{"blame", "-w", "--porcelain"}
if opt.StartLine != 0 || opt.EndLine != 0 {
args = append(args, fmt.Sprintf("-L%d,%d", opt.StartLine, opt.EndLine))
}
args = append(args, string(opt.NewestCommit), "--", path)
cmd := exec.Command("git", args...)
cmd.Dir = r.Dir
out, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("exec `git blame` failed: %s. Output was:\n\n%s", err, out)
}
if len(out) < 1 {
// go 1.8.5 changed the behavior of `git blame` on empty files.
// previously, it returned a boundary commit. now, it returns nothing.
// TODO(sqs) TODO(beyang): make `git blame` return the boundary commit
// on an empty file somehow, or come up with some other workaround.
st, err := os.Stat(filepath.Join(r.Dir, path))
if err == nil && st.Size() == 0 {
return nil, nil
}
return nil, fmt.Errorf("Expected git output of length at least 1")
}
commits := make(map[string]vcs.Commit)
hunks := make([]*vcs.Hunk, 0)
remainingLines := strings.Split(string(out[:len(out)-1]), "\n")
byteOffset := 0
for len(remainingLines) > 0 {
// Consume hunk
hunkHeader := strings.Split(remainingLines[0], " ")
if len(hunkHeader) != 4 {
fmt.Printf("Remaining lines: %+v, %d, '%s'\n", remainingLines, len(remainingLines), remainingLines[0])
return nil, fmt.Errorf("Expected at least 4 parts to hunkHeader, but got: '%s'", hunkHeader)
}
commitID := hunkHeader[0]
lineNoCur, _ := strconv.Atoi(hunkHeader[2])
nLines, _ := strconv.Atoi(hunkHeader[3])
hunk := &vcs.Hunk{
CommitID: vcs.CommitID(commitID),
StartLine: int(lineNoCur),
EndLine: int(lineNoCur + nLines),
StartByte: byteOffset,
}
if _, in := commits[commitID]; in {
// Already seen commit
byteOffset += len(remainingLines[1])
remainingLines = remainingLines[2:]
} else {
// New commit
author := strings.Join(strings.Split(remainingLines[1], " ")[1:], " ")
email := strings.Join(strings.Split(remainingLines[2], " ")[1:], " ")
if len(email) >= 2 && email[0] == '<' && email[len(email)-1] == '>' {
email = email[1 : len(email)-1]
}
authorTime, err := strconv.ParseInt(strings.Join(strings.Split(remainingLines[3], " ")[1:], " "), 10, 64)
if err != nil {
return nil, fmt.Errorf("Failed to parse author-time %q", remainingLines[3])
}
summary := strings.Join(strings.Split(remainingLines[9], " ")[1:], " ")
commit := vcs.Commit{
ID: vcs.CommitID(commitID),
Message: summary,
Author: vcs.Signature{
Name: author,
Email: email,
Date: pbtypes.NewTimestamp(time.Unix(authorTime, 0).In(time.UTC)),
},
}
if len(remainingLines) >= 13 && strings.HasPrefix(remainingLines[10], "previous ") {
byteOffset += len(remainingLines[12])
remainingLines = remainingLines[13:]
} else if len(remainingLines) >= 13 && remainingLines[10] == "boundary" {
byteOffset += len(remainingLines[12])
remainingLines = remainingLines[13:]
} else if len(remainingLines) >= 12 {
byteOffset += len(remainingLines[11])
remainingLines = remainingLines[12:]
} else if len(remainingLines) == 11 {
// Empty file
remainingLines = remainingLines[11:]
} else {
//.........这里部分代码省略.........
示例15: commitLog
func (r *Repository) commitLog(opt vcs.CommitsOptions) ([]*vcs.Commit, uint, error) {
args := []string{"log", `--format=format:%H%x00%aN%x00%aE%x00%at%x00%cN%x00%cE%x00%ct%x00%B%x00%P%x00`}
if opt.N != 0 {
args = append(args, "-n", strconv.FormatUint(uint64(opt.N), 10))
}
if opt.Skip != 0 {
args = append(args, "--skip="+strconv.FormatUint(uint64(opt.Skip), 10))
}
// Range
rng := string(opt.Head)
if opt.Base != "" {
rng += "..." + string(opt.Base)
}
args = append(args, rng)
cmd := exec.Command("git", args...)
cmd.Dir = r.Dir
out, err := cmd.CombinedOutput()
if err != nil {
out = bytes.TrimSpace(out)
if isBadObjectErr(string(out), string(opt.Head)) {
return nil, 0, vcs.ErrCommitNotFound
}
return nil, 0, fmt.Errorf("exec `git log` failed: %s. Output was:\n\n%s", err, out)
}
const partsPerCommit = 9 // number of \x00-separated fields per commit
allParts := bytes.Split(out, []byte{'\x00'})
numCommits := len(allParts) / partsPerCommit
commits := make([]*vcs.Commit, numCommits)
for i := 0; i < numCommits; i++ {
parts := allParts[partsPerCommit*i : partsPerCommit*(i+1)]
// log outputs are newline separated, so all but the 1st commit ID part
// has an erroneous leading newline.
parts[0] = bytes.TrimPrefix(parts[0], []byte{'\n'})
authorTime, err := strconv.ParseInt(string(parts[3]), 10, 64)
if err != nil {
return nil, 0, fmt.Errorf("parsing git commit author time: %s", err)
}
committerTime, err := strconv.ParseInt(string(parts[6]), 10, 64)
if err != nil {
return nil, 0, fmt.Errorf("parsing git commit committer time: %s", err)
}
var parents []vcs.CommitID
if parentPart := parts[8]; len(parentPart) > 0 {
parentIDs := bytes.Split(parentPart, []byte{' '})
parents = make([]vcs.CommitID, len(parentIDs))
for i, id := range parentIDs {
parents[i] = vcs.CommitID(id)
}
}
commits[i] = &vcs.Commit{
ID: vcs.CommitID(parts[0]),
Author: vcs.Signature{string(parts[1]), string(parts[2]), pbtypes.NewTimestamp(time.Unix(authorTime, 0))},
Committer: &vcs.Signature{string(parts[4]), string(parts[5]), pbtypes.NewTimestamp(time.Unix(committerTime, 0))},
Message: string(bytes.TrimSuffix(parts[7], []byte{'\n'})),
Parents: parents,
}
}
// Count commits.
cmd = exec.Command("git", "rev-list", "--count", rng)
cmd.Dir = r.Dir
out, err = cmd.CombinedOutput()
if err != nil {
return nil, 0, fmt.Errorf("exec `git rev-list --count` failed: %s. Output was:\n\n%s", err, out)
}
out = bytes.TrimSpace(out)
total, err := strconv.ParseUint(string(out), 10, 64)
if err != nil {
return nil, 0, err
}
return commits, uint(total), nil
}