Refactor git command arguments and make all arguments to be safe to be used (#21535)

Follow #21464

Make all git command arguments strictly safe. Most changes are one-to-one replacing, keep all existing logic.
This commit is contained in:
wxiaoguang 2022-10-23 22:44:45 +08:00 committed by GitHub
parent 4eeea7b30e
commit dcd9fc7ee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 425 additions and 391 deletions

View file

@ -35,30 +35,33 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p
_ = stdoutWriter.Close()
}
args := make([]string, 0, 8+len(paths))
args = append(args, "log", "--name-status", "-c", "--format=commit%x00%H %P%x00", "--parents", "--no-renames", "-t", "-z", head, "--")
cmd := NewCommand(ctx)
cmd.AddArguments("log", "--name-status", "-c", "--format=commit%x00%H %P%x00", "--parents", "--no-renames", "-t", "-z").AddDynamicArguments(head)
var files []string
if len(paths) < 70 {
if treepath != "" {
args = append(args, treepath)
files = append(files, treepath)
for _, pth := range paths {
if pth != "" {
args = append(args, path.Join(treepath, pth))
files = append(files, path.Join(treepath, pth))
}
}
} else {
for _, pth := range paths {
if pth != "" {
args = append(args, pth)
files = append(files, pth)
}
}
}
} else if treepath != "" {
args = append(args, treepath)
files = append(files, treepath)
}
cmd.AddDashesAndList(files...)
go func() {
stderr := strings.Builder{}
err := NewCommand(ctx, args...).Run(&RunOpts{
err := cmd.Run(&RunOpts{
Dir: repository,
Stdout: stdoutWriter,
Stderr: &stderr,