This is one of the Code walkthrough I wrote while exploring the Gitea codebase.
The Go exec package runs external commands and is improved by the Gitea modules/process package.
- Adds a set of functions (Exec, ExecDir etc.) that conveniently copy their arguments to the corresponding exec.Cmd field (Dir etc.).
- Adds a timeout (defaults to one minute).
- Adds the running process in a list of in-flight commands and removes it from the list after it completes.
- Returns stdout & stdin as strings instead of io.Writer
The list of processes can be obtained in a thread safe manner, to be displayed or to cancel a particular process.
The Gitea modules/git has an interface similar to Gitea modules/process (Run instead of Exec, RunInDir instead of ExecDir etc.) and:
- Appends stderr to error when execution fails
- Trace errors in the logs.
- Provides a default description for the in flight processes.
- Passes the parent environment and overrides LC_ALL with the Gitea settings.
- Allows for an optional pipelinefunction that must complete before the process returns (see how it is used to process git patch output for an example).
It does not share code with Gitea modules/process except for the process manager.