diff options
Diffstat (limited to 'vendor/code.gitea.io')
-rw-r--r-- | vendor/code.gitea.io/git/commit.go | 52 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/repo_commit.go | 3 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/submodule.go | 16 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/tree.go | 22 |
4 files changed, 84 insertions, 9 deletions
diff --git a/vendor/code.gitea.io/git/commit.go b/vendor/code.gitea.io/git/commit.go index 5e8c91d303..227df09b7d 100644 --- a/vendor/code.gitea.io/git/commit.go +++ b/vendor/code.gitea.io/git/commit.go @@ -1,4 +1,5 @@ // Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2018 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -9,6 +10,7 @@ import ( "bytes" "container/list" "fmt" + "io" "net/http" "strconv" "strings" @@ -279,6 +281,56 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) { return nil, nil } +// CommitFileStatus represents status of files in a commit. +type CommitFileStatus struct { + Added []string + Removed []string + Modified []string +} + +// NewCommitFileStatus creates a CommitFileStatus +func NewCommitFileStatus() *CommitFileStatus { + return &CommitFileStatus{ + []string{}, []string{}, []string{}, + } +} + +// GetCommitFileStatus returns file status of commit in given repository. +func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) { + stdout, w := io.Pipe() + done := make(chan struct{}) + fileStatus := NewCommitFileStatus() + go func() { + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + fields := strings.Fields(scanner.Text()) + if len(fields) < 2 { + continue + } + + switch fields[0][0] { + case 'A': + fileStatus.Added = append(fileStatus.Added, fields[1]) + case 'D': + fileStatus.Removed = append(fileStatus.Removed, fields[1]) + case 'M': + fileStatus.Modified = append(fileStatus.Modified, fields[1]) + } + } + done <- struct{}{} + }() + + stderr := new(bytes.Buffer) + err := NewCommand("show", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr) + w.Close() // Close writer to exit parsing goroutine + if err != nil { + return nil, concatenateError(err, stderr.String()) + } + + <-done + return fileStatus, nil +} + // GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository. func GetFullCommitID(repoPath, shortID string) (string, error) { if len(shortID) >= 40 { diff --git a/vendor/code.gitea.io/git/repo_commit.go b/vendor/code.gitea.io/git/repo_commit.go index d5cab8f873..484568585f 100644 --- a/vendor/code.gitea.io/git/repo_commit.go +++ b/vendor/code.gitea.io/git/repo_commit.go @@ -140,6 +140,9 @@ func (repo *Repository) GetCommit(commitID string) (*Commit, error) { var err error commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path) if err != nil { + if strings.Contains(err.Error(), "unknown revision or path") { + return nil, ErrNotExist{commitID, ""} + } return nil, err } } diff --git a/vendor/code.gitea.io/git/submodule.go b/vendor/code.gitea.io/git/submodule.go index a0fe7b4a56..294df3986a 100644 --- a/vendor/code.gitea.io/git/submodule.go +++ b/vendor/code.gitea.io/git/submodule.go @@ -29,13 +29,12 @@ func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile { } } -// RefURL guesses and returns reference URL. -func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { - if sf.refURL == "" { +func getRefURL(refURL, urlPrefix, parentPath string) string { + if refURL == "" { return "" } - url := strings.TrimSuffix(sf.refURL, ".git") + url := strings.TrimSuffix(refURL, ".git") // git://xxx/user/repo if strings.HasPrefix(url, "git://") { @@ -67,12 +66,21 @@ func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { if strings.Contains(urlPrefix, url[i+1:j]) { return urlPrefix + url[j+1:] } + if strings.HasPrefix(url, "ssh://") || strings.HasPrefix(url, "git+ssh://") { + k := strings.Index(url[j+1:], "/") + return "http://" + url[i+1:j] + "/" + url[j+1:][k+1:] + } return "http://" + url[i+1:j] + "/" + url[j+1:] } return url } +// RefURL guesses and returns reference URL. +func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { + return getRefURL(sf.refURL, urlPrefix, parentPath) +} + // RefID returns reference ID. func (sf *SubModuleFile) RefID() string { return sf.refID diff --git a/vendor/code.gitea.io/git/tree.go b/vendor/code.gitea.io/git/tree.go index b67bf55840..b65fe19409 100644 --- a/vendor/code.gitea.io/git/tree.go +++ b/vendor/code.gitea.io/git/tree.go @@ -18,6 +18,9 @@ type Tree struct { entries Entries entriesParsed bool + + entriesRecursive Entries + entriesRecursiveParsed bool } // NewTree create a new tree according the repository and commit id @@ -67,20 +70,29 @@ func (t *Tree) ListEntries() (Entries, error) { if err != nil { return nil, err } + t.entries, err = parseTreeEntries(stdout, t) + if err == nil { + t.entriesParsed = true + } + return t.entries, err } // ListEntriesRecursive returns all entries of current tree recursively including all subtrees func (t *Tree) ListEntriesRecursive() (Entries, error) { - if t.entriesParsed { - return t.entries, nil + if t.entriesRecursiveParsed { + return t.entriesRecursive, nil } stdout, err := NewCommand("ls-tree", "-t", "-r", t.ID.String()).RunInDirBytes(t.repo.Path) - if err != nil { return nil, err } - t.entries, err = parseTreeEntries(stdout, t) - return t.entries, err + + t.entriesRecursive, err = parseTreeEntries(stdout, t) + if err == nil { + t.entriesRecursiveParsed = true + } + + return t.entriesRecursive, err } |