本文整理汇总了Golang中gopkg/in/src-d/go-git/v2/core.NewHash函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHash函数的具体用法?Golang NewHash怎么用?Golang NewHash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRevList
func (s *ReferencesSuite) TestRevList(c *C) {
for _, t := range referencesTests {
repo, ok := s.repos[t.repo]
c.Assert(ok, Equals, true)
commit, err := repo.Commit(core.NewHash(t.commit))
c.Assert(err, IsNil)
revs, err := commit.References(t.path)
c.Assert(err, IsNil)
c.Assert(len(revs), Equals, len(t.revs))
for i := range revs {
if revs[i].Hash.String() != t.revs[i] {
commit, err := repo.Commit(core.NewHash(t.revs[i]))
c.Assert(err, IsNil)
equiv, err := equivalent(t.path, revs[i], commit)
c.Assert(err, IsNil)
if equiv {
fmt.Printf("cherry-pick detected: %s %s\n", revs[i].Hash.String(), t.revs[i])
} else {
c.Fatalf("\nrepo=%s, commit=%s, path=%s, \n%s",
t.repo, t.commit, t.path, compareSideBySide(t.revs, revs))
}
}
}
}
}
示例2: mockBlame
func (s *BlameCommon) mockBlame(t blameTest, c *C) (blame *Blame) {
repo, ok := s.repos[t.repo]
c.Assert(ok, Equals, true)
commit, err := repo.Commit(core.NewHash(t.rev))
c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, repo, t.rev))
file, err := commit.File(t.path)
c.Assert(err, IsNil)
lines := file.Lines()
c.Assert(len(t.blames), Equals, len(lines), Commentf(
"repo=%s, path=%s, rev=%s: the number of lines in the file and the number of expected blames differ (len(blames)=%d, len(lines)=%d)\nblames=%#q\nlines=%#q", t.repo, t.path, t.rev, len(t.blames), len(lines), t.blames, lines))
blamedLines := make([]*line, 0, len(t.blames))
for i := range t.blames {
commit, err := repo.Commit(core.NewHash(t.blames[i]))
c.Assert(err, IsNil)
l := &line{
author: commit.Author.Email,
text: lines[i],
}
blamedLines = append(blamedLines, l)
}
return &Blame{
Path: t.path,
Rev: core.NewHash(t.rev),
Lines: blamedLines,
}
}
示例3: TestGitUploadPackRequest
func (s *SuiteCommon) TestGitUploadPackRequest(c *C) {
r := &GitUploadPackRequest{}
r.Want(core.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
r.Want(core.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
r.Have(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
c.Assert(r.String(), Equals,
"0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n"+
"0032want 2b41ef280fdb67a9b250678686a0c3e03b0a9989\n"+
"0032have 6ecf0ef2c2dffb796033e5a02219af86ec6584e5\n0000"+
"0009done\n",
)
}
示例4: makeHashSlice
func makeHashSlice(hashes []string) []core.Hash {
series := make([]core.Hash, 0, len(hashes))
for _, member := range hashes {
series = append(series, core.NewHash(member))
}
return series
}
示例5: TestFetchNotConnected
func (s *SuiteRemote) TestFetchNotConnected(c *C) {
r := NewGitUploadPackService("foo bar")
pr := &common.GitUploadPackRequest{}
pr.Want(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
_, err := r.Fetch(pr)
c.Assert(err, Equals, ErrNotConnected)
}
示例6: AssertObjects
func AssertObjects(c *C, s *core.RAWObjectStorage, expects []string) {
c.Assert(len(expects), Equals, len(s.Objects))
for _, expected := range expects {
obtained, ok := s.Get(core.NewHash(expected))
c.Assert(ok, Equals, true)
c.Assert(obtained.Hash().String(), Equals, expected)
}
}
示例7: readLine
func (r *GitUploadPackInfo) readLine(line string) {
parts := strings.Split(strings.Trim(line, " \n"), " ")
if len(parts) != 2 {
return
}
r.Refs[parts[1]] = core.NewHash(parts[0])
}
示例8: Ref
// Ref returns the Hash pointing the given refName
func (r *Remote) Ref(refName string) (core.Hash, error) {
ref, ok := r.upInfo.Refs[refName]
if !ok {
return core.NewHash(""), fmt.Errorf("unable to find ref %q", refName)
}
return ref, nil
}
示例9: makeObjectSlice
func makeObjectSlice(hashes []string, storage core.ObjectStorage) []core.Object {
series := make([]core.Object, 0, len(hashes))
for _, member := range hashes {
obj, err := storage.Get(core.NewHash(member))
if err == nil {
series = append(series, obj)
}
}
return series
}
示例10: TestContents
func (s *SuiteFile) TestContents(c *C) {
for i, t := range contentsTests {
commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
file, err := commit.File(t.path)
c.Assert(err, IsNil)
c.Assert(file.Contents(), Equals, t.contents, Commentf(
"subtest %d: commit=%s, path=%s", i, t.commit, t.path))
}
}
示例11: commits
// returns the commits from a slice of hashes
func (s *ReferencesSuite) commits(cc *C, repo string, hs ...string) []*Commit {
r, ok := s.repos[repo]
cc.Assert(ok, Equals, true)
result := make([]*Commit, 0, len(hs))
for _, h := range hs {
c, err := r.Commit(core.NewHash(h))
cc.Assert(err, IsNil)
result = append(result, c)
}
return result
}
示例12: TestIgnoreEmptyDirEntries
// It is difficult to assert that we are ignoring an (empty) dir as even
// if we don't, no files will be found in it.
//
// At least this test has a high chance of panicking if
// we don't ignore empty dirs.
func (s *SuiteFile) TestIgnoreEmptyDirEntries(c *C) {
for i, t := range ignoreEmptyDirEntriesTests {
commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
for file := range commit.Tree().Files() {
_ = file.Contents()
// this would probably panic if we are not ignoring empty dirs
}
}
}
示例13: Info
func (s *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
hash := core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
cap := common.NewCapabilities()
cap.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")
return &common.GitUploadPackInfo{
Capabilities: cap,
Head: hash,
Refs: map[string]core.Hash{"refs/heads/master": hash},
}, nil
}
示例14: TestFile
func (s *SuiteCommit) TestFile(c *C) {
for i, t := range fileTests {
commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
file, err := commit.File(t.path)
found := err == nil
c.Assert(found, Equals, t.found, Commentf("subtest %d, path=%s, commit=%s", i, t.path, t.commit))
if found {
c.Assert(file.Hash.String(), Equals, t.blobHash, Commentf("subtest %d, commit=%s, path=%s", i, t.commit, t.path))
}
}
}
示例15: Decode
// Decode transform an core.Object into a Blob struct
func (c *Commit) Decode(o core.Object) error {
c.Hash = o.Hash()
r := bufio.NewReader(o.Reader())
var message bool
for {
line, err := r.ReadSlice('\n')
if err != nil && err != io.EOF {
return err
}
line = bytes.TrimSpace(line)
if !message {
if len(line) == 0 {
message = true
continue
}
split := bytes.SplitN(line, []byte{' '}, 2)
switch string(split[0]) {
case "tree":
c.tree = core.NewHash(string(split[1]))
case "parent":
c.parents = append(c.parents, core.NewHash(string(split[1])))
case "author":
c.Author.Decode(split[1])
case "committer":
c.Committer.Decode(split[1])
}
} else {
c.Message += string(line) + "\n"
}
if err == io.EOF {
return nil
}
}
}