aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorRichard Mahn <richmahn@users.noreply.github.com>2019-06-29 16:51:10 -0400
committertechknowlogick <techknowlogick@gitea.io>2019-06-29 16:51:10 -0400
commitcd96dee9822c8b744526ba862fd8b5ec0e2c30ff (patch)
treed7bbf2f2b7adf80b17f3ab3971ae49bae7b010c4 /modules/git
parent738285a4aac5df2e60f4038aa79be3e9fe921bdb (diff)
downloadgitea-cd96dee9822c8b744526ba862fd8b5ec0e2c30ff.tar.gz
gitea-cd96dee9822c8b744526ba862fd8b5ec0e2c30ff.zip
Fixes #7292 - API File Contents bug (#7301)
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/blob.go13
-rw-r--r--modules/git/repo_object.go17
2 files changed, 30 insertions, 0 deletions
diff --git a/modules/git/blob.go b/modules/git/blob.go
index 73ac89dfdf..68147673a3 100644
--- a/modules/git/blob.go
+++ b/modules/git/blob.go
@@ -37,6 +37,19 @@ func (b *Blob) Name() string {
return b.name
}
+// GetBlobContent Gets the content of the blob as raw text
+func (b *Blob) GetBlobContent() (string, error) {
+ dataRc, err := b.DataAsync()
+ if err != nil {
+ return "", err
+ }
+ defer dataRc.Close()
+ buf := make([]byte, 1024)
+ n, _ := dataRc.Read(buf)
+ buf = buf[:n]
+ return string(buf), nil
+}
+
// GetBlobContentBase64 Reads the content of the blob with a base64 encode and returns the encoded string
func (b *Blob) GetBlobContentBase64() (string, error) {
dataRc, err := b.DataAsync()
diff --git a/modules/git/repo_object.go b/modules/git/repo_object.go
index 67060e30b0..d4d638a743 100644
--- a/modules/git/repo_object.go
+++ b/modules/git/repo_object.go
@@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2019 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.
@@ -22,6 +23,8 @@ const (
ObjectBlob ObjectType = "blob"
// ObjectTag tag object type
ObjectTag ObjectType = "tag"
+ // ObjectBranch branch object type
+ ObjectBranch ObjectType = "branch"
)
// HashObject takes a reader and returns SHA1 hash for that reader
@@ -44,3 +47,17 @@ func (repo *Repository) hashObject(reader io.Reader) (string, error) {
}
return strings.TrimSpace(stdout.String()), nil
}
+
+// GetRefType gets the type of the ref based on the string
+func (repo *Repository) GetRefType(ref string) ObjectType {
+ if repo.IsTagExist(ref) {
+ return ObjectTag
+ } else if repo.IsBranchExist(ref) {
+ return ObjectBranch
+ } else if repo.IsCommitExist(ref) {
+ return ObjectCommit
+ } else if _, err := repo.GetBlob(ref); err == nil {
+ return ObjectBlob
+ }
+ return ObjectType("invalid")
+}