Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 6b8bab3

Browse files
committed
Add repo_blob
This adds a new repo.GetBlob(id) method for use by gitea.
1 parent 31f4b8e commit 6b8bab3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

repo_blob.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
func (repo *Repository) getBlob(id SHA1) (*Blob, error) {
8+
if _, err := NewCommand("cat-file", "-p", id.String()).RunInDir(repo.Path); err != nil {
9+
return nil, ErrNotExist{id.String(), ""}
10+
}
11+
12+
return &Blob{
13+
repo: repo,
14+
TreeEntry: &TreeEntry{
15+
ID: id,
16+
ptree: &Tree{
17+
repo: repo,
18+
},
19+
},
20+
}, nil
21+
}
22+
23+
// GetBlob finds the blob object in the repository.
24+
func (repo *Repository) GetBlob(idStr string) (*Blob, error) {
25+
id, err := NewIDFromString(idStr)
26+
if err != nil {
27+
return nil, err
28+
}
29+
return repo.getBlob(id)
30+
}

0 commit comments

Comments
 (0)