Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit ac095bb

Browse files
authored
new plumbing package (#118)
* plumbing: now core was renamed to core, and formats and clients moved inside
1 parent e523701 commit ac095bb

File tree

133 files changed

+2000
-1933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+2000
-1933
lines changed

blame.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"strings"
99
"unicode/utf8"
1010

11-
"gopkg.in/src-d/go-git.v4/core"
1211
"gopkg.in/src-d/go-git.v4/diff"
12+
"gopkg.in/src-d/go-git.v4/plumbing"
1313
)
1414

1515
type Blame struct {
1616
Path string
17-
Rev core.Hash
17+
Rev plumbing.Hash
1818
Lines []*line
1919
}
2020

@@ -256,7 +256,7 @@ func prettyPrintAuthor(c *Commit) string {
256256
// utility function to calculate the number of runes needed
257257
// to print the longest author name in the blame of a file.
258258
func (b *blame) maxAuthorLength() int {
259-
memo := make(map[core.Hash]struct{}, len(b.graph)-1)
259+
memo := make(map[plumbing.Hash]struct{}, len(b.graph)-1)
260260
fVs := b.graph[len(b.graph)-1]
261261
m := 0
262262
for ln := range fVs {

blame_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package git
22

33
import (
4-
"gopkg.in/src-d/go-git.v4/core"
54
"gopkg.in/src-d/go-git.v4/fixtures"
5+
"gopkg.in/src-d/go-git.v4/plumbing"
66

77
. "gopkg.in/check.v1"
88
)
@@ -24,7 +24,7 @@ func (s *BlameSuite) mockBlame(t blameTest, c *C) (blame *Blame) {
2424
r, ok := s.Repositories[t.repo]
2525
c.Assert(ok, Equals, true)
2626

27-
commit, err := r.Commit(core.NewHash(t.rev))
27+
commit, err := r.Commit(plumbing.NewHash(t.rev))
2828
c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, r, t.rev))
2929

3030
f, err := commit.File(t.path)
@@ -36,7 +36,7 @@ func (s *BlameSuite) mockBlame(t blameTest, c *C) (blame *Blame) {
3636

3737
blamedLines := make([]*line, 0, len(t.blames))
3838
for i := range t.blames {
39-
commit, err := r.Commit(core.NewHash(t.blames[i]))
39+
commit, err := r.Commit(plumbing.NewHash(t.blames[i]))
4040
c.Assert(err, IsNil)
4141
l := &line{
4242
author: commit.Author.Email,
@@ -47,7 +47,7 @@ func (s *BlameSuite) mockBlame(t blameTest, c *C) (blame *Blame) {
4747

4848
return &Blame{
4949
Path: t.path,
50-
Rev: core.NewHash(t.rev),
50+
Rev: plumbing.NewHash(t.rev),
5151
Lines: blamedLines,
5252
}
5353
}
@@ -65,7 +65,7 @@ func (s *BlameSuite) TestBlame(c *C) {
6565
r, ok := s.Repositories[t.repo]
6666
c.Assert(ok, Equals, true)
6767

68-
commit, err := r.Commit(core.NewHash(t.rev))
68+
commit, err := r.Commit(plumbing.NewHash(t.rev))
6969
c.Assert(err, IsNil)
7070

7171
obt, err := commit.Blame(t.path)

blobs.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@ package git
33
import (
44
"io"
55

6-
"gopkg.in/src-d/go-git.v4/core"
6+
"gopkg.in/src-d/go-git.v4/plumbing"
7+
"gopkg.in/src-d/go-git.v4/plumbing/storer"
78
)
89

910
// Blob is used to store file data - it is generally a file.
1011
type Blob struct {
11-
Hash core.Hash
12+
Hash plumbing.Hash
1213
Size int64
1314

14-
obj core.Object
15+
obj plumbing.Object
1516
}
1617

1718
// ID returns the object ID of the blob. The returned value will always match
1819
// the current value of Blob.Hash.
1920
//
2021
// ID is present to fulfill the Object interface.
21-
func (b *Blob) ID() core.Hash {
22+
func (b *Blob) ID() plumbing.Hash {
2223
return b.Hash
2324
}
2425

25-
// Type returns the type of object. It always returns core.BlobObject.
26+
// Type returns the type of object. It always returns plumbing.BlobObject.
2627
//
2728
// Type is present to fulfill the Object interface.
28-
func (b *Blob) Type() core.ObjectType {
29-
return core.BlobObject
29+
func (b *Blob) Type() plumbing.ObjectType {
30+
return plumbing.BlobObject
3031
}
3132

32-
// Decode transforms a core.Object into a Blob struct.
33-
func (b *Blob) Decode(o core.Object) error {
34-
if o.Type() != core.BlobObject {
33+
// Decode transforms a plumbing.Object into a Blob struct.
34+
func (b *Blob) Decode(o plumbing.Object) error {
35+
if o.Type() != plumbing.BlobObject {
3536
return ErrUnsupportedObject
3637
}
3738

@@ -42,8 +43,8 @@ func (b *Blob) Decode(o core.Object) error {
4243
return nil
4344
}
4445

45-
// Encode transforms a Blob into a core.Object.
46-
func (b *Blob) Encode(o core.Object) error {
46+
// Encode transforms a Blob into a plumbing.Object.
47+
func (b *Blob) Encode(o plumbing.Object) error {
4748
w, err := o.Writer()
4849
if err != nil {
4950
return err
@@ -55,7 +56,7 @@ func (b *Blob) Encode(o core.Object) error {
5556
}
5657
defer checkClose(r, &err)
5758
_, err = io.Copy(w, r)
58-
o.SetType(core.BlobObject)
59+
o.SetType(plumbing.BlobObject)
5960
return err
6061
}
6162

@@ -66,15 +67,15 @@ func (b *Blob) Reader() (io.ReadCloser, error) {
6667

6768
// BlobIter provides an iterator for a set of blobs.
6869
type BlobIter struct {
69-
core.ObjectIter
70+
storer.ObjectIter
7071
r *Repository
7172
}
7273

7374
// NewBlobIter returns a CommitIter for the given repository and underlying
7475
// object iterator.
7576
//
7677
// The returned BlobIter will automatically skip over non-blob objects.
77-
func NewBlobIter(r *Repository, iter core.ObjectIter) *BlobIter {
78+
func NewBlobIter(r *Repository, iter storer.ObjectIter) *BlobIter {
7879
return &BlobIter{iter, r}
7980
}
8081

@@ -87,7 +88,7 @@ func (iter *BlobIter) Next() (*Blob, error) {
8788
return nil, err
8889
}
8990

90-
if obj.Type() != core.BlobObject {
91+
if obj.Type() != plumbing.BlobObject {
9192
continue
9293
}
9394

@@ -100,8 +101,8 @@ func (iter *BlobIter) Next() (*Blob, error) {
100101
// an error happens or the end of the iter is reached. If ErrStop is sent
101102
// the iteration is stop but no error is returned. The iterator is closed.
102103
func (iter *BlobIter) ForEach(cb func(*Blob) error) error {
103-
return iter.ObjectIter.ForEach(func(obj core.Object) error {
104-
if obj.Type() != core.BlobObject {
104+
return iter.ObjectIter.ForEach(func(obj plumbing.Object) error {
105+
if obj.Type() != plumbing.BlobObject {
105106
return nil
106107
}
107108

blobs_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"io"
55
"io/ioutil"
66

7-
"gopkg.in/src-d/go-git.v4/core"
7+
"gopkg.in/src-d/go-git.v4/plumbing"
88

99
. "gopkg.in/check.v1"
1010
)
@@ -16,8 +16,8 @@ type BlobsSuite struct {
1616
var _ = Suite(&BlobsSuite{})
1717

1818
func (s *BlobsSuite) TestBlobHash(c *C) {
19-
o := &core.MemoryObject{}
20-
o.SetType(core.BlobObject)
19+
o := &plumbing.MemoryObject{}
20+
o.SetType(plumbing.BlobObject)
2121
o.SetSize(3)
2222

2323
writer, err := o.Writer()
@@ -42,19 +42,19 @@ func (s *BlobsSuite) TestBlobHash(c *C) {
4242
}
4343

4444
func (s *BlobsSuite) TestBlobDecodeEncodeIdempotent(c *C) {
45-
var objects []*core.MemoryObject
45+
var objects []*plumbing.MemoryObject
4646
for _, str := range []string{"foo", "foo\n"} {
47-
obj := &core.MemoryObject{}
47+
obj := &plumbing.MemoryObject{}
4848
obj.Write([]byte(str))
49-
obj.SetType(core.BlobObject)
49+
obj.SetType(plumbing.BlobObject)
5050
obj.Hash()
5151
objects = append(objects, obj)
5252
}
5353
for _, object := range objects {
5454
blob := &Blob{}
5555
err := blob.Decode(object)
5656
c.Assert(err, IsNil)
57-
newObject := &core.MemoryObject{}
57+
newObject := &plumbing.MemoryObject{}
5858
err = blob.Encode(newObject)
5959
c.Assert(err, IsNil)
6060
newObject.Hash() // Ensure Hash is pre-computed before deep comparison

commit.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,26 @@ import (
88
"sort"
99
"strings"
1010

11-
"gopkg.in/src-d/go-git.v4/core"
11+
"gopkg.in/src-d/go-git.v4/plumbing"
12+
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1213
)
1314

1415
// Hash hash of an object
15-
type Hash core.Hash
16+
type Hash plumbing.Hash
1617

1718
// Commit points to a single tree, marking it as what the project looked like
1819
// at a certain point in time. It contains meta-information about that point
1920
// in time, such as a timestamp, the author of the changes since the last
2021
// commit, a pointer to the previous commit(s), etc.
2122
// http://schacon.github.io/gitbook/1_the_git_object_model.html
2223
type Commit struct {
23-
Hash core.Hash
24+
Hash plumbing.Hash
2425
Author Signature
2526
Committer Signature
2627
Message string
2728

28-
tree core.Hash
29-
parents []core.Hash
29+
tree plumbing.Hash
30+
parents []plumbing.Hash
3031
r *Repository
3132
}
3233

@@ -38,7 +39,7 @@ func (c *Commit) Tree() (*Tree, error) {
3839
// Parents return a CommitIter to the parent Commits
3940
func (c *Commit) Parents() *CommitIter {
4041
return NewCommitIter(c.r,
41-
core.NewObjectLookupIter(c.r.s, core.CommitObject, c.parents),
42+
storer.NewObjectLookupIter(c.r.s, plumbing.CommitObject, c.parents),
4243
)
4344
}
4445

@@ -73,20 +74,20 @@ func (c *Commit) Files() (*FileIter, error) {
7374
// the current value of Commit.Hash.
7475
//
7576
// ID is present to fulfill the Object interface.
76-
func (c *Commit) ID() core.Hash {
77+
func (c *Commit) ID() plumbing.Hash {
7778
return c.Hash
7879
}
7980

80-
// Type returns the type of object. It always returns core.CommitObject.
81+
// Type returns the type of object. It always returns plumbing.CommitObject.
8182
//
8283
// Type is present to fulfill the Object interface.
83-
func (c *Commit) Type() core.ObjectType {
84-
return core.CommitObject
84+
func (c *Commit) Type() plumbing.ObjectType {
85+
return plumbing.CommitObject
8586
}
8687

87-
// Decode transforms a core.Object into a Commit struct.
88-
func (c *Commit) Decode(o core.Object) (err error) {
89-
if o.Type() != core.CommitObject {
88+
// Decode transforms a plumbing.Object into a Commit struct.
89+
func (c *Commit) Decode(o plumbing.Object) (err error) {
90+
if o.Type() != plumbing.CommitObject {
9091
return ErrUnsupportedObject
9192
}
9293

@@ -117,9 +118,9 @@ func (c *Commit) Decode(o core.Object) (err error) {
117118
split := bytes.SplitN(line, []byte{' '}, 2)
118119
switch string(split[0]) {
119120
case "tree":
120-
c.tree = core.NewHash(string(split[1]))
121+
c.tree = plumbing.NewHash(string(split[1]))
121122
case "parent":
122-
c.parents = append(c.parents, core.NewHash(string(split[1])))
123+
c.parents = append(c.parents, plumbing.NewHash(string(split[1])))
123124
case "author":
124125
c.Author.Decode(split[1])
125126
case "committer":
@@ -147,9 +148,9 @@ func (c *Commit) History() ([]*Commit, error) {
147148
return commits, err
148149
}
149150

150-
// Encode transforms a Commit into a core.Object.
151-
func (b *Commit) Encode(o core.Object) error {
152-
o.SetType(core.CommitObject)
151+
// Encode transforms a Commit into a plumbing.Object.
152+
func (b *Commit) Encode(o plumbing.Object) error {
153+
o.SetType(plumbing.CommitObject)
153154
w, err := o.Writer()
154155
if err != nil {
155156
return err
@@ -184,7 +185,7 @@ func (b *Commit) Encode(o core.Object) error {
184185
func (c *Commit) String() string {
185186
return fmt.Sprintf(
186187
"%s %s\nAuthor: %s\nDate: %s\n\n%s\n",
187-
core.CommitObject, c.Hash, c.Author.String(),
188+
plumbing.CommitObject, c.Hash, c.Author.String(),
188189
c.Author.When.Format(DateFormat), indent(c.Message),
189190
)
190191
}
@@ -204,15 +205,15 @@ func indent(t string) string {
204205

205206
// CommitIter provides an iterator for a set of commits.
206207
type CommitIter struct {
207-
core.ObjectIter
208+
storer.ObjectIter
208209
r *Repository
209210
}
210211

211212
// NewCommitIter returns a CommitIter for the given repository and underlying
212213
// object iterator.
213214
//
214215
// The returned CommitIter will automatically skip over non-commit objects.
215-
func NewCommitIter(r *Repository, iter core.ObjectIter) *CommitIter {
216+
func NewCommitIter(r *Repository, iter storer.ObjectIter) *CommitIter {
216217
return &CommitIter{iter, r}
217218
}
218219

@@ -232,7 +233,7 @@ func (iter *CommitIter) Next() (*Commit, error) {
232233
// an error happends or the end of the iter is reached. If ErrStop is sent
233234
// the iteration is stop but no error is returned. The iterator is closed.
234235
func (iter *CommitIter) ForEach(cb func(*Commit) error) error {
235-
return iter.ObjectIter.ForEach(func(obj core.Object) error {
236+
return iter.ObjectIter.ForEach(func(obj plumbing.Object) error {
236237
commit := &Commit{r: iter.r}
237238
if err := commit.Decode(obj); err != nil {
238239
return err

0 commit comments

Comments
 (0)