Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions modules/indexer/code/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ 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") {
lines := strings.Split(stdout, "\n")
for i, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
continue
Expand Down Expand Up @@ -161,15 +162,25 @@ 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 (i%30 == 0 || i == len(lines)-1) && len(updatedFilenames) > 0 {
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
}

updates, err1 := parseGitLsTreeOutput(lsTreeStdout)
if err1 != nil {
return nil, err1
}
changes.Updates = append(changes.Updates, updates...)
updatedFilenames = updatedFilenames[0:0]
}
}

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