当前位置: 首页>>代码示例>>Golang>>正文


Golang vcs.CommitID函数代码示例

本文整理汇总了Golang中sourcegraph/com/sourcegraph/go-vcs/vcs.CommitID函数的典型用法代码示例。如果您正苦于以下问题:Golang CommitID函数的具体用法?Golang CommitID怎么用?Golang CommitID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CommitID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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
}
开发者ID:alexsaveliev,项目名称:go-vcs,代码行数:30,代码来源:repo.go

示例2: 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
}
开发者ID:shazow,项目名称:go-vcs,代码行数:35,代码来源:repo.go

示例3: serveRepoMergeBase

func (h *Handler) serveRepoMergeBase(w http.ResponseWriter, r *http.Request) error {
	v := mux.Vars(r)

	repo, repoPath, done, err := h.getRepo(r)
	if err != nil {
		return err
	}
	defer done()

	if repo, ok := repo.(vcs.Merger); ok {
		a, b := vcs.CommitID(v["CommitIDA"]), vcs.CommitID(v["CommitIDB"])

		mb, err := repo.MergeBase(a, b)
		if err != nil {
			return err
		}

		var statusCode int
		if commitIDIsCanon(string(a)) && commitIDIsCanon(string(b)) {
			setLongCache(w)
			statusCode = http.StatusMovedPermanently
		} else {
			setShortCache(w)
			statusCode = http.StatusFound
		}
		http.Redirect(w, r, h.router.URLToRepoCommit(repoPath, mb).String(), statusCode)
		return nil
	}

	return &httpError{http.StatusNotImplemented, fmt.Errorf("Merger not yet implemented by %T", repo)}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:31,代码来源:merge.go

示例4: TestServeRepoCrossRepoDiff

func TestServeRepoCrossRepoDiff(t *testing.T) {
	setupHandlerTest()
	defer teardownHandlerTest()

	baseRepoPath := "a.b/c"
	headRepoPath := "x.y/z"
	mockHeadRepo := vcs_testing.MockRepository{}
	opt := vcs.DiffOptions{}

	rm := &mockCrossRepoDiff{
		t:        t,
		base:     vcs.CommitID(strings.Repeat("a", 40)),
		headRepo: mockHeadRepo,
		head:     vcs.CommitID(strings.Repeat("b", 40)),
		opt:      opt,
		diff:     &vcs.Diff{Raw: "diff"},
	}
	sm := &mockService{
		t: t,
		open: func(repoPath string) (interface{}, error) {
			switch repoPath {
			case baseRepoPath:
				return rm, nil
			case headRepoPath:
				return mockHeadRepo, nil
			default:
				panic("unexpected repo clone: " + repoPath)
			}
		},
	}
	testHandler.Service = sm

	resp, err := http.Get(server.URL + testHandler.router.URLToRepoCrossRepoDiff(baseRepoPath, rm.base, headRepoPath, rm.head, &opt).String())
	if err != nil && !isIgnoredRedirectErr(err) {
		t.Fatal(err)
	}
	defer resp.Body.Close()

	if !rm.called {
		t.Errorf("!called")
	}

	var diff *vcs.Diff
	if err := json.NewDecoder(resp.Body).Decode(&diff); err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(diff, rm.diff) {
		t.Errorf("got crossRepoDiff %+v, want %+v", diff, rm.diff)
	}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:51,代码来源:diff_test.go

示例5: ResolveRevision

// ResolveRevision returns the revision that the given revision
// specifier resolves to, or a non-nil error if there is no such
// revision.
func (r *Repository) ResolveRevision(spec string) (vcs.CommitID, error) {
	// TODO: git rev-parse supports a horde of complex syntaxes, it will be a fair bit more work to support all of them.
	// e.g. "[email protected]{yesterday}", "master~3", and various text/path/tree traversal search.

	if len(spec) == 40 {
		commit, err := r.repo.GetCommit(spec)
		if err == nil {
			return vcs.CommitID(commit.Id.String()), nil
		}
	}

	ci, err := r.ResolveBranch(spec)
	if err == nil {
		return ci, nil
	}
	ci, err = r.ResolveTag(spec)
	if err == nil {
		return ci, nil
	}
	// Do an extra lookup just in case it's a complex syntax we don't support
	// TODO: Remove fallback usage: ResolveRevision
	ci, err = r.Repository.ResolveRevision(spec)
	if err == nil {
		return ci, nil
	}
	return ci, vcs.ErrRevisionNotFound
}
开发者ID:emil2k,项目名称:go-vcs,代码行数:30,代码来源:repo.go

示例6: 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
}
开发者ID:shazow,项目名称:go-vcs,代码行数:26,代码来源:repo.go

示例7: Branches

func (r *Repository) Branches(opt vcs.BranchesOptions) ([]*vcs.Branch, error) {
	if opt.ContainsCommit != "" {
		return nil, fmt.Errorf("vcs.BranchesOptions.ContainsCommit option not implemented")
	}

	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
}
开发者ID:shazow,项目名称:go-vcs,代码行数:30,代码来源:repo.go

示例8: 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)
	}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:31,代码来源:repo_test.go

示例9: 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)
	}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:34,代码来源:merge_test.go

示例10: submoduleInfo

func (fs *filesystem) submoduleInfo(path string, e *git.TreeEntry) (*util.FileInfo, error) {
	// TODO: Cache submodules?
	subs, err := e.Tree().GetSubmodules()
	if err != nil {
		return nil, err
	}
	var found *git.Submodule
	for _, sub := range subs {
		if sub.Path == path {
			found = sub
			break
		}
	}

	if found == nil {
		return nil, fmt.Errorf("submodule not found: %s", path)
	}

	return &util.FileInfo{
		Name_: e.Name(),
		Mode_: vcs.ModeSubmodule,
		Sys_: vcs.SubmoduleInfo{
			URL:      found.URL,
			CommitID: vcs.CommitID(e.Id.String()),
		},
	}, nil
}
开发者ID:emil2k,项目名称:go-vcs,代码行数:27,代码来源:vfs.go

示例11: 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.Submodules.Lookup(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)
}
开发者ID:shazow,项目名称:go-vcs,代码行数:29,代码来源:repo.go

示例12: TestServeRepoTreeEntry_File

func TestServeRepoTreeEntry_File(t *testing.T) {
	setupHandlerTest()
	defer teardownHandlerTest()

	commitID := vcs.CommitID(strings.Repeat("a", 40))

	repoPath := "a.b/c"
	rm := &mockFileSystem{
		t:  t,
		at: commitID,
		fs: mapFS(map[string]string{"myfile": "mydata"}),
	}
	sm := &mockServiceForExistingRepo{
		t:        t,
		repoPath: repoPath,
		repo:     rm,
	}
	testHandler.Service = sm

	resp, err := http.Get(server.URL + testHandler.router.URLToRepoTreeEntry(repoPath, commitID, "myfile").String())
	if err != nil {
		t.Fatal(err)
	}
	defer resp.Body.Close()
	if got, want := resp.StatusCode, http.StatusOK; got != want {
		t.Errorf("got status code %d, want %d", got, want)
	}

	if !sm.opened {
		t.Errorf("!opened")
	}
	if !rm.called {
		t.Errorf("!called")
	}

	var e *vcsclient.TreeEntry
	if err := json.NewDecoder(resp.Body).Decode(&e); err != nil {
		t.Fatal(err)
	}

	wantEntry := &vcsclient.TreeEntry{
		Name:     "myfile",
		Type:     vcsclient.FileEntry,
		Size:     6,
		ModTime:  pbtypes.NewTimestamp(time.Time{}),
		Contents: []byte("mydata"),
	}

	if !reflect.DeepEqual(e, wantEntry) {
		t.Errorf("got tree entry %+v, want %+v", e, wantEntry)
	}

	// used canonical commit ID, so should be long-cached
	if cc := resp.Header.Get("cache-control"); cc != longCacheControl {
		t.Errorf("got cache-control %q, want %q", cc, longCacheControl)
	}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:57,代码来源:tree_test.go

示例13: ResolveBranch

// ResolveBranch returns the branch with the given name, or
// ErrBranchNotFound if no such branch exists.
func (r *Repository) ResolveBranch(name string) (vcs.CommitID, error) {
	id, err := r.repo.GetCommitIdOfBranch(name)
	if _, ok := err.(git.RefNotFound); ok {
		return "", vcs.ErrBranchNotFound
	} else if err != nil {
		// Unexpected error
		return "", err
	}
	return vcs.CommitID(id), nil
}
开发者ID:emil2k,项目名称:go-vcs,代码行数:12,代码来源:repo.go

示例14: TestServeRepoDiff

func TestServeRepoDiff(t *testing.T) {
	setupHandlerTest()
	defer teardownHandlerTest()

	repoPath := "a.b/c"
	opt := vcs.DiffOptions{}

	rm := &mockDiff{
		t:    t,
		base: vcs.CommitID(strings.Repeat("a", 40)),
		head: vcs.CommitID(strings.Repeat("b", 40)),
		opt:  opt,
		diff: &vcs.Diff{Raw: "diff"},
	}
	sm := &mockServiceForExistingRepo{
		t:        t,
		repoPath: repoPath,
		repo:     rm,
	}
	testHandler.Service = sm

	resp, err := http.Get(server.URL + testHandler.router.URLToRepoDiff(repoPath, rm.base, rm.head, &opt).String())
	if err != nil && !isIgnoredRedirectErr(err) {
		t.Fatal(err)
	}
	defer resp.Body.Close()

	if !sm.opened {
		t.Errorf("!opened")
	}
	if !rm.called {
		t.Errorf("!called")
	}

	var diff *vcs.Diff
	if err := json.NewDecoder(resp.Body).Decode(&diff); err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(diff, rm.diff) {
		t.Errorf("got diff %+v, want %+v", diff, rm.diff)
	}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:43,代码来源:diff_test.go

示例15: checkCommitID

// checkCommitID returns whether the commit ID is canonical (i.e., the
// full 40-character commit ID), and an error (if any).
func checkCommitID(commitID string) (vcs.CommitID, bool, error) {
	if commitID == "" {
		return "", false, &httpError{http.StatusBadRequest, errors.New("CommitID is empty")}
	}

	if !isLowercaseHex(commitID) {
		return "", false, &httpError{http.StatusBadRequest, errors.New("CommitID must be lowercase hex")}
	}

	return vcs.CommitID(commitID), commitIDIsCanon(commitID), nil
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:13,代码来源:commit.go


注:本文中的sourcegraph/com/sourcegraph/go-vcs/vcs.CommitID函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。