-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git-Trees API. #4185
Git-Trees API. #4185
Changes from 6 commits
7c45a55
48338e1
a59c455
bf6c63d
7b4bcc4
99f0e54
ed04816
46905a3
45a60f1
623d021
37c34e0
7a950a2
6598e98
f658384
b92db71
59b1daa
5b9c8fe
d5ed153
897b865
eb7742b
6814c26
a26fd26
25c34d8
5fe2746
1b821d2
c53e546
5068374
8bb9520
0328acb
f74cad1
7cc0d40
9eb63b0
e85daf1
1b5ec15
48928cc
af5435f
59fdb8c
9905e9a
0b05cd0
d38aeda
72429b3
ec90e15
fca09a5
4318e91
ebcb8bc
df943b2
4ed80ae
60b4e64
0c402a8
7ef246f
b6c878d
f152851
691eb27
112ef3c
0304456
2fe11b7
6ac2094
b413dd7
72accef
667f119
42a2aad
740e3d6
5c7eeb7
549934b
f0ede64
adc13ad
8910c49
de08694
fcf365e
55e7e1d
a64c719
d0f5292
15064a3
d7c2fa9
5e2a1d4
3a05893
afe0379
d847a98
caf33a0
66f33b6
228826d
64d8e7a
58491da
82d441b
3e7e7f4
f055495
8e9d23d
dd4314b
974b34a
1e59f29
46e07e3
ef96951
9d177bb
29a20d9
b90c97a
981c638
bb0a40d
350aa83
8d0d9b6
63f15cc
0004af3
d587f36
b47751a
e46a55f
dcfb0bd
13b4eaf
f5869a4
1542444
50cfaa6
3f4c472
f8b14f2
d22f137
e925f52
194ed38
6e8b8e0
6e81f3d
59849af
bb267f2
eb826f1
a8182a3
83f7843
0cc3320
88e62d7
5eecb9a
9a8897f
41fc619
ccd33cf
aa2d183
fc8e16d
d9e8366
0f82261
e9dfce0
b5797da
f596178
b8529e2
afc156a
ff4d1ce
381d561
d28ab73
3aa4da0
d1ef32a
7ff1d1d
8b1276c
bf52578
2ae67fb
1a59c90
692c9ae
9fb741b
1f72e70
4335971
919b06d
8f39249
121cd6c
35f7eb4
1cef59e
5776bb4
2743b29
7aa43ea
5cf2e9f
fd39667
d05774a
da617fc
8fc2f72
e53276c
87e7522
cf56d46
257890c
012ea4a
7633d03
60aa671
9249c13
068217c
fadb78c
13dc611
24434b5
80da260
f69d36b
2542b66
f7ce2b8
0e29981
5b49d45
83fcc6f
af6ac62
966f02f
56c8314
c93f12c
43acff4
40015e7
cc2fd48
5a6daf7
5fadd11
46da812
92030cd
c012fd5
51623fc
2ab56e1
6cd41ec
b9bff47
72e7986
60de076
5ae50c6
e75fe1b
3a408b8
215b63b
3a6972c
9cd224c
bacbc57
b3a7c2c
1be1627
023d812
b7983c7
8bb93c6
eafcf90
edf9411
e0d57fa
6054ac8
7359948
41d70dc
df9b85b
4f21e0b
3197f73
25edcd9
9c51b78
0eac73a
b5c770f
0bd5f6f
dd76689
dc076df
7906976
74f03d3
89a1eb2
cb37bc1
5de1348
fd9ea48
154faf7
a74bb76
15e42cf
5563133
d805745
3af4c56
96e797e
092efad
95a419b
99fa5ee
a04069d
a7b3e41
8c7ad40
af99357
5355736
2a959b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 repo | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/git" | ||
"code.gitea.io/sdk/gitea" | ||
) | ||
|
||
func GetTree(ctx *context.APIContext) { | ||
sha := ctx.Params("sha") | ||
if len(sha) == 0 { | ||
ctx.Error(400, "sha not provided", nil) | ||
return | ||
} | ||
Tree := GetTreeBySHA(ctx, sha) | ||
if Tree != nil { | ||
ctx.JSON(200, Tree) | ||
} else { | ||
ctx.Error(400, "sha invalid", nil) | ||
} | ||
} | ||
|
||
func GetTreeBySHA(ctx *context.APIContext, sha string) *gitea.GitTreeResponse { | ||
GitTree, err := ctx.Repo.GitRepo.GetTree(sha) | ||
if err != nil || GitTree == nil{ | ||
return nil | ||
} | ||
tree := new(gitea.GitTreeResponse) | ||
RepoID := strings.TrimRight(setting.AppURL, "/") + "/api/v1/repos/" + ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name | ||
tree.SHA = GitTree.ID.String() | ||
tree.URL = RepoID + "/trees/" + tree.SHA | ||
var Entries git.Entries | ||
if ctx.QueryBool("recursive") { | ||
Entries, err = GitTree.ListEntriesRecursive() | ||
} else { | ||
Entries, err = GitTree.ListEntries() | ||
} | ||
if err != nil { | ||
return tree | ||
} | ||
RepoIDLen := len(RepoID) | ||
BlobURL := make([]byte, RepoIDLen + 47) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kasi-R could you please add a comment or variable describing where the magic number |
||
copy(BlobURL[:], RepoID) | ||
copy(BlobURL[RepoIDLen:], "/blobs/") | ||
TreeURL := make([]byte, RepoIDLen + 47) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above -- same here please. |
||
copy(TreeURL[:], RepoID) | ||
copy(TreeURL[RepoIDLen:], "/trees/") | ||
CopyPos := len(TreeURL) - 40 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar request here -- where is the |
||
|
||
if len(Entries) > 1000 { | ||
tree.Entries = make([]gitea.GitTreeEntry, 1000) | ||
} else { | ||
tree.Entries = make([]gitea.GitTreeEntry, len(Entries)) | ||
} | ||
for e := range Entries { | ||
if e > 1000 { | ||
tree.Truncated = true | ||
break | ||
} | ||
|
||
tree.Entries[e].Path = Entries[e].Name() | ||
tree.Entries[e].Mode = fmt.Sprintf("%06x", Entries[e].Mode()) | ||
tree.Entries[e].Type = string(Entries[e].Type) | ||
tree.Entries[e].Size = Entries[e].Size() | ||
tree.Entries[e].SHA = Entries[e].ID.String() | ||
|
||
if Entries[e].IsDir() { | ||
copy(TreeURL[CopyPos:], Entries[e].ID.String()) | ||
tree.Entries[e].URL = string(TreeURL[:]) | ||
} else { | ||
copy(BlobURL[CopyPos:], Entries[e].ID.String()) | ||
tree.Entries[e].URL = string(BlobURL[:]) | ||
} | ||
} | ||
return tree | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably use github compatible route (
/git/trees
)