@@ -73,7 +73,7 @@ func ToPayloadCommit(repo *repo_model.Repository, c *git.Commit) *api.PayloadCom
73
73
}
74
74
75
75
// ToCommit convert a git.Commit to api.Commit
76
- func ToCommit (repo * repo_model.Repository , gitRepo * git.Repository , commit * git.Commit , userCache map [string ]* user_model.User ) (* api.Commit , error ) {
76
+ func ToCommit (repo * repo_model.Repository , gitRepo * git.Repository , commit * git.Commit , userCache map [string ]* user_model.User , stat bool ) (* api.Commit , error ) {
77
77
var apiAuthor , apiCommitter * api.User
78
78
79
79
// Retrieve author and committer information
@@ -133,28 +133,7 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
133
133
}
134
134
}
135
135
136
- // Retrieve files affected by the commit
137
- fileStatus , err := git .GetCommitFileStatus (gitRepo .Ctx , repo .RepoPath (), commit .ID .String ())
138
- if err != nil {
139
- return nil , err
140
- }
141
- affectedFileList := make ([]* api.CommitAffectedFiles , 0 , len (fileStatus .Added )+ len (fileStatus .Removed )+ len (fileStatus .Modified ))
142
- for _ , files := range [][]string {fileStatus .Added , fileStatus .Removed , fileStatus .Modified } {
143
- for _ , filename := range files {
144
- affectedFileList = append (affectedFileList , & api.CommitAffectedFiles {
145
- Filename : filename ,
146
- })
147
- }
148
- }
149
-
150
- diff , err := gitdiff .GetDiff (gitRepo , & gitdiff.DiffOptions {
151
- AfterCommitID : commit .ID .String (),
152
- })
153
- if err != nil {
154
- return nil , err
155
- }
156
-
157
- return & api.Commit {
136
+ res := & api.Commit {
158
137
CommitMeta : & api.CommitMeta {
159
138
URL : repo .APIURL () + "/git/commits/" + url .PathEscape (commit .ID .String ()),
160
139
SHA : commit .ID .String (),
@@ -188,11 +167,37 @@ func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.
188
167
Author : apiAuthor ,
189
168
Committer : apiCommitter ,
190
169
Parents : apiParents ,
191
- Files : affectedFileList ,
192
- Stats : & api.CommitStats {
170
+ }
171
+
172
+ // Retrieve files affected by the commit
173
+ if stat {
174
+ fileStatus , err := git .GetCommitFileStatus (gitRepo .Ctx , repo .RepoPath (), commit .ID .String ())
175
+ if err != nil {
176
+ return nil , err
177
+ }
178
+ affectedFileList := make ([]* api.CommitAffectedFiles , 0 , len (fileStatus .Added )+ len (fileStatus .Removed )+ len (fileStatus .Modified ))
179
+ for _ , files := range [][]string {fileStatus .Added , fileStatus .Removed , fileStatus .Modified } {
180
+ for _ , filename := range files {
181
+ affectedFileList = append (affectedFileList , & api.CommitAffectedFiles {
182
+ Filename : filename ,
183
+ })
184
+ }
185
+ }
186
+
187
+ diff , err := gitdiff .GetDiff (gitRepo , & gitdiff.DiffOptions {
188
+ AfterCommitID : commit .ID .String (),
189
+ })
190
+ if err != nil {
191
+ return nil , err
192
+ }
193
+
194
+ res .Files = affectedFileList
195
+ res .Stats = & api.CommitStats {
193
196
Total : diff .TotalAddition + diff .TotalDeletion ,
194
197
Additions : diff .TotalAddition ,
195
198
Deletions : diff .TotalDeletion ,
196
- },
197
- }, nil
199
+ }
200
+ }
201
+
202
+ return res , nil
198
203
}
0 commit comments