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