This repository has been archived on 2019-08-27. You can view files and clone it, but cannot push or open issues or pull requests.
git/repo_blob.go
Peter Hoffmann d945eda535 Blob api (#132)
* Add repo_blob

This adds a new Repository.GetBlob(id) method for use by gitea.

* This is a follow-up for PR #121 to implement blob_api including full test coverage

Signed-off-by: Berengar W. Lehr <Berengar.Lehr@kompetenztest.de>
2018-11-11 09:54:02 +02:00

31 lines
706 B
Go

// 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.
package git
func (repo *Repository) getBlob(id SHA1) (*Blob, error) {
if _, err := NewCommand("cat-file", "-p", id.String()).RunInDir(repo.Path); err != nil {
return nil, ErrNotExist{id.String(), ""}
}
return &Blob{
repo: repo,
TreeEntry: &TreeEntry{
ID: id,
ptree: &Tree{
repo: repo,
},
},
}, nil
}
// GetBlob finds the blob object in the repository.
func (repo *Repository) GetBlob(idStr string) (*Blob, error) {
id, err := NewIDFromString(idStr)
if err != nil {
return nil, err
}
return repo.getBlob(id)
}