mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 13:50:39 +00:00
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:
parent
4eeea7b30e
commit
dcd9fc7ee8
71 changed files with 425 additions and 391 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue