@@ -113,7 +113,24 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
113113 var changes internal.RepoChanges
114114 var err error
115115 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 {
117134 line = strings .TrimSpace (line )
118135 if len (line ) == 0 {
119136 continue
@@ -161,15 +178,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
161178 default :
162179 log .Warn ("Unrecognized status: %c (line=%s)" , status , line )
163180 }
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+ }
164190 }
165191
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+ }
171196 }
172197
173- changes .Updates , err = parseGitLsTreeOutput (lsTreeStdout )
174198 return & changes , err
175199}
0 commit comments