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

Commit f4bea44

Browse files
smolamcuadros
authored andcommitted
move plumbing from top level package to plumbing (#183)
* plumbing: rename Object -> EncodedObject. * plumbing/storer: rename ObjectStorer -> EncodedObjectStorer. * move difftree to plumbing/difftree. * move diff -> utils/diff * make Object/Tag/Blob/Tree/Commit/File depend on storer. * Object and its implementations now depend only on storer.EncodedObjectStorer, not git.Repository. * Tests are decoupled accordingly. * move Object/Commit/File/Tag/Tree to plumbing/object. * move Object/Commit/File/Tag/Tree to plumbing/object. * move checkClose to utils/ioutil. * move RevListObjects to plumbing/revlist.Objects. * move DiffTree to plumbing/difftree package. * rename files with plural nouns to singular * plumbing/object: add GetBlob/GetCommit/GetTag/GetTree.
1 parent 825c00d commit f4bea44

Some content is hidden

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

64 files changed

+974
-771
lines changed

blame.go

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

11-
"gopkg.in/src-d/go-git.v4/diff"
1211
"gopkg.in/src-d/go-git.v4/plumbing"
12+
"gopkg.in/src-d/go-git.v4/plumbing/object"
13+
"gopkg.in/src-d/go-git.v4/utils/diff"
1314
)
1415

15-
type Blame struct {
16+
type BlameResult struct {
1617
Path string
1718
Rev plumbing.Hash
1819
Lines []*line
@@ -62,7 +63,7 @@ type Blame struct {
6263
// 1. Add memoization between revlist and assign.
6364
//
6465
// 2. It is using much more memory than needed, see the TODOs below.
65-
func (c *Commit) Blame(path string) (*Blame, error) {
66+
func Blame(c *object.Commit, path string) (*BlameResult, error) {
6667
b := new(blame)
6768
b.fRev = c
6869
b.path = path
@@ -92,7 +93,7 @@ func (c *Commit) Blame(path string) (*Blame, error) {
9293
return nil, err
9394
}
9495

95-
return &Blame{
96+
return &BlameResult{
9697
Path: path,
9798
Rev: c.Hash,
9899
Lines: lines,
@@ -111,7 +112,7 @@ func newLine(author, text string) *line {
111112
}
112113
}
113114

114-
func newLines(contents []string, commits []*Commit) ([]*line, error) {
115+
func newLines(contents []string, commits []*object.Commit) ([]*line, error) {
115116
if len(contents) != len(commits) {
116117
return nil, errors.New("contents and commits have different length")
117118
}
@@ -126,18 +127,18 @@ func newLines(contents []string, commits []*Commit) ([]*line, error) {
126127
// this struct is internally used by the blame function to hold its
127128
// inputs, outputs and state.
128129
type blame struct {
129-
path string // the path of the file to blame
130-
fRev *Commit // the commit of the final revision of the file to blame
131-
revs []*Commit // the chain of revisions affecting the the file to blame
132-
data []string // the contents of the file across all its revisions
133-
graph [][]*Commit // the graph of the lines in the file across all the revisions TODO: not all commits are needed, only the current rev and the prev
130+
path string // the path of the file to blame
131+
fRev *object.Commit // the commit of the final revision of the file to blame
132+
revs []*object.Commit // the chain of revisions affecting the the file to blame
133+
data []string // the contents of the file across all its revisions
134+
graph [][]*object.Commit // the graph of the lines in the file across all the revisions TODO: not all commits are needed, only the current rev and the prev
134135
}
135136

136137
// calculte the history of a file "path", starting from commit "from", sorted by commit date.
137138
func (b *blame) fillRevs() error {
138139
var err error
139140

140-
b.revs, err = b.fRev.References(b.path)
141+
b.revs, err = References(b.fRev, b.path)
141142
if err != nil {
142143
return err
143144
}
@@ -146,7 +147,7 @@ func (b *blame) fillRevs() error {
146147

147148
// build graph of a file from its revision history
148149
func (b *blame) fillGraphAndData() error {
149-
b.graph = make([][]*Commit, len(b.revs))
150+
b.graph = make([][]*object.Commit, len(b.revs))
150151
b.data = make([]string, len(b.revs)) // file contents in all the revisions
151152
// for every revision of the file, starting with the first
152153
// one...
@@ -162,13 +163,13 @@ func (b *blame) fillGraphAndData() error {
162163
}
163164
nLines := countLines(b.data[i])
164165
// create a node for each line
165-
b.graph[i] = make([]*Commit, nLines)
166+
b.graph[i] = make([]*object.Commit, nLines)
166167
// assign a commit to each node
167168
// if this is the first revision, then the node is assigned to
168169
// this first commit.
169170
if i == 0 {
170171
for j := 0; j < nLines; j++ {
171-
b.graph[i][j] = (*Commit)(b.revs[i])
172+
b.graph[i][j] = (*object.Commit)(b.revs[i])
172173
}
173174
} else {
174175
// if this is not the first commit, then assign to the old
@@ -182,11 +183,11 @@ func (b *blame) fillGraphAndData() error {
182183

183184
// sliceGraph returns a slice of commits (one per line) for a particular
184185
// revision of a file (0=first revision).
185-
func (b *blame) sliceGraph(i int) []*Commit {
186+
func (b *blame) sliceGraph(i int) []*object.Commit {
186187
fVs := b.graph[i]
187-
result := make([]*Commit, 0, len(fVs))
188+
result := make([]*object.Commit, 0, len(fVs))
188189
for _, v := range fVs {
189-
c := Commit(*v)
190+
c := object.Commit(*v)
190191
result = append(result, &c)
191192
}
192193
return result
@@ -209,7 +210,7 @@ func (b *blame) assignOrigin(c, p int) {
209210
b.graph[c][dl] = b.graph[p][sl]
210211
case hunks[h].Type == 1:
211212
dl++
212-
b.graph[c][dl] = (*Commit)(b.revs[c])
213+
b.graph[c][dl] = (*object.Commit)(b.revs[c])
213214
case hunks[h].Type == -1:
214215
sl++
215216
default:
@@ -249,7 +250,7 @@ func (b *blame) GoString() string {
249250
}
250251

251252
// utility function to pretty print the author.
252-
func prettyPrintAuthor(c *Commit) string {
253+
func prettyPrintAuthor(c *object.Commit) string {
253254
return fmt.Sprintf("%s %s", c.Author.Name, c.Author.When.Format("2006-01-02"))
254255
}
255256

blame_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func (s *BlameSuite) TestBlame(c *C) {
2929
commit, err := r.Commit(plumbing.NewHash(t.rev))
3030
c.Assert(err, IsNil)
3131

32-
obt, err := commit.Blame(t.path)
32+
obt, err := Blame(commit, t.path)
3333
c.Assert(err, IsNil)
3434
c.Assert(obt, DeepEquals, exp)
3535
}
3636
}
3737

38-
func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *Blame) {
38+
func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameResult) {
3939
commit, err := r.Commit(plumbing.NewHash(t.rev))
4040
c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, t.repo, t.rev))
4141

@@ -57,7 +57,7 @@ func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *Blame)
5757
blamedLines = append(blamedLines, l)
5858
}
5959

60-
return &Blame{
60+
return &BlameResult{
6161
Path: t.path,
6262
Rev: plumbing.NewHash(t.rev),
6363
Lines: blamedLines,

common.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package git
22

33
import (
4-
"io"
54
"strings"
65

76
"gopkg.in/src-d/go-git.v4/config"
@@ -13,7 +12,7 @@ import (
1312
// information in an system directory (such as `.git`) and others
1413
// implementations are in memmory being ephemeral
1514
type Storer interface {
16-
storer.ObjectStorer
15+
storer.EncodedObjectStorer
1716
storer.ReferenceStorer
1817
config.ConfigStorer
1918
}
@@ -34,26 +33,3 @@ func countLines(s string) int {
3433

3534
return nEOL + 1
3635
}
37-
38-
// checkClose is used with defer to close the given io.Closer and check its
39-
// returned error value. If Close returns an error and the given *error
40-
// is not nil, *error is set to the error returned by Close.
41-
//
42-
// checkClose is typically used with named return values like so:
43-
//
44-
// func do(obj *Object) (err error) {
45-
// w, err := obj.Writer()
46-
// if err != nil {
47-
// return nil
48-
// }
49-
// defer checkClose(w, &err)
50-
// // work with w
51-
// }
52-
func checkClose(c io.Closer, err *error) {
53-
if cerr := c.Close(); cerr != nil && *err == nil {
54-
*err = cerr
55-
}
56-
}
57-
58-
// DateFormat is the format being use in the orignal git implementation
59-
const DateFormat = "Mon Jan 02 15:04:05 2006 -0700"

common_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"gopkg.in/src-d/go-git.v4/fixtures"
88
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
9+
"gopkg.in/src-d/go-git.v4/plumbing/storer"
910
"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
1011

1112
. "gopkg.in/check.v1"
@@ -16,6 +17,7 @@ func Test(t *testing.T) { TestingT(t) }
1617
type BaseSuite struct {
1718
fixtures.Suite
1819
Repository *Repository
20+
Storer storer.EncodedObjectStorer
1921

2022
cache map[string]*Repository
2123
}
@@ -31,6 +33,7 @@ func (s *BaseSuite) SetUpSuite(c *C) {
3133
func (s *BaseSuite) buildBasicRepository(c *C) {
3234
f := fixtures.Basic().One()
3335
s.Repository = s.NewRepository(f)
36+
s.Storer = s.Repository.s
3437
}
3538

3639
func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository {

cshared/blame_cshared.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func c_Blame_get_Path(b uint64) *C.char {
1313
if !ok {
1414
return nil
1515
}
16-
blame := obj.(*git.Blame)
16+
blame := obj.(*git.BlameResult)
1717
return C.CString(blame.Path)
1818
}
1919

@@ -23,7 +23,7 @@ func c_Blame_get_Rev(b uint64) *C.char {
2323
if !ok {
2424
return nil
2525
}
26-
blame := obj.(*git.Blame)
26+
blame := obj.(*git.BlameResult)
2727
return CBytes(blame.Rev[:])
2828
}
2929

@@ -33,7 +33,7 @@ func c_Blame_get_Lines_len(b uint64) int {
3333
if !ok {
3434
return 0
3535
}
36-
blame := obj.(*git.Blame)
36+
blame := obj.(*git.BlameResult)
3737
return len(blame.Lines)
3838
}
3939

@@ -43,7 +43,7 @@ func c_Blame_get_Lines_item(b uint64, i int) {
4343
if !ok {
4444
return
4545
}
46-
blame := obj.(*git.Blame)
46+
blame := obj.(*git.BlameResult)
4747
line := blame.Lines[i]
4848
_ = line
4949
}

0 commit comments

Comments
 (0)