@@ -115,7 +115,25 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
115115 var changes internal.RepoChanges
116116 var err error
117117 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 {
119137 line = strings .TrimSpace (line )
120138 if len (line ) == 0 {
121139 continue
@@ -163,17 +181,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
163181 default :
164182 log .Warn ("Unrecognized status: %c (line=%s)" , status , line )
165183 }
166- }
167184
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+ }
173193 }
174194
175- objectFormat := git .ObjectFormatFromName (repo .ObjectFormatName )
195+ if len (updatedFilenames ) > 0 {
196+ if err := updateChanges (); err != nil {
197+ return nil , err
198+ }
199+ }
176200
177- changes .Updates , err = parseGitLsTreeOutput (objectFormat , lsTreeStdout )
178201 return & changes , err
179202}
0 commit comments