Skip to content

Commit

Permalink
Fix index too many file names bug (#31903) (#31953)
Browse files Browse the repository at this point in the history
Try to fix #31884
Fix #28584 
Backport #31903
  • Loading branch information
lunny authored Sep 3, 2024
1 parent 6f5748c commit d3b0bc2
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions modules/indexer/code/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,25 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
var changes internal.RepoChanges
var err error
updatedFilenames := make([]string, 0, 10)
for _, line := range strings.Split(stdout, "\n") {
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)

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(objectFormat, 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)
if len(line) == 0 {
continue
Expand Down Expand Up @@ -163,17 +181,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
default:
log.Warn("Unrecognized status: %c (line=%s)", status, line)
}
}

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 nil, err
// According to https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation#more-information
// the command line length should less than 8191 characters, assume filepath is 256, then 8191/256 = 31, so we use 30
if len(updatedFilenames) >= 30 {
if err := updateChanges(); err != nil {
return nil, err
}
updatedFilenames = updatedFilenames[0:0]
}
}

objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
if len(updatedFilenames) > 0 {
if err := updateChanges(); err != nil {
return nil, err
}
}

changes.Updates, err = parseGitLsTreeOutput(objectFormat, lsTreeStdout)
return &changes, err
}

0 comments on commit d3b0bc2

Please sign in to comment.