aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/code.gitea.io/git/tree.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2016-12-22 17:30:52 +0800
committerThomas Boerger <thomas@webhippie.de>2016-12-22 10:30:52 +0100
commit47a7529d9655e11471bbe39958222a13854a6133 (patch)
tree98e597255245e17d39a0062c3977fb8a510cf413 /vendor/code.gitea.io/git/tree.go
parent0c5c34d7ddaf31a6d8123dac36b221de61f5ff96 (diff)
downloadgitea-47a7529d9655e11471bbe39958222a13854a6133.tar.gz
gitea-47a7529d9655e11471bbe39958222a13854a6133.zip
update code.gitea.io/git (#450)
Diffstat (limited to 'vendor/code.gitea.io/git/tree.go')
-rw-r--r--vendor/code.gitea.io/git/tree.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/vendor/code.gitea.io/git/tree.go b/vendor/code.gitea.io/git/tree.go
index 8704282efd..05e7afd127 100644
--- a/vendor/code.gitea.io/git/tree.go
+++ b/vendor/code.gitea.io/git/tree.go
@@ -12,7 +12,7 @@ import (
// Tree represents a flat directory listing.
type Tree struct {
- ID sha1
+ ID SHA1
repo *Repository
// parent tree
@@ -22,7 +22,8 @@ type Tree struct {
entriesParsed bool
}
-func NewTree(repo *Repository, id sha1) *Tree {
+// NewTree create a new tree according the repository and commit id
+func NewTree(repo *Repository, id SHA1) *Tree {
return &Tree{
ID: id,
repo: repo,
@@ -63,22 +64,22 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
step := 6
switch string(data[pos : pos+step]) {
case "100644":
- entry.mode = ENTRY_MODE_BLOB
- entry.Type = OBJECT_BLOB
+ entry.mode = EntryModeBlob
+ entry.Type = ObjectBlob
case "100755":
- entry.mode = ENTRY_MODE_EXEC
- entry.Type = OBJECT_BLOB
+ entry.mode = EntryModeExec
+ entry.Type = ObjectBlob
case "120000":
- entry.mode = ENTRY_MODE_SYMLINK
- entry.Type = OBJECT_BLOB
+ entry.mode = EntryModeSymlink
+ entry.Type = ObjectBlob
case "160000":
- entry.mode = ENTRY_MODE_COMMIT
- entry.Type = OBJECT_COMMIT
+ entry.mode = EntryModeCommit
+ entry.Type = ObjectCommit
step = 8
case "040000":
- entry.mode = ENTRY_MODE_TREE
- entry.Type = OBJECT_TREE
+ entry.mode = EntryModeTree
+ entry.Type = ObjectTree
default:
return nil, fmt.Errorf("unknown type: %v", string(data[pos:pos+step]))
}
@@ -90,7 +91,7 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
return nil, err
}
entry.ID = id
- pos += step + 1 // Skip half of sha1.
+ pos += step + 1 // Skip half of SHA1.
step = bytes.IndexByte(data[pos:], '\n')
@@ -107,6 +108,7 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
return entries, nil
}
+// SubTree get a sub tree by the sub dir path
func (t *Tree) SubTree(rpath string) (*Tree, error) {
if len(rpath) == 0 {
return t, nil