Browse Source

update code.gitea.io/git (#450)

Lunny Xiao 3 years ago
parent
commit
47a7529d96

+ 1 - 1
cmd/serve.go

@@ -121,7 +121,7 @@ func handleUpdateTask(uuid string, user, repoUser *models.User, reponame string,
121 121
 
122 122
 	// Ask for running deliver hook and test pull request tasks.
123 123
 	reqURL := setting.LocalURL + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" +
124
-		strings.TrimPrefix(task.RefName, git.BRANCH_PREFIX) + "&secret=" + base.EncodeMD5(repoUser.Salt) + "&pusher=" + com.ToStr(user.ID)
124
+		strings.TrimPrefix(task.RefName, git.BranchPrefix) + "&secret=" + base.EncodeMD5(repoUser.Salt) + "&pusher=" + com.ToStr(user.ID)
125 125
 	log.GitLogger.Trace("Trigger task: %s", reqURL)
126 126
 
127 127
 	resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{

+ 2 - 2
models/action.go

@@ -494,12 +494,12 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
494 494
 	isNewBranch := false
495 495
 	opType := ActionCommitRepo
496 496
 	// Check it's tag push or branch.
497
-	if strings.HasPrefix(opts.RefFullName, git.TAG_PREFIX) {
497
+	if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
498 498
 		opType = ActionPushTag
499 499
 		opts.Commits = &PushCommits{}
500 500
 	} else {
501 501
 		// if not the first commit, set the compare URL.
502
-		if opts.OldCommitID == git.EMPTY_SHA {
502
+		if opts.OldCommitID == git.EmptySHA {
503 503
 			isNewBranch = true
504 504
 		} else {
505 505
 			opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)

+ 1 - 1
models/pull.go

@@ -380,7 +380,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
380 380
 	l.PushFront(mergeCommit)
381 381
 
382 382
 	p := &api.PushPayload{
383
-		Ref:        git.BRANCH_PREFIX + pr.BaseBranch,
383
+		Ref:        git.BranchPrefix + pr.BaseBranch,
384 384
 		Before:     pr.MergeBase,
385 385
 		After:      pr.MergedCommitID,
386 386
 		CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),

+ 4 - 4
models/repo_editor.go

@@ -158,13 +158,13 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
158 158
 	}
159 159
 	oldCommitID := opts.LastCommitID
160 160
 	if opts.NewBranch != opts.OldBranch {
161
-		oldCommitID = git.EMPTY_SHA
161
+		oldCommitID = git.EmptySHA
162 162
 	}
163 163
 	if err := CommitRepoAction(CommitRepoActionOptions{
164 164
 		PusherName:  doer.Name,
165 165
 		RepoOwnerID: repo.MustOwner().ID,
166 166
 		RepoName:    repo.Name,
167
-		RefFullName: git.BRANCH_PREFIX + opts.NewBranch,
167
+		RefFullName: git.BranchPrefix + opts.NewBranch,
168 168
 		OldCommitID: oldCommitID,
169 169
 		NewCommitID: commit.ID.String(),
170 170
 		Commits:     pushCommits,
@@ -297,7 +297,7 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
297 297
 		PusherName:  doer.Name,
298 298
 		RepoOwnerID: repo.MustOwner().ID,
299 299
 		RepoName:    repo.Name,
300
-		RefFullName: git.BRANCH_PREFIX + opts.NewBranch,
300
+		RefFullName: git.BranchPrefix + opts.NewBranch,
301 301
 		OldCommitID: opts.LastCommitID,
302 302
 		NewCommitID: commit.ID.String(),
303 303
 		Commits:     pushCommits,
@@ -533,7 +533,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
533 533
 		PusherName:  doer.Name,
534 534
 		RepoOwnerID: repo.MustOwner().ID,
535 535
 		RepoName:    repo.Name,
536
-		RefFullName: git.BRANCH_PREFIX + opts.NewBranch,
536
+		RefFullName: git.BranchPrefix + opts.NewBranch,
537 537
 		OldCommitID: opts.LastCommitID,
538 538
 		NewCommitID: commit.ID.String(),
539 539
 		Commits:     pushCommits,

+ 4 - 4
models/update.go

@@ -91,10 +91,10 @@ type PushUpdateOptions struct {
91 91
 // PushUpdate must be called for any push actions in order to
92 92
 // generates necessary push action history feeds.
93 93
 func PushUpdate(opts PushUpdateOptions) (err error) {
94
-	isNewRef := opts.OldCommitID == git.EMPTY_SHA
95
-	isDelRef := opts.NewCommitID == git.EMPTY_SHA
94
+	isNewRef := opts.OldCommitID == git.EmptySHA
95
+	isDelRef := opts.NewCommitID == git.EmptySHA
96 96
 	if isNewRef && isDelRef {
97
-		return fmt.Errorf("Old and new revisions are both %s", git.EMPTY_SHA)
97
+		return fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
98 98
 	}
99 99
 
100 100
 	repoPath := RepoPath(opts.RepoUserName, opts.RepoName)
@@ -127,7 +127,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
127 127
 	}
128 128
 
129 129
 	// Push tags.
130
-	if strings.HasPrefix(opts.RefFullName, git.TAG_PREFIX) {
130
+	if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
131 131
 		if err := CommitRepoAction(CommitRepoActionOptions{
132 132
 			PusherName:  opts.PusherName,
133 133
 			RepoOwnerID: owner.ID,

File diff suppressed because it is too large
+ 251 - 228
modules/bindata/bindata.go


+ 1 - 1
routers/repo/http.go

@@ -208,7 +208,7 @@ func HTTP(ctx *context.Context) {
208 208
 						RepoUserName: username,
209 209
 						RepoName:     reponame,
210 210
 					}); err == nil {
211
-						go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refFullName, git.BRANCH_PREFIX), true)
211
+						go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refFullName, git.BranchPrefix), true)
212 212
 					}
213 213
 
214 214
 				}

+ 2 - 2
routers/repo/webhook.go

@@ -361,7 +361,7 @@ func TestWebhook(ctx *context.Context) {
361 361
 	if commit == nil {
362 362
 		ghost := models.NewGhostUser()
363 363
 		commit = &git.Commit{
364
-			ID:            git.MustIDFromString(git.EMPTY_SHA),
364
+			ID:            git.MustIDFromString(git.EmptySHA),
365 365
 			Author:        ghost.NewGitSig(),
366 366
 			Committer:     ghost.NewGitSig(),
367 367
 			CommitMessage: "This is a fake commit",
@@ -370,7 +370,7 @@ func TestWebhook(ctx *context.Context) {
370 370
 
371 371
 	apiUser := ctx.User.APIFormat()
372 372
 	p := &api.PushPayload{
373
-		Ref:    git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
373
+		Ref:    git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
374 374
 		Before: commit.ID.String(),
375 375
 		After:  commit.ID.String(),
376 376
 		Commits: []*api.PayloadCommit{

+ 2 - 2
routers/repo/wiki.go

@@ -66,7 +66,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
66 66
 		}
67 67
 		pages := make([]PageMeta, 0, len(entries))
68 68
 		for i := range entries {
69
-			if entries[i].Type == git.OBJECT_BLOB && strings.HasSuffix(entries[i].Name(), ".md") {
69
+			if entries[i].Type == git.ObjectBlob && strings.HasSuffix(entries[i].Name(), ".md") {
70 70
 				name := strings.TrimSuffix(entries[i].Name(), ".md")
71 71
 				pages = append(pages, PageMeta{
72 72
 					Name: name,
@@ -171,7 +171,7 @@ func WikiPages(ctx *context.Context) {
171 171
 	}
172 172
 	pages := make([]PageMeta, 0, len(entries))
173 173
 	for i := range entries {
174
-		if entries[i].Type == git.OBJECT_BLOB && strings.HasSuffix(entries[i].Name(), ".md") {
174
+		if entries[i].Type == git.ObjectBlob && strings.HasSuffix(entries[i].Name(), ".md") {
175 175
 			c, err := wikiRepo.GetCommitByPath(entries[i].Name())
176 176
 			if err != nil {
177 177
 				ctx.Handle(500, "GetCommit", err)

File diff suppressed because it is too large
+ 30 - 106
vendor/code.gitea.io/git/CONTRIBUTING.md


+ 0 - 9
vendor/code.gitea.io/git/CONTRIBUTORS

@@ -1,9 +0,0 @@
1
-Andrey Nering <nobody@nobody.tld> (@andreynering)
2
-Kim Carlbäcker <kim.carlbacker@gmail.com> (@bkcsoft)
3
-LefsFlare <nobody@nobody.tld> (@LefsFlarey)
4
-Lunny Xiao <xiaolunwen@gmail.com> (@lunny)
5
-Rachid Zarouali <nobody@nobody.tld> (@xinity)
6
-Rémy Boulanouar <admin@dblk.org> (@DblK)
7
-Sandro Santilli <strk@kbt.io> (@strk)
8
-Thibault Meyer <nobody@nobody.tld> (@0xbaadf00d)
9
-Thomas Boerger <thomas@webhippie.de> (@tboerger)

+ 4 - 2
vendor/code.gitea.io/git/MAINTAINERS

@@ -1,4 +1,6 @@
1
-Andrey Nering <nobody@nobody.tld> (@andreynering)
1
+Alexey Makhov <amakhov@avito.ru> (@makhov)
2
+Andrey Nering <andrey.nering@gmail.com> (@andreynering)
3
+Kees de Vries <bouwko@gmail.com> (@Bwko)
2 4
 Kim Carlbäcker <kim.carlbacker@gmail.com> (@bkcsoft)
3 5
 LefsFlare <nobody@nobody.tld> (@LefsFlarey)
4 6
 Lunny Xiao <xiaolunwen@gmail.com> (@lunny)
@@ -6,5 +8,5 @@ Matthias Loibl <mail@matthiasloibl.com> (@metalmatze)
6 8
 Rachid Zarouali <nobody@nobody.tld> (@xinity)
7 9
 Rémy Boulanouar <admin@dblk.org> (@DblK)
8 10
 Sandro Santilli <strk@kbt.io> (@strk)
9
-Thibault Meyer <nobody@nobody.tld> (@0xbaadf00d)
11
+Thibault Meyer <meyer.thibault@gmail.com> (@0xbaadf00d)
10 12
 Thomas Boerger <thomas@webhippie.de> (@tboerger)

+ 9 - 0
vendor/code.gitea.io/git/README.md

@@ -10,6 +10,15 @@
10 10
 This project is a Go module to access Git through shell commands. For further
11 11
 informations take a look at the current [documentation](https://godoc.org/code.gitea.io/git).
12 12
 
13
+## Contributing
14
+
15
+Fork -> Patch -> Push -> Pull Request
16
+
17
+## Authors
18
+
19
+* [Maintainers](https://github.com/orgs/go-gitea/people)
20
+* [Contributors](https://github.com/go-gitea/git/graphs/contributors)
21
+
13 22
 ## License
14 23
 
15 24
 This project is under the MIT License. See the [LICENSE](LICENSE) file for the

+ 1 - 0
vendor/code.gitea.io/git/blob.go

@@ -25,6 +25,7 @@ func (b *Blob) Data() (io.Reader, error) {
25 25
 	return bytes.NewBuffer(stdout), nil
26 26
 }
27 27
 
28
+// DataPipeline gets content of blob and write the result or error to stdout or stderr
28 29
 func (b *Blob) DataPipeline(stdout, stderr io.Writer) error {
29 30
 	return NewCommand("show", b.ID.String()).RunInDirPipeline(b.repo.Path, stdout, stderr)
30 31
 }

+ 8 - 5
vendor/code.gitea.io/git/command.go

@@ -13,6 +13,11 @@ import (
13 13
 	"time"
14 14
 )
15 15
 
16
+var (
17
+	// GlobalCommandArgs global command args for external package setting
18
+	GlobalCommandArgs []string
19
+)
20
+
16 21
 // Command represents a command with its subcommands or arguments.
17 22
 type Command struct {
18 23
 	name string
@@ -30,7 +35,7 @@ func (c *Command) String() string {
30 35
 func NewCommand(args ...string) *Command {
31 36
 	return &Command{
32 37
 		name: "git",
33
-		args: args,
38
+		args: append(GlobalCommandArgs, args...),
34 39
 	}
35 40
 }
36 41
 
@@ -40,13 +45,11 @@ func (c *Command) AddArguments(args ...string) *Command {
40 45
 	return c
41 46
 }
42 47
 
43
-const DEFAULT_TIMEOUT = 60 * time.Second
44
-
45 48
 // RunInDirTimeoutPipeline executes the command in given directory with given timeout,
46 49
 // it pipes stdout and stderr to given io.Writer.
47 50
 func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error {
48 51
 	if timeout == -1 {
49
-		timeout = DEFAULT_TIMEOUT
52
+		timeout = 60 * time.Second
50 53
 	}
51 54
 
52 55
 	if len(dir) == 0 {
@@ -106,7 +109,7 @@ func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error {
106 109
 	return c.RunInDirTimeoutPipeline(-1, dir, stdout, stderr)
107 110
 }
108 111
 
109
-// RunInDir executes the command in given directory
112
+// RunInDirBytes executes the command in given directory
110 113
 // and returns stdout in []byte and error (combined with stderr).
111 114
 func (c *Command) RunInDirBytes(dir string) ([]byte, error) {
112 115
 	return c.RunInDirTimeout(-1, dir)

+ 18 - 7
vendor/code.gitea.io/git/commit.go

@@ -18,13 +18,13 @@ import (
18 18
 // Commit represents a git commit.
19 19
 type Commit struct {
20 20
 	Tree
21
-	ID            sha1 // The ID of this commit object
21
+	ID            SHA1 // The ID of this commit object
22 22
 	Author        *Signature
23 23
 	Committer     *Signature
24 24
 	CommitMessage string
25 25
 
26
-	parents        []sha1 // SHA1 strings
27
-	submoduleCache *objectCache
26
+	parents        []SHA1 // SHA1 strings
27
+	submoduleCache *ObjectCache
28 28
 }
29 29
 
30 30
 // Message returns the commit message. Same as retrieving CommitMessage directly.
@@ -39,9 +39,9 @@ func (c *Commit) Summary() string {
39 39
 
40 40
 // ParentID returns oid of n-th parent (0-based index).
41 41
 // It returns nil if no such parent exists.
42
-func (c *Commit) ParentID(n int) (sha1, error) {
42
+func (c *Commit) ParentID(n int) (SHA1, error) {
43 43
 	if n >= len(c.parents) {
44
-		return sha1{}, ErrNotExist{"", ""}
44
+		return SHA1{}, ErrNotExist{"", ""}
45 45
 	}
46 46
 	return c.parents[n], nil
47 47
 }
@@ -73,6 +73,7 @@ func isImageFile(data []byte) (string, bool) {
73 73
 	return contentType, false
74 74
 }
75 75
 
76
+// IsImageFile is a file image type
76 77
 func (c *Commit) IsImageFile(name string) bool {
77 78
 	blob, err := c.GetBlobByPath(name)
78 79
 	if err != nil {
@@ -95,7 +96,7 @@ func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) {
95 96
 	return c.repo.getCommitByPathWithID(c.ID, relpath)
96 97
 }
97 98
 
98
-// AddAllChanges marks local changes to be ready for commit.
99
+// AddChanges marks local changes to be ready for commit.
99 100
 func AddChanges(repoPath string, all bool, files ...string) error {
100 101
 	cmd := NewCommand("add")
101 102
 	if all {
@@ -105,6 +106,7 @@ func AddChanges(repoPath string, all bool, files ...string) error {
105 106
 	return err
106 107
 }
107 108
 
109
+// CommitChangesOptions the options when a commit created
108 110
 type CommitChangesOptions struct {
109 111
 	Committer *Signature
110 112
 	Author    *Signature
@@ -166,22 +168,27 @@ func CommitsCount(repoPath, revision string) (int64, error) {
166 168
 	return commitsCount(repoPath, revision, "")
167 169
 }
168 170
 
171
+// CommitsCount returns number of total commits of until current revision.
169 172
 func (c *Commit) CommitsCount() (int64, error) {
170 173
 	return CommitsCount(c.repo.Path, c.ID.String())
171 174
 }
172 175
 
176
+// CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
173 177
 func (c *Commit) CommitsByRange(page int) (*list.List, error) {
174 178
 	return c.repo.commitsByRange(c.ID, page)
175 179
 }
176 180
 
181
+// CommitsBefore returns all the commits before current revision
177 182
 func (c *Commit) CommitsBefore() (*list.List, error) {
178 183
 	return c.repo.getCommitsBefore(c.ID)
179 184
 }
180 185
 
186
+// CommitsBeforeLimit returns num commits before current revision
181 187
 func (c *Commit) CommitsBeforeLimit(num int) (*list.List, error) {
182 188
 	return c.repo.getCommitsBeforeLimit(c.ID, num)
183 189
 }
184 190
 
191
+// CommitsBeforeUntil returns the commits between commitID to current revision
185 192
 func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error) {
186 193
 	endCommit, err := c.repo.GetCommit(commitID)
187 194
 	if err != nil {
@@ -190,15 +197,18 @@ func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error) {
190 197
 	return c.repo.CommitsBetween(c, endCommit)
191 198
 }
192 199
 
200
+// SearchCommits returns the commits match the keyword before current revision
193 201
 func (c *Commit) SearchCommits(keyword string) (*list.List, error) {
194 202
 	return c.repo.searchCommits(c.ID, keyword)
195 203
 }
196 204
 
205
+// GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision
197 206
 func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error) {
198 207
 	return c.repo.getFilesChanged(pastCommit, c.ID.String())
199 208
 }
200 209
 
201
-func (c *Commit) GetSubModules() (*objectCache, error) {
210
+// GetSubModules get all the sub modules of current revision git tree
211
+func (c *Commit) GetSubModules() (*ObjectCache, error) {
202 212
 	if c.submoduleCache != nil {
203 213
 		return c.submoduleCache, nil
204 214
 	}
@@ -236,6 +246,7 @@ func (c *Commit) GetSubModules() (*objectCache, error) {
236 246
 	return c.submoduleCache, nil
237 247
 }
238 248
 
249
+// GetSubModule get the sub module according entryname
239 250
 func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
240 251
 	modules, err := c.GetSubModules()
241 252
 	if err != nil {

+ 4 - 0
vendor/code.gitea.io/git/commit_archive.go

@@ -10,13 +10,17 @@ import (
10 10
 	"strings"
11 11
 )
12 12
 
13
+// ArchiveType archive types
13 14
 type ArchiveType int
14 15
 
15 16
 const (
17
+	// ZIP zip archive type
16 18
 	ZIP ArchiveType = iota + 1
19
+	// TARGZ tar gz archive type
17 20
 	TARGZ
18 21
 )
19 22
 
23
+// CreateArchive create archive content to the target path
20 24
 func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error {
21 25
 	var format string
22 26
 	switch archiveType {

+ 6 - 0
vendor/code.gitea.io/git/error.go

@@ -9,10 +9,12 @@ import (
9 9
 	"time"
10 10
 )
11 11
 
12
+// ErrExecTimeout error when exec timed out
12 13
 type ErrExecTimeout struct {
13 14
 	Duration time.Duration
14 15
 }
15 16
 
17
+// IsErrExecTimeout if some error is ErrExecTimeout
16 18
 func IsErrExecTimeout(err error) bool {
17 19
 	_, ok := err.(ErrExecTimeout)
18 20
 	return ok
@@ -22,11 +24,13 @@ func (err ErrExecTimeout) Error() string {
22 24
 	return fmt.Sprintf("execution is timeout [duration: %v]", err.Duration)
23 25
 }
24 26
 
27
+// ErrNotExist commit not exist error
25 28
 type ErrNotExist struct {
26 29
 	ID      string
27 30
 	RelPath string
28 31
 }
29 32
 
33
+// IsErrNotExist if some error is ErrNotExist
30 34
 func IsErrNotExist(err error) bool {
31 35
 	_, ok := err.(ErrNotExist)
32 36
 	return ok
@@ -36,10 +40,12 @@ func (err ErrNotExist) Error() string {
36 40
 	return fmt.Sprintf("object does not exist [id: %s, rel_path: %s]", err.ID, err.RelPath)
37 41
 }
38 42
 
43
+// ErrUnsupportedVersion error when required git version not matched
39 44
 type ErrUnsupportedVersion struct {
40 45
 	Required string
41 46
 }
42 47
 
48
+// IsErrUnsupportedVersion if some error is ErrUnsupportedVersion
43 49
 func IsErrUnsupportedVersion(err error) bool {
44 50
 	_, ok := err.(ErrUnsupportedVersion)
45 51
 	return ok

+ 5 - 5
vendor/code.gitea.io/git/git.go

@@ -10,16 +10,16 @@ import (
10 10
 	"time"
11 11
 )
12 12
 
13
-const _VERSION = "0.4.2"
14
-
13
+// Version return this package's current version
15 14
 func Version() string {
16
-	return _VERSION
15
+	return "0.4.2"
17 16
 }
18 17
 
19 18
 var (
20 19
 	// Debug enables verbose logging on everything.
21 20
 	// This should be false in case Gogs starts in SSH mode.
22
-	Debug  = false
21
+	Debug = false
22
+	// Prefix the log prefix
23 23
 	Prefix = "[git-module] "
24 24
 )
25 25
 
@@ -38,7 +38,7 @@ func log(format string, args ...interface{}) {
38 38
 
39 39
 var gitVersion string
40 40
 
41
-// Version returns current Git version from shell.
41
+// BinVersion returns current Git version from shell.
42 42
 func BinVersion() (string, error) {
43 43
 	if len(gitVersion) > 0 {
44 44
 		return gitVersion, nil

+ 3 - 0
vendor/code.gitea.io/git/hook.go

@@ -22,6 +22,7 @@ var hookNames = []string{
22 22
 }
23 23
 
24 24
 var (
25
+	// ErrNotValidHook error when a git hook is not valid
25 26
 	ErrNotValidHook = errors.New("not a valid Git hook")
26 27
 )
27 28
 
@@ -70,6 +71,7 @@ func GetHook(repoPath, name string) (*Hook, error) {
70 71
 	return h, nil
71 72
 }
72 73
 
74
+// Name return the name of the hook
73 75
 func (h *Hook) Name() string {
74 76
 	return h.name
75 77
 }
@@ -102,6 +104,7 @@ func ListHooks(repoPath string) (_ []*Hook, err error) {
102 104
 }
103 105
 
104 106
 const (
107
+	// HookPathUpdate hook update path
105 108
 	HookPathUpdate = "hooks/update"
106 109
 )
107 110
 

+ 8 - 5
vendor/code.gitea.io/git/repo.go

@@ -18,11 +18,11 @@ import (
18 18
 type Repository struct {
19 19
 	Path string
20 20
 
21
-	commitCache *objectCache
22
-	tagCache    *objectCache
21
+	commitCache *ObjectCache
22
+	tagCache    *ObjectCache
23 23
 }
24 24
 
25
-const _PRETTY_LOG_FORMAT = `--pretty=format:%H`
25
+const prettyLogFormat = `--pretty=format:%H`
26 26
 
27 27
 func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) {
28 28
 	l := list.New()
@@ -32,8 +32,8 @@ func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, err
32 32
 
33 33
 	parts := bytes.Split(logs, []byte{'\n'})
34 34
 
35
-	for _, commitId := range parts {
36
-		commit, err := repo.GetCommit(string(commitId))
35
+	for _, commitID := range parts {
36
+		commit, err := repo.GetCommit(string(commitID))
37 37
 		if err != nil {
38 38
 			return nil, err
39 39
 		}
@@ -80,6 +80,7 @@ func OpenRepository(repoPath string) (*Repository, error) {
80 80
 	}, nil
81 81
 }
82 82
 
83
+// CloneRepoOptions options when clone a repository
83 84
 type CloneRepoOptions struct {
84 85
 	Timeout time.Duration
85 86
 	Mirror  bool
@@ -118,6 +119,7 @@ func Clone(from, to string, opts CloneRepoOptions) (err error) {
118 119
 	return err
119 120
 }
120 121
 
122
+// PullRemoteOptions options when pull from remote
121 123
 type PullRemoteOptions struct {
122 124
 	Timeout time.Duration
123 125
 	All     bool
@@ -153,6 +155,7 @@ func Push(repoPath, remote, branch string) error {
153 155
 	return err
154 156
 }
155 157
 
158
+// CheckoutOptions options when heck out some branch
156 159
 type CheckoutOptions struct {
157 160
 	Timeout   time.Duration
158 161
 	Branch    string

+ 9 - 7
vendor/code.gitea.io/git/repo_branch.go

@@ -11,7 +11,8 @@ import (
11 11
 	"github.com/mcuadros/go-version"
12 12
 )
13 13
 
14
-const BRANCH_PREFIX = "refs/heads/"
14
+// BranchPrefix base dir of the branch information file store on git
15
+const BranchPrefix = "refs/heads/"
15 16
 
16 17
 // IsReferenceExist returns true if given reference exists in the repository.
17 18
 func IsReferenceExist(repoPath, name string) bool {
@@ -21,9 +22,10 @@ func IsReferenceExist(repoPath, name string) bool {
21 22
 
22 23
 // IsBranchExist returns true if given branch exists in the repository.
23 24
 func IsBranchExist(repoPath, name string) bool {
24
-	return IsReferenceExist(repoPath, BRANCH_PREFIX+name)
25
+	return IsReferenceExist(repoPath, BranchPrefix+name)
25 26
 }
26 27
 
28
+// IsBranchExist returns true if given branch exists in current repository.
27 29
 func (repo *Repository) IsBranchExist(name string) bool {
28 30
 	return IsBranchExist(repo.Path, name)
29 31
 }
@@ -42,12 +44,12 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
42 44
 	}
43 45
 	stdout = strings.TrimSpace(stdout)
44 46
 
45
-	if !strings.HasPrefix(stdout, BRANCH_PREFIX) {
47
+	if !strings.HasPrefix(stdout, BranchPrefix) {
46 48
 		return nil, fmt.Errorf("invalid HEAD branch: %v", stdout)
47 49
 	}
48 50
 
49 51
 	return &Branch{
50
-		Name: stdout[len(BRANCH_PREFIX):],
52
+		Name: stdout[len(BranchPrefix):],
51 53
 		Path: stdout,
52 54
 	}, nil
53 55
 }
@@ -58,7 +60,7 @@ func (repo *Repository) SetDefaultBranch(name string) error {
58 60
 		return ErrUnsupportedVersion{"1.7.10"}
59 61
 	}
60 62
 
61
-	_, err := NewCommand("symbolic-ref", "HEAD", BRANCH_PREFIX+name).RunInDir(repo.Path)
63
+	_, err := NewCommand("symbolic-ref", "HEAD", BranchPrefix+name).RunInDir(repo.Path)
62 64
 	return err
63 65
 }
64 66
 
@@ -76,12 +78,12 @@ func (repo *Repository) GetBranches() ([]string, error) {
76 78
 		if len(fields) != 2 {
77 79
 			continue // NOTE: I should believe git will not give me wrong string.
78 80
 		}
79
-		branches[i] = strings.TrimPrefix(fields[1], BRANCH_PREFIX)
81
+		branches[i] = strings.TrimPrefix(fields[1], BranchPrefix)
80 82
 	}
81 83
 	return branches, nil
82 84
 }
83 85
 
84
-// Option(s) for delete branch
86
+// DeleteBranchOptions Option(s) for delete branch
85 87
 type DeleteBranchOptions struct {
86 88
 	Force bool
87 89
 }

+ 23 - 16
vendor/code.gitea.io/git/repo_commit.go

@@ -28,12 +28,12 @@ func (repo *Repository) getRefCommitID(name string) (string, error) {
28 28
 
29 29
 // GetBranchCommitID returns last commit ID string of given branch.
30 30
 func (repo *Repository) GetBranchCommitID(name string) (string, error) {
31
-	return repo.getRefCommitID(BRANCH_PREFIX + name)
31
+	return repo.getRefCommitID(BranchPrefix + name)
32 32
 }
33 33
 
34 34
 // GetTagCommitID returns last commit ID string of given tag.
35 35
 func (repo *Repository) GetTagCommitID(name string) (string, error) {
36
-	return repo.getRefCommitID(TAG_PREFIX + name)
36
+	return repo.getRefCommitID(TagPrefix + name)
37 37
 }
38 38
 
39 39
 // parseCommitData parses commit information from the (uncompressed) raw
@@ -41,7 +41,7 @@ func (repo *Repository) GetTagCommitID(name string) (string, error) {
41 41
 // \n\n separate headers from message
42 42
 func parseCommitData(data []byte) (*Commit, error) {
43 43
 	commit := new(Commit)
44
-	commit.parents = make([]sha1, 0, 1)
44
+	commit.parents = make([]SHA1, 0, 1)
45 45
 	// we now have the contents of the commit object. Let's investigate...
46 46
 	nextline := 0
47 47
 l:
@@ -90,7 +90,7 @@ l:
90 90
 	return commit, nil
91 91
 }
92 92
 
93
-func (repo *Repository) getCommit(id sha1) (*Commit, error) {
93
+func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
94 94
 	c, ok := repo.commitCache.Get(id.String())
95 95
 	if ok {
96 96
 		log("Hit cache: %s", id)
@@ -142,6 +142,7 @@ func (repo *Repository) GetBranchCommit(name string) (*Commit, error) {
142 142
 	return repo.GetCommit(commitID)
143 143
 }
144 144
 
145
+// GetTagCommit get the commit of the specific tag via name
145 146
 func (repo *Repository) GetTagCommit(name string) (*Commit, error) {
146 147
 	commitID, err := repo.GetTagCommitID(name)
147 148
 	if err != nil {
@@ -150,13 +151,13 @@ func (repo *Repository) GetTagCommit(name string) (*Commit, error) {
150 151
 	return repo.GetCommit(commitID)
151 152
 }
152 153
 
153
-func (repo *Repository) getCommitByPathWithID(id sha1, relpath string) (*Commit, error) {
154
+func (repo *Repository) getCommitByPathWithID(id SHA1, relpath string) (*Commit, error) {
154 155
 	// File name starts with ':' must be escaped.
155 156
 	if relpath[0] == ':' {
156 157
 		relpath = `\` + relpath
157 158
 	}
158 159
 
159
-	stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, id.String(), "--", relpath).RunInDir(repo.Path)
160
+	stdout, err := NewCommand("log", "-1", prettyLogFormat, id.String(), "--", relpath).RunInDir(repo.Path)
160 161
 	if err != nil {
161 162
 		return nil, err
162 163
 	}
@@ -171,7 +172,7 @@ func (repo *Repository) getCommitByPathWithID(id sha1, relpath string) (*Commit,
171 172
 
172 173
 // GetCommitByPath returns the last commit of relative path.
173 174
 func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
174
-	stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path)
175
+	stdout, err := NewCommand("log", "-1", prettyLogFormat, "--", relpath).RunInDirBytes(repo.Path)
175 176
 	if err != nil {
176 177
 		return nil, err
177 178
 	}
@@ -183,19 +184,20 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
183 184
 	return commits.Front().Value.(*Commit), nil
184 185
 }
185 186
 
187
+// CommitsRangeSize the default commits range size
186 188
 var CommitsRangeSize = 50
187 189
 
188
-func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) {
190
+func (repo *Repository) commitsByRange(id SHA1, page int) (*list.List, error) {
189 191
 	stdout, err := NewCommand("log", id.String(), "--skip="+strconv.Itoa((page-1)*CommitsRangeSize),
190
-		"--max-count="+strconv.Itoa(CommitsRangeSize), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
192
+		"--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat).RunInDirBytes(repo.Path)
191 193
 	if err != nil {
192 194
 		return nil, err
193 195
 	}
194 196
 	return repo.parsePrettyFormatLogToList(stdout)
195 197
 }
196 198
 
197
-func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, error) {
198
-	stdout, err := NewCommand("log", id.String(), "-100", "-i", "--grep="+keyword, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
199
+func (repo *Repository) searchCommits(id SHA1, keyword string) (*list.List, error) {
200
+	stdout, err := NewCommand("log", id.String(), "-100", "-i", "--grep="+keyword, prettyLogFormat).RunInDirBytes(repo.Path)
199 201
 	if err != nil {
200 202
 		return nil, err
201 203
 	}
@@ -210,19 +212,22 @@ func (repo *Repository) getFilesChanged(id1 string, id2 string) ([]string, error
210 212
 	return strings.Split(string(stdout), "\n"), nil
211 213
 }
212 214
 
215
+// FileCommitsCount return the number of files at a revison
213 216
 func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
214 217
 	return commitsCount(repo.Path, revision, file)
215 218
 }
216 219
 
220
+// CommitsByFileAndRange return the commits accroding revison file and the page
217 221
 func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
218 222
 	stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*50),
219
-		"--max-count="+strconv.Itoa(CommitsRangeSize), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path)
223
+		"--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat, "--", file).RunInDirBytes(repo.Path)
220 224
 	if err != nil {
221 225
 		return nil, err
222 226
 	}
223 227
 	return repo.parsePrettyFormatLogToList(stdout)
224 228
 }
225 229
 
230
+// FilesCountBetween return the number of files changed between two commits
226 231
 func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) {
227 232
 	stdout, err := NewCommand("diff", "--name-only", startCommitID+"..."+endCommitID).RunInDir(repo.Path)
228 233
 	if err != nil {
@@ -266,6 +271,7 @@ func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List
266 271
 	return l, nil
267 272
 }
268 273
 
274
+// CommitsBetweenIDs return commits between twoe commits
269 275
 func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, error) {
270 276
 	lastCommit, err := repo.GetCommit(last)
271 277
 	if err != nil {
@@ -278,12 +284,13 @@ func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, erro
278 284
 	return repo.CommitsBetween(lastCommit, beforeCommit)
279 285
 }
280 286
 
287
+// CommitsCountBetween return numbers of commits between two commits
281 288
 func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
282 289
 	return commitsCount(repo.Path, start+"..."+end, "")
283 290
 }
284 291
 
285
-// The limit is depth, not total number of returned commits.
286
-func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha1, current, limit int) error {
292
+// commitsBefore the limit is depth, not total number of returned commits.
293
+func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id SHA1, current, limit int) error {
287 294
 	// Reach the limit
288 295
 	if limit > 0 && current > limit {
289 296
 		return nil
@@ -342,12 +349,12 @@ func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha
342 349
 	return nil
343 350
 }
344 351
 
345
-func (repo *Repository) getCommitsBefore(id sha1) (*list.List, error) {
352
+func (repo *Repository) getCommitsBefore(id SHA1) (*list.List, error) {
346 353
 	l := list.New()
347 354
 	return l, repo.commitsBefore(l, nil, id, 1, 0)
348 355
 }
349 356
 
350
-func (repo *Repository) getCommitsBeforeLimit(id sha1, num int) (*list.List, error) {
357
+func (repo *Repository) getCommitsBeforeLimit(id SHA1, num int) (*list.List, error) {
351 358
 	l := list.New()
352 359
 	return l, repo.commitsBefore(l, nil, id, 1, num)
353 360
 }

+ 2 - 0
vendor/code.gitea.io/git/repo_hook.go

@@ -4,10 +4,12 @@
4 4
 
5 5
 package git
6 6
 
7
+// GetHook get one hook accroding the name on a repository
7 8
 func (repo *Repository) GetHook(name string) (*Hook, error) {
8 9
 	return GetHook(repo.Path, name)
9 10
 }
10 11
 
12
+// Hooks get all the hooks on the repository
11 13
 func (repo *Repository) Hooks() ([]*Hook, error) {
12 14
 	return ListHooks(repo.Path)
13 15
 }

+ 9 - 4
vendor/code.gitea.io/git/repo_object.go

@@ -4,11 +4,16 @@
4 4
 
5 5
 package git
6 6
 
7
+// ObjectType git object type
7 8
 type ObjectType string
8 9
 
9 10
 const (
10
-	OBJECT_COMMIT ObjectType = "commit"
11
-	OBJECT_TREE   ObjectType = "tree"
12
-	OBJECT_BLOB   ObjectType = "blob"
13
-	OBJECT_TAG    ObjectType = "tag"
11
+	// ObjectCommit commit object type
12
+	ObjectCommit ObjectType = "commit"
13
+	// ObjectTree tree object type
14
+	ObjectTree ObjectType = "tree"
15
+	// ObjectBlob blob object type
16
+	ObjectBlob ObjectType = "blob"
17
+	// ObjectTag tag object type
18
+	ObjectTag ObjectType = "tag"
14 19
 )

+ 1 - 1
vendor/code.gitea.io/git/repo_pull.go

@@ -50,7 +50,7 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri
50 50
 		return nil, fmt.Errorf("GetMergeBase: %v", err)
51 51
 	}
52 52
 
53
-	logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
53
+	logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
54 54
 	if err != nil {
55 55
 		return nil, err
56 56
 	}

+ 8 - 5
vendor/code.gitea.io/git/repo_tag.go

@@ -10,23 +10,26 @@ import (
10 10
 	"github.com/mcuadros/go-version"
11 11
 )
12 12
 
13
-const TAG_PREFIX = "refs/tags/"
13
+// TagPrefix tags prefix path on the repository
14
+const TagPrefix = "refs/tags/"
14 15
 
15 16
 // IsTagExist returns true if given tag exists in the repository.
16 17
 func IsTagExist(repoPath, name string) bool {
17
-	return IsReferenceExist(repoPath, TAG_PREFIX+name)
18
+	return IsReferenceExist(repoPath, TagPrefix+name)
18 19
 }
19 20
 
21
+// IsTagExist returns true if given tag exists in the repository.
20 22
 func (repo *Repository) IsTagExist(name string) bool {
21 23
 	return IsTagExist(repo.Path, name)
22 24
 }
23 25
 
26
+// CreateTag create one tag in the repository
24 27
 func (repo *Repository) CreateTag(name, revision string) error {
25 28
 	_, err := NewCommand("tag", name, revision).RunInDir(repo.Path)
26 29
 	return err
27 30
 }
28 31
 
29
-func (repo *Repository) getTag(id sha1) (*Tag, error) {
32
+func (repo *Repository) getTag(id SHA1) (*Tag, error) {
30 33
 	t, ok := repo.tagCache.Get(id.String())
31 34
 	if ok {
32 35
 		log("Hit cache: %s", id)
@@ -41,11 +44,11 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) {
41 44
 	tp = strings.TrimSpace(tp)
42 45
 
43 46
 	// Tag is a commit.
44
-	if ObjectType(tp) == OBJECT_COMMIT {
47
+	if ObjectType(tp) == ObjectCommit {
45 48
 		tag := &Tag{
46 49
 			ID:     id,
47 50
 			Object: id,
48
-			Type:   string(OBJECT_COMMIT),
51
+			Type:   string(ObjectCommit),
49 52
 			repo:   repo,
50 53
 		}
51 54
 

+ 2 - 2
vendor/code.gitea.io/git/repo_tree.go

@@ -4,7 +4,7 @@
4 4
 
5 5
 package git
6 6
 
7
-func (repo *Repository) getTree(id sha1) (*Tree, error) {
7
+func (repo *Repository) getTree(id SHA1) (*Tree, error) {
8 8
 	treePath := filepathFromSHA1(repo.Path, id.String())
9 9
 	if isFile(treePath) {
10 10
 		_, err := NewCommand("ls-tree", id.String()).RunInDir(repo.Path)
@@ -16,7 +16,7 @@ func (repo *Repository) getTree(id sha1) (*Tree, error) {
16 16
 	return NewTree(repo, id), nil
17 17
 }
18 18
 
19
-// Find the tree object in the repository.
19
+// GetTree find the tree object in the repository.
20 20
 func (repo *Repository) GetTree(idStr string) (*Tree, error) {
21 21
 	id, err := NewIDFromString(idStr)
22 22
 	if err != nil {

+ 21 - 19
vendor/code.gitea.io/git/sha1.go

@@ -10,13 +10,15 @@ import (
10 10
 	"strings"
11 11
 )
12 12
 
13
-const EMPTY_SHA = "0000000000000000000000000000000000000000"
13
+// EmptySHA defines empty git SHA
14
+const EmptySHA = "0000000000000000000000000000000000000000"
14 15
 
15
-type sha1 [20]byte
16
+// SHA1 a git commit name
17
+type SHA1 [20]byte
16 18
 
17
-// Equal returns true if s has the same sha1 as caller.
18
-// Support 40-length-string, []byte, sha1.
19
-func (id sha1) Equal(s2 interface{}) bool {
19
+// Equal returns true if s has the same SHA1 as caller.
20
+// Support 40-length-string, []byte, SHA1.
21
+func (id SHA1) Equal(s2 interface{}) bool {
20 22
 	switch v := s2.(type) {
21 23
 	case string:
22 24
 		if len(v) != 40 {
@@ -32,7 +34,7 @@ func (id sha1) Equal(s2 interface{}) bool {
32 34
 				return false
33 35
 			}
34 36
 		}
35
-	case sha1:
37
+	case SHA1:
36 38
 		for i, v := range v {
37 39
 			if id[i] != v {
38 40
 				return false
@@ -45,42 +47,42 @@ func (id sha1) Equal(s2 interface{}) bool {
45 47
 }
46 48
 
47 49
 // String returns string (hex) representation of the Oid.
48
-func (s sha1) String() string {
50
+func (id SHA1) String() string {
49 51
 	result := make([]byte, 0, 40)
50 52
 	hexvalues := []byte("0123456789abcdef")
51 53
 	for i := 0; i < 20; i++ {
52
-		result = append(result, hexvalues[s[i]>>4])
53
-		result = append(result, hexvalues[s[i]&0xf])
54
+		result = append(result, hexvalues[id[i]>>4])
55
+		result = append(result, hexvalues[id[i]&0xf])
54 56
 	}
55 57
 	return string(result)
56 58
 }
57 59
 
58
-// MustID always creates a new sha1 from a [20]byte array with no validation of input.
59
-func MustID(b []byte) sha1 {
60
-	var id sha1
60
+// MustID always creates a new SHA1 from a [20]byte array with no validation of input.
61
+func MustID(b []byte) SHA1 {
62
+	var id SHA1
61 63
 	for i := 0; i < 20; i++ {
62 64
 		id[i] = b[i]
63 65
 	}
64 66
 	return id
65 67
 }
66 68
 
67
-// NewID creates a new sha1 from a [20]byte array.
68
-func NewID(b []byte) (sha1, error) {
69
+// NewID creates a new SHA1 from a [20]byte array.
70
+func NewID(b []byte) (SHA1, error) {
69 71
 	if len(b) != 20 {
70
-		return sha1{}, fmt.Errorf("Length must be 20: %v", b)
72
+		return SHA1{}, fmt.Errorf("Length must be 20: %v", b)
71 73
 	}
72 74
 	return MustID(b), nil
73 75
 }
74 76
 
75 77
 // MustIDFromString always creates a new sha from a ID with no validation of input.
76
-func MustIDFromString(s string) sha1 {
78
+func MustIDFromString(s string) SHA1 {
77 79
 	b, _ := hex.DecodeString(s)
78 80
 	return MustID(b)
79 81
 }
80 82
 
81
-// NewIDFromString creates a new sha1 from a ID string of length 40.
82
-func NewIDFromString(s string) (sha1, error) {
83
-	var id sha1
83
+// NewIDFromString creates a new SHA1 from a ID string of length 40.
84
+func NewIDFromString(s string) (SHA1, error) {
85
+	var id SHA1
84 86
 	s = strings.TrimSpace(s)
85 87
 	if len(s) != 40 {
86 88
 		return id, fmt.Errorf("Length must be 40: %s", s)

+ 3 - 2
vendor/code.gitea.io/git/submodule.go

@@ -6,6 +6,7 @@ package git
6 6
 
7 7
 import "strings"
8 8
 
9
+// SubModule submodule is a reference on git repository
9 10
 type SubModule struct {
10 11
 	Name string
11 12
 	URL  string
@@ -19,6 +20,7 @@ type SubModuleFile struct {
19 20
 	refID  string
20 21
 }
21 22
 
23
+// NewSubModuleFile create a new submodule file
22 24
 func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
23 25
 	return &SubModuleFile{
24 26
 		Commit: c,
@@ -64,9 +66,8 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
64 66
 		// fix problem with reverse proxy works only with local server
65 67
 		if strings.Contains(urlPrefix, url[i+1:j]) {
66 68
 			return urlPrefix + url[j+1:]
67
-		} else {
68
-			return "http://" + url[i+1:j] + "/" + url[j+1:]
69 69
 		}
70
+		return "http://" + url[i+1:j] + "/" + url[j+1:]
70 71
 	}
71 72
 
72 73
 	return url

+ 3 - 2
vendor/code.gitea.io/git/tag.go

@@ -9,14 +9,15 @@ import "bytes"
9 9
 // Tag represents a Git tag.
10 10
 type Tag struct {
11 11
 	Name    string
12
-	ID      sha1
12
+	ID      SHA1
13 13
 	repo    *Repository
14
-	Object  sha1 // The id of this commit object
14
+	Object  SHA1 // The id of this commit object
15 15
 	Type    string
16 16
 	Tagger  *Signature
17 17
 	Message string
18 18
 }
19 19
 
20
+// Commit return the commit of the tag reference
20 21
 func (tag *Tag) Commit() (*Commit, error) {
21 22
 	return tag.repo.getCommit(tag.Object)
22 23
 }

+ 15 - 13
vendor/code.gitea.io/git/tree.go

@@ -12,7 +12,7 @@ import (
12 12
 
13 13
 // Tree represents a flat directory listing.
14 14
 type Tree struct {
15
-	ID   sha1
15
+	ID   SHA1
16 16
 	repo *Repository
17 17
 
18 18
 	// parent tree
@@ -22,7 +22,8 @@ type Tree struct {
22 22
 	entriesParsed bool
23 23
 }
24 24
 
25
-func NewTree(repo *Repository, id sha1) *Tree {
25
+// NewTree create a new tree according the repository and commit id
26
+func NewTree(repo *Repository, id SHA1) *Tree {
26 27
 	return &Tree{
27 28
 		ID:   id,
28 29
 		repo: repo,
@@ -63,22 +64,22 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
63 64
 		step := 6
64 65
 		switch string(data[pos : pos+step]) {
65 66
 		case "100644":
66
-			entry.mode = ENTRY_MODE_BLOB
67
-			entry.Type = OBJECT_BLOB
67
+			entry.mode = EntryModeBlob
68
+			entry.Type = ObjectBlob
68 69
 		case "100755":
69
-			entry.mode = ENTRY_MODE_EXEC
70
-			entry.Type = OBJECT_BLOB
70
+			entry.mode = EntryModeExec
71
+			entry.Type = ObjectBlob
71 72
 		case "120000":
72
-			entry.mode = ENTRY_MODE_SYMLINK
73
-			entry.Type = OBJECT_BLOB
73
+			entry.mode = EntryModeSymlink
74
+			entry.Type = ObjectBlob
74 75
 		case "160000":
75
-			entry.mode = ENTRY_MODE_COMMIT
76
-			entry.Type = OBJECT_COMMIT
76
+			entry.mode = EntryModeCommit
77
+			entry.Type = ObjectCommit
77 78
 
78 79
 			step = 8
79 80
 		case "040000":
80
-			entry.mode = ENTRY_MODE_TREE
81
-			entry.Type = OBJECT_TREE
81
+			entry.mode = EntryModeTree
82
+			entry.Type = ObjectTree
82 83
 		default:
83 84
 			return nil, fmt.Errorf("unknown type: %v", string(data[pos:pos+step]))
84 85
 		}
@@ -90,7 +91,7 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
90 91
 			return nil, err
91 92
 		}
92 93
 		entry.ID = id
93
-		pos += step + 1 // Skip half of sha1.
94
+		pos += step + 1 // Skip half of SHA1.
94 95
 
95 96
 		step = bytes.IndexByte(data[pos:], '\n')
96 97
 
@@ -107,6 +108,7 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
107 108
 	return entries, nil
108 109
 }
109 110
 
111
+// SubTree get a sub tree by the sub dir path
110 112
 func (t *Tree) SubTree(rpath string) (*Tree, error) {
111 113
 	if len(rpath) == 0 {
112 114
 		return t, nil

+ 4 - 2
vendor/code.gitea.io/git/tree_blob.go

@@ -9,12 +9,13 @@ import (
9 9
 	"strings"
10 10
 )
11 11
 
12
+// GetTreeEntryByPath get the tree entries accroding the sub dir
12 13
 func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
13 14
 	if len(relpath) == 0 {
14 15
 		return &TreeEntry{
15 16
 			ID:   t.ID,
16
-			Type: OBJECT_TREE,
17
-			mode: ENTRY_MODE_TREE,
17
+			Type: ObjectTree,
18
+			mode: EntryModeTree,
18 19
 		}, nil
19 20
 	}
20 21
 
@@ -43,6 +44,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
43 44
 	return nil, ErrNotExist{"", relpath}
44 45
 }
45 46
 
47
+// GetBlobByPath get the blob object accroding the path
46 48
 func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) {
47 49
 	entry, err := t.GetTreeEntryByPath(relpath)
48 50
 	if err != nil {

+ 28 - 9
vendor/code.gitea.io/git/tree_entry.go

@@ -14,20 +14,27 @@ import (
14 14
 	"strings"
15 15
 )
16 16
 
17
+// EntryMode the type of the object in the git tree
17 18
 type EntryMode int
18 19
 
19 20
 // There are only a few file modes in Git. They look like unix file modes, but they can only be
20 21
 // one of these.
21 22
 const (
22
-	ENTRY_MODE_BLOB    EntryMode = 0100644
23
-	ENTRY_MODE_EXEC    EntryMode = 0100755
24
-	ENTRY_MODE_SYMLINK EntryMode = 0120000
25
-	ENTRY_MODE_COMMIT  EntryMode = 0160000
26
-	ENTRY_MODE_TREE    EntryMode = 0040000
23
+	// EntryModeBlob
24
+	EntryModeBlob EntryMode = 0100644
25
+	// EntryModeExec
26
+	EntryModeExec EntryMode = 0100755
27
+	// EntryModeSymlink
28
+	EntryModeSymlink EntryMode = 0120000
29
+	// EntryModeCommit
30
+	EntryModeCommit EntryMode = 0160000
31
+	// EntryModeTree
32
+	EntryModeTree EntryMode = 0040000
27 33
 )
28 34
 
35
+// TreeEntry the leaf in the git tree
29 36
 type TreeEntry struct {
30
-	ID   sha1
37
+	ID   SHA1
31 38
 	Type ObjectType
32 39
 
33 40
 	mode EntryMode
@@ -41,10 +48,12 @@ type TreeEntry struct {
41 48
 	sized bool
42 49
 }
43 50
 
51
+// Name returns the name of the entry
44 52
 func (te *TreeEntry) Name() string {
45 53
 	return te.name
46 54
 }
47 55
 
56
+// Size returns the size of the entry
48 57
 func (te *TreeEntry) Size() int64 {
49 58
 	if te.IsDir() {
50 59
 		return 0
@@ -62,14 +71,22 @@ func (te *TreeEntry) Size() int64 {
62 71
 	return te.size
63 72
 }
64 73
 
74
+// IsSubModule if the entry is a sub module
65 75
 func (te *TreeEntry) IsSubModule() bool {
66
-	return te.mode == ENTRY_MODE_COMMIT
76
+	return te.mode == EntryModeCommit
67 77
 }
68 78
 
79
+// IsDir if the entry is a sub dir
69 80
 func (te *TreeEntry) IsDir() bool {
70
-	return te.mode == ENTRY_MODE_TREE
81
+	return te.mode == EntryModeTree
71 82
 }
72 83
 
84
+// IsLink if the entry is a symlink
85
+func (te *TreeEntry) IsLink() bool {
86
+	return te.mode == EntryModeSymlink
87
+}
88
+
89
+// Blob retrun the blob object the entry
73 90
 func (te *TreeEntry) Blob() *Blob {
74 91
 	return &Blob{
75 92
 		repo:      te.ptree.repo,
@@ -77,6 +94,7 @@ func (te *TreeEntry) Blob() *Blob {
77 94
 	}
78 95
 }
79 96
 
97
+// Entries a list of entry
80 98
 type Entries []*TreeEntry
81 99
 
82 100
 var sorter = []func(t1, t2 *TreeEntry) bool{
@@ -105,6 +123,7 @@ func (tes Entries) Less(i, j int) bool {
105 123
 	return sorter[k](t1, t2)
106 124
 }
107 125
 
126
+// Sort sort the list of entry
108 127
 func (tes Entries) Sort() {
109 128
 	sort.Sort(tes)
110 129
 }
@@ -167,7 +186,7 @@ func (tes Entries) GetCommitsInfoWithCustomConcurrency(commit *Commit, treePath
167 186
 		// However when taskChan is full, code will block and wait any running goroutines to finish.
168 187
 		taskChan <- true
169 188
 
170
-		if tes[i].Type != OBJECT_COMMIT {
189
+		if tes[i].Type != ObjectCommit {
171 190
 			go func(i int) {
172 191
 				cinfo := commitInfo{entryName: tes[i].Name()}
173 192
 				c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name()))

+ 13 - 10
vendor/code.gitea.io/git/utils.go

@@ -12,26 +12,28 @@ import (
12 12
 	"sync"
13 13
 )
14 14
 
15
-// objectCache provides thread-safe cache opeations.
16
-type objectCache struct {
15
+// ObjectCache provides thread-safe cache opeations.
16
+type ObjectCache struct {
17 17
 	lock  sync.RWMutex
18 18
 	cache map[string]interface{}
19 19
 }
20 20
 
21
-func newObjectCache() *objectCache {
22
-	return &objectCache{
21
+func newObjectCache() *ObjectCache {
22
+	return &ObjectCache{
23 23
 		cache: make(map[string]interface{}, 10),
24 24
 	}
25 25
 }
26 26
 
27
-func (oc *objectCache) Set(id string, obj interface{}) {
27
+// Set add obj to cache
28
+func (oc *ObjectCache) Set(id string, obj interface{}) {
28 29
 	oc.lock.Lock()
29 30
 	defer oc.lock.Unlock()
30 31
 
31 32
 	oc.cache[id] = obj
32 33
 }
33 34
 
34
-func (oc *objectCache) Get(id string) (interface{}, bool) {
35
+// Get get cached obj by id
36
+func (oc *ObjectCache) Get(id string) (interface{}, bool) {
35 37
 	oc.lock.RLock()
36 38
 	defer oc.lock.RUnlock()
37 39
 
@@ -80,13 +82,14 @@ func filepathFromSHA1(rootdir, sha1 string) string {
80 82
 	return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:])
81 83
 }
82 84
 
85
+// RefEndName return the end name of a ref name
83 86
 func RefEndName(refStr string) string {
84
-	if strings.HasPrefix(refStr, BRANCH_PREFIX) {
85
-		return refStr[len(BRANCH_PREFIX):]
87
+	if strings.HasPrefix(refStr, BranchPrefix) {
88
+		return refStr[len(BranchPrefix):]
86 89
 	}
87 90
 
88
-	if strings.HasPrefix(refStr, TAG_PREFIX) {
89
-		return refStr[len(TAG_PREFIX):]
91
+	if strings.HasPrefix(refStr, TagPrefix) {
92
+		return refStr[len(TagPrefix):]
90 93
 	}
91 94
 
92 95
 	return refStr

+ 3 - 3
vendor/vendor.json

@@ -3,10 +3,10 @@
3 3
 	"ignore": "test",
4 4
 	"package": [
5 5
 		{
6
-			"checksumSHA1": "X4WaxEtgFkM4VHg6TcNk2xkrqCI=",
6
+			"checksumSHA1": "OWuUWQ8sWC8n+eTQttx+3vfES8g=",
7 7
 			"path": "code.gitea.io/git",
8
-			"revision": "0807b517283977be34f0ff5510b21e676fc1527c",
9
-			"revisionTime": "2016-11-13T14:20:52Z"
8
+			"revision": "634abd6a61c350a95f6b146c3a5fc323282608ae",
9
+			"revisionTime": "2016-12-22T08:49:21Z"
10 10
 		},
11 11
 		{
12 12
 			"checksumSHA1": "KZEYDYPzVc12f0770V++kIHhfa0=",