本文整理汇总了Golang中gopkg/in/src-d/go-git/v4/plumbing.NewHash函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHash函数的具体用法?Golang NewHash怎么用?Golang NewHash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFetchDepth
func (s *RemoteSuite) TestFetchDepth(c *C) {
url := s.GetBasicLocalRepositoryURL()
sto := memory.NewStorage()
r := newRemote(sto, nil, &config.RemoteConfig{Name: "foo", URL: url})
refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*")
err := r.Fetch(&FetchOptions{
RefSpecs: []config.RefSpec{refspec},
Depth: 1,
})
c.Assert(err, IsNil)
c.Assert(sto.Objects, HasLen, 18)
expectedRefs := []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
plumbing.NewReferenceFromStrings("refs/remotes/origin/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"),
}
for _, exp := range expectedRefs {
r, _ := sto.Reference(exp.Name())
c.Assert(exp.String(), Equals, r.String())
}
h, err := sto.Shallow()
c.Assert(err, IsNil)
c.Assert(h, HasLen, 2)
c.Assert(h, DeepEquals, []plumbing.Hash{
plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881"),
plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
})
}
示例2: ExampleUploadRequest_Encode
func ExampleUploadRequest_Encode() {
// Create an empty UlReq with the contents you want...
ur := NewUploadRequest()
// Add a couple of wants
ur.Wants = append(ur.Wants, plumbing.NewHash("3333333333333333333333333333333333333333"))
ur.Wants = append(ur.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))
ur.Wants = append(ur.Wants, plumbing.NewHash("2222222222222222222222222222222222222222"))
// And some capabilities you will like the server to use
ur.Capabilities.Add(capability.OFSDelta)
ur.Capabilities.Add(capability.SymRef, "HEAD:/refs/heads/master")
// Add a couple of shallows
ur.Shallows = append(ur.Shallows, plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
ur.Shallows = append(ur.Shallows, plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
// And retrict the answer of the server to commits newer than "2015-01-02 03:04:05 UTC"
since := time.Date(2015, time.January, 2, 3, 4, 5, 0, time.UTC)
ur.Depth = DepthSince(since)
// Create a new Encode for the stdout...
e := newUlReqEncoder(os.Stdout)
// ...and encode the upload-request to it.
_ = e.Encode(ur) // ignoring errors for brevity
// Output:
// 005bwant 1111111111111111111111111111111111111111 ofs-delta symref=HEAD:/refs/heads/master
// 0032want 2222222222222222222222222222222222222222
// 0032want 3333333333333333333333333333333333333333
// 0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
// 0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
// 001cdeepen-since 1420167845
// 0000
}
示例3: TestWantsWithCapabilities
func (s *UlReqEncodeSuite) TestWantsWithCapabilities(c *C) {
ur := NewUploadRequest()
ur.Wants = append(ur.Wants,
plumbing.NewHash("4444444444444444444444444444444444444444"),
plumbing.NewHash("1111111111111111111111111111111111111111"),
plumbing.NewHash("3333333333333333333333333333333333333333"),
plumbing.NewHash("2222222222222222222222222222222222222222"),
plumbing.NewHash("5555555555555555555555555555555555555555"),
)
ur.Capabilities.Add(capability.MultiACK)
ur.Capabilities.Add(capability.OFSDelta)
ur.Capabilities.Add(capability.Sideband)
ur.Capabilities.Add(capability.SymRef, "HEAD:/refs/heads/master")
ur.Capabilities.Add(capability.ThinPack)
expected := []string{
"want 1111111111111111111111111111111111111111 multi_ack ofs-delta side-band symref=HEAD:/refs/heads/master thin-pack\n",
"want 2222222222222222222222222222222222222222\n",
"want 3333333333333333333333333333333333333333\n",
"want 4444444444444444444444444444444444444444\n",
"want 5555555555555555555555555555555555555555\n",
pktline.FlushString,
}
testUlReqEncode(c, ur, expected)
}
示例4: TestRevListObjectsNewBranch
// * 6ecf0ef vendor stuff
// | * e8d3ffa some code in a branch
// |/
// * 918c48b some code
// -----
func (s *RevListSuite) TestRevListObjectsNewBranch(c *C) {
someCommit := s.commit(c, plumbing.NewHash(someCommit))
someCommitBranch := s.commit(c, plumbing.NewHash(someCommitBranch))
someCommitOtherBranch := s.commit(c, plumbing.NewHash(someCommitOtherBranch))
localHist, err := Objects(s.Storer, []*object.Commit{someCommit}, nil)
c.Assert(err, IsNil)
remoteHist, err := Objects(
s.Storer, []*object.Commit{someCommitBranch, someCommitOtherBranch}, localHist)
c.Assert(err, IsNil)
revList := map[string]bool{
"a8d315b2b1c615d43042c3a62402b8a54288cf5c": true, // init tree
"cf4aa3b38974fb7d81f367c0830f7d78d65ab86b": true, // vendor folder
"9dea2395f5403188298c1dabe8bdafe562c491e3": true, // foo.go
"e8d3ffab552895c19b9fcf7aa264d277cde33881": true, // branch commit
"dbd3641b371024f44d0e469a9c8f5457b0660de1": true, // init tree
"7e59600739c96546163833214c36459e324bad0a": true, // README
"6ecf0ef2c2dffb796033e5a02219af86ec6584e5": true, // otherBranch commit
}
for _, h := range remoteHist {
c.Assert(revList[h.String()], Equals, true)
}
c.Assert(len(remoteHist), Equals, len(revList))
}
示例5: TestWantsWithCapabilities
func (s *SuiteEncoder) TestWantsWithCapabilities(c *C) {
ur := New()
ur.Wants = append(ur.Wants, plumbing.NewHash("4444444444444444444444444444444444444444"))
ur.Wants = append(ur.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))
ur.Wants = append(ur.Wants, plumbing.NewHash("3333333333333333333333333333333333333333"))
ur.Wants = append(ur.Wants, plumbing.NewHash("2222222222222222222222222222222222222222"))
ur.Wants = append(ur.Wants, plumbing.NewHash("5555555555555555555555555555555555555555"))
ur.Capabilities.Add("sysref", "HEAD:/refs/heads/master")
ur.Capabilities.Add("multi_ack")
ur.Capabilities.Add("thin-pack")
ur.Capabilities.Add("side-band")
ur.Capabilities.Add("ofs-delta")
expected := []string{
"want 1111111111111111111111111111111111111111 multi_ack ofs-delta side-band sysref=HEAD:/refs/heads/master thin-pack\n",
"want 2222222222222222222222222222222222222222\n",
"want 3333333333333333333333333333333333333333\n",
"want 4444444444444444444444444444444444444444\n",
"want 5555555555555555555555555555555555555555\n",
pktline.FlushString,
}
testEncode(c, ur, expected)
}
示例6: TestTagEncodeDecodeIdempotent
func (s *TagSuite) TestTagEncodeDecodeIdempotent(c *C) {
ts, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00")
c.Assert(err, IsNil)
tags := []*Tag{
{
Name: "foo",
Tagger: Signature{Name: "Foo", Email: "[email protected]", When: ts},
Message: "Message\n\nFoo\nBar\nBaz\n\n",
TargetType: plumbing.BlobObject,
Target: plumbing.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d"),
},
{
Name: "foo",
Tagger: Signature{Name: "Foo", Email: "[email protected]", When: ts},
TargetType: plumbing.BlobObject,
Target: plumbing.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d"),
},
}
for _, tag := range tags {
obj := &plumbing.MemoryObject{}
err = tag.Encode(obj)
c.Assert(err, IsNil)
newTag := &Tag{}
err = newTag.Decode(obj)
c.Assert(err, IsNil)
tag.Hash = obj.Hash()
c.Assert(newTag, DeepEquals, tag)
}
}
示例7: mockBlame
func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameResult) {
commit, err := r.Commit(plumbing.NewHash(t.rev))
c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, t.repo, t.rev))
f, err := commit.File(t.path)
c.Assert(err, IsNil)
lines, err := f.Lines()
c.Assert(err, IsNil)
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 := r.Commit(plumbing.NewHash(t.blames[i]))
c.Assert(err, IsNil)
l := &line{
author: commit.Author.Email,
text: lines[i],
}
blamedLines = append(blamedLines, l)
}
return &BlameResult{
Path: t.path,
Rev: plumbing.NewHash(t.rev),
Lines: blamedLines,
}
}
示例8: TestRevList
func (s *ReferencesSuite) TestRevList(c *C) {
for _, t := range referencesTests {
r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repo).One())
commit, err := r.Commit(plumbing.NewHash(t.commit))
c.Assert(err, IsNil)
revs, err := References(commit, 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 := s.Repository.Commit(plumbing.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))
}
}
}
}
}
示例9: TestManyShallowSingleWant
func (s *UlReqDecodeSuite) TestManyShallowSingleWant(c *C) {
payloads := []string{
"want 3333333333333333333333333333333333333333 ofs-delta multi_ack",
"shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"shallow cccccccccccccccccccccccccccccccccccccccc",
"shallow dddddddddddddddddddddddddddddddddddddddd",
pktline.FlushString,
}
ur := s.testDecodeOK(c, payloads)
expectedWants := []plumbing.Hash{
plumbing.NewHash("3333333333333333333333333333333333333333"),
}
expectedShallows := []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
plumbing.NewHash("cccccccccccccccccccccccccccccccccccccccc"),
plumbing.NewHash("dddddddddddddddddddddddddddddddddddddddd"),
}
sort.Sort(byHash(expectedShallows))
c.Assert(ur.Wants, DeepEquals, expectedWants)
c.Assert(ur.Capabilities.Supports(capability.OFSDelta), Equals, true)
c.Assert(ur.Capabilities.Supports(capability.MultiACK), Equals, true)
sort.Sort(byHash(ur.Shallows))
c.Assert(ur.Shallows, DeepEquals, expectedShallows)
}
示例10: TestSingleShallowManyWants
func (s *UlReqDecodeSuite) TestSingleShallowManyWants(c *C) {
payloads := []string{
"want 3333333333333333333333333333333333333333 ofs-delta multi_ack",
"want 4444444444444444444444444444444444444444",
"want 1111111111111111111111111111111111111111",
"want 2222222222222222222222222222222222222222",
"shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
pktline.FlushString,
}
ur := s.testDecodeOK(c, payloads)
expectedWants := []plumbing.Hash{
plumbing.NewHash("1111111111111111111111111111111111111111"),
plumbing.NewHash("2222222222222222222222222222222222222222"),
plumbing.NewHash("3333333333333333333333333333333333333333"),
plumbing.NewHash("4444444444444444444444444444444444444444"),
}
sort.Sort(byHash(expectedWants))
expectedShallows := []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
}
sort.Sort(byHash(ur.Wants))
c.Assert(ur.Wants, DeepEquals, expectedWants)
c.Assert(ur.Capabilities.Supports(capability.OFSDelta), Equals, true)
c.Assert(ur.Capabilities.Supports(capability.MultiACK), Equals, true)
c.Assert(ur.Shallows, DeepEquals, expectedShallows)
}
示例11: TestString
func (s *TagSuite) TestString(c *C) {
tag := s.tag(c, plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69"))
c.Assert(tag.String(), Equals, ""+
"tag annotated-tag\n"+
"Tagger: Máximo Cuadros <[email protected]>\n"+
"Date: Wed Sep 21 21:13:35 2016 +0200\n"+
"\n"+
"example annotated tag\n"+
"\n"+
"commit f7b877701fbf855b44c0a9e86f3fdce2c298b07f\n"+
"Author: Máximo Cuadros <[email protected]>\n"+
"Date: Wed Sep 21 21:10:52 2016 +0200\n"+
"\n"+
" initial\n"+
"\n",
)
tag = s.tag(c, plumbing.NewHash("152175bf7e5580299fa1f0ba41ef6474cc043b70"))
c.Assert(tag.String(), Equals, ""+
"tag tree-tag\n"+
"Tagger: Máximo Cuadros <[email protected]>\n"+
"Date: Wed Sep 21 21:17:56 2016 +0200\n"+
"\n"+
"a tagged tree\n"+
"\n",
)
}
示例12: TestValidateShallows
func (s *UlReqSuite) TestValidateShallows(c *C) {
r := NewUploadRequest()
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))
r.Shallows = append(r.Shallows, plumbing.NewHash("2222222222222222222222222222222222222222"))
err := r.Validate()
c.Assert(err, NotNil)
r.Capabilities.Set(capability.Shallow)
err = r.Validate()
c.Assert(err, IsNil)
}
示例13: TestRevListObjectsReverse
func (s *RevListSuite) TestRevListObjectsReverse(c *C) {
initCommit := s.commit(c, plumbing.NewHash(initialCommit))
secondCommit := s.commit(c, plumbing.NewHash(secondCommit))
localHist, err := Objects(s.Storer, []*object.Commit{secondCommit}, nil)
c.Assert(err, IsNil)
remoteHist, err := Objects(s.Storer, []*object.Commit{initCommit}, localHist)
c.Assert(err, IsNil)
c.Assert(len(remoteHist), Equals, 0)
}
示例14: TestFetchNoChanges
func (s *RemoteSuite) TestFetchNoChanges(c *C) {
r := NewGitUploadPackService(s.Endpoint)
c.Assert(r.Connect(), IsNil)
req := &common.GitUploadPackRequest{}
req.Want(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
req.Have(plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
reader, err := r.Fetch(req)
c.Assert(err, Equals, common.ErrEmptyGitUploadPack)
c.Assert(reader, IsNil)
}
示例15: TestChangeFilesInsert
func (s *DiffTreeSuite) TestChangeFilesInsert(c *C) {
tree := s.tree(c, plumbing.NewHash("a8d315b2b1c615d43042c3a62402b8a54288cf5c"))
change := &Change{Action: Insert}
change.To.Name = "json/long.json"
change.To.Tree = tree
change.To.TreeEntry.Hash = plumbing.NewHash("49c6bb89b17060d7b4deacb7b338fcc6ea2352a9")
from, to, err := change.Files()
c.Assert(err, IsNil)
c.Assert(from, IsNil)
c.Assert(to.ID(), Equals, change.To.TreeEntry.Hash)
}