mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Fix index too many file names bug (#31903)
Try to fix #31884 Fix #28584
This commit is contained in:
		@@ -113,7 +113,24 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
 | 
				
			|||||||
	var changes internal.RepoChanges
 | 
						var changes internal.RepoChanges
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	updatedFilenames := make([]string, 0, 10)
 | 
						updatedFilenames := make([]string, 0, 10)
 | 
				
			||||||
	for _, line := range strings.Split(stdout, "\n") {
 | 
					
 | 
				
			||||||
 | 
						updateChanges := func() error {
 | 
				
			||||||
 | 
							cmd := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l").AddDynamicArguments(revision).
 | 
				
			||||||
 | 
								AddDashesAndList(updatedFilenames...)
 | 
				
			||||||
 | 
							lsTreeStdout, _, err := cmd.RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()})
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							updates, err1 := parseGitLsTreeOutput(lsTreeStdout)
 | 
				
			||||||
 | 
							if err1 != nil {
 | 
				
			||||||
 | 
								return err1
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							changes.Updates = append(changes.Updates, updates...)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						lines := strings.Split(stdout, "\n")
 | 
				
			||||||
 | 
						for _, line := range lines {
 | 
				
			||||||
		line = strings.TrimSpace(line)
 | 
							line = strings.TrimSpace(line)
 | 
				
			||||||
		if len(line) == 0 {
 | 
							if len(line) == 0 {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
@@ -161,15 +178,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
 | 
				
			|||||||
		default:
 | 
							default:
 | 
				
			||||||
			log.Warn("Unrecognized status: %c (line=%s)", status, line)
 | 
								log.Warn("Unrecognized status: %c (line=%s)", status, line)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cmd := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l").AddDynamicArguments(revision).
 | 
							// According to https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation#more-information
 | 
				
			||||||
		AddDashesAndList(updatedFilenames...)
 | 
							// the command line length should less than 8191 characters, assume filepath is 256, then 8191/256 = 31, so we use 30
 | 
				
			||||||
	lsTreeStdout, _, err := cmd.RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()})
 | 
							if len(updatedFilenames) >= 30 {
 | 
				
			||||||
	if err != nil {
 | 
								if err := updateChanges(); err != nil {
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								updatedFilenames = updatedFilenames[0:0]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(updatedFilenames) > 0 {
 | 
				
			||||||
 | 
							if err := updateChanges(); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	changes.Updates, err = parseGitLsTreeOutput(lsTreeStdout)
 | 
					 | 
				
			||||||
	return &changes, err
 | 
						return &changes, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user