@@ -115,7 +115,25 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
115
115
var changes internal.RepoChanges
116
116
var err error
117
117
updatedFilenames := make ([]string , 0 , 10 )
118
- for _ , line := range strings .Split (stdout , "\n " ) {
118
+ objectFormat := git .ObjectFormatFromName (repo .ObjectFormatName )
119
+
120
+ updateChanges := func () error {
121
+ cmd := git .NewCommand (ctx , "ls-tree" , "--full-tree" , "-l" ).AddDynamicArguments (revision ).
122
+ AddDashesAndList (updatedFilenames ... )
123
+ lsTreeStdout , _ , err := cmd .RunStdBytes (& git.RunOpts {Dir : repo .RepoPath ()})
124
+ if err != nil {
125
+ return err
126
+ }
127
+
128
+ updates , err1 := parseGitLsTreeOutput (objectFormat , lsTreeStdout )
129
+ if err1 != nil {
130
+ return err1
131
+ }
132
+ changes .Updates = append (changes .Updates , updates ... )
133
+ return nil
134
+ }
135
+ lines := strings .Split (stdout , "\n " )
136
+ for _ , line := range lines {
119
137
line = strings .TrimSpace (line )
120
138
if len (line ) == 0 {
121
139
continue
@@ -163,17 +181,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
163
181
default :
164
182
log .Warn ("Unrecognized status: %c (line=%s)" , status , line )
165
183
}
166
- }
167
184
168
- cmd := git .NewCommand (ctx , "ls-tree" , "--full-tree" , "-l" ).AddDynamicArguments (revision ).
169
- AddDashesAndList (updatedFilenames ... )
170
- lsTreeStdout , _ , err := cmd .RunStdBytes (& git.RunOpts {Dir : repo .RepoPath ()})
171
- if err != nil {
172
- return nil , err
185
+ // According to https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation#more-information
186
+ // the command line length should less than 8191 characters, assume filepath is 256, then 8191/256 = 31, so we use 30
187
+ if len (updatedFilenames ) >= 30 {
188
+ if err := updateChanges (); err != nil {
189
+ return nil , err
190
+ }
191
+ updatedFilenames = updatedFilenames [0 :0 ]
192
+ }
173
193
}
174
194
175
- objectFormat := git .ObjectFormatFromName (repo .ObjectFormatName )
195
+ if len (updatedFilenames ) > 0 {
196
+ if err := updateChanges (); err != nil {
197
+ return nil , err
198
+ }
199
+ }
176
200
177
- changes .Updates , err = parseGitLsTreeOutput (objectFormat , lsTreeStdout )
178
201
return & changes , err
179
202
}
0 commit comments