@@ -42,9 +42,9 @@ const DefaultLocale = "C"
4242
4343// Command represents a command with its subcommands or arguments.
4444type Command struct {
45- prog string
46- args []string
47- parentContext context.Context
45+ prog string
46+ args []string
47+ // parentContext context.Context
4848 globalArgsLength int
4949 brokenArgs []string
5050}
@@ -82,7 +82,7 @@ func (c *Command) LogString() string {
8282
8383// NewCommand creates and returns a new Git Command based on given command and arguments.
8484// Each argument should be safe to be trusted. User-provided arguments should be passed to AddDynamicArguments instead.
85- func NewCommand (ctx context. Context , args ... internal.CmdArg ) * Command {
85+ func NewCommand (args ... internal.CmdArg ) * Command {
8686 // Make an explicit copy of globalCommandArgs, otherwise append might overwrite it
8787 cargs := make ([]string , 0 , len (globalCommandArgs )+ len (args ))
8888 for _ , arg := range globalCommandArgs {
@@ -92,32 +92,32 @@ func NewCommand(ctx context.Context, args ...internal.CmdArg) *Command {
9292 cargs = append (cargs , string (arg ))
9393 }
9494 return & Command {
95- prog : GitExecutable ,
96- args : cargs ,
97- parentContext : ctx ,
95+ prog : GitExecutable ,
96+ args : cargs ,
97+ // parentContext: ctx,
9898 globalArgsLength : len (globalCommandArgs ),
9999 }
100100}
101101
102102// NewCommandContextNoGlobals creates and returns a new Git Command based on given command and arguments only with the specify args and don't care global command args
103103// Each argument should be safe to be trusted. User-provided arguments should be passed to AddDynamicArguments instead.
104- func NewCommandContextNoGlobals (ctx context. Context , args ... internal.CmdArg ) * Command {
104+ func NewCommandContextNoGlobals (args ... internal.CmdArg ) * Command {
105105 cargs := make ([]string , 0 , len (args ))
106106 for _ , arg := range args {
107107 cargs = append (cargs , string (arg ))
108108 }
109109 return & Command {
110- prog : GitExecutable ,
111- args : cargs ,
112- parentContext : ctx ,
110+ prog : GitExecutable ,
111+ args : cargs ,
112+ // parentContext: ctx,
113113 }
114114}
115115
116- // SetParentContext sets the parent context for this command
117- func (c * Command ) SetParentContext (ctx context.Context ) * Command {
118- c .parentContext = ctx
119- return c
120- }
116+ // // SetParentContext sets the parent context for this command
117+ // func (c *Command) SetParentContext(ctx context.Context) *Command {
118+ // c.parentContext = ctx
119+ // return c
120+ // }
121121
122122// isSafeArgumentValue checks if the argument is safe to be used as a value (not an option)
123123func isSafeArgumentValue (s string ) bool {
@@ -277,11 +277,11 @@ func CommonCmdServEnvs() []string {
277277var ErrBrokenCommand = errors .New ("git command is broken" )
278278
279279// Run runs the command with the RunOpts
280- func (c * Command ) Run (opts * RunOpts ) error {
281- return c .run (1 , opts )
280+ func (c * Command ) Run (ctx context. Context , opts * RunOpts ) error {
281+ return c .run (ctx , 1 , opts )
282282}
283283
284- func (c * Command ) run (skip int , opts * RunOpts ) error {
284+ func (c * Command ) run (ctx context. Context , skip int , opts * RunOpts ) error {
285285 if len (c .brokenArgs ) != 0 {
286286 log .Error ("git command is broken: %s, broken args: %s" , c .LogString (), strings .Join (c .brokenArgs , " " ))
287287 return ErrBrokenCommand
@@ -305,19 +305,18 @@ func (c *Command) run(skip int, opts *RunOpts) error {
305305 desc := fmt .Sprintf ("git.Run(by:%s, repo:%s): %s" , callerInfo , logArgSanitize (opts .Dir ), cmdLogString )
306306 log .Debug ("git.Command: %s" , desc )
307307
308- _ , span := gtprof .GetTracer ().Start (c . parentContext , gtprof .TraceSpanGitRun )
308+ _ , span := gtprof .GetTracer ().Start (ctx , gtprof .TraceSpanGitRun )
309309 defer span .End ()
310310 span .SetAttributeString (gtprof .TraceAttrFuncCaller , callerInfo )
311311 span .SetAttributeString (gtprof .TraceAttrGitCommand , cmdLogString )
312312
313- var ctx context.Context
314313 var cancel context.CancelFunc
315314 var finished context.CancelFunc
316315
317316 if opts .UseContextTimeout {
318- ctx , cancel , finished = process .GetManager ().AddContext (c . parentContext , desc )
317+ ctx , cancel , finished = process .GetManager ().AddContext (ctx , desc )
319318 } else {
320- ctx , cancel , finished = process .GetManager ().AddContextTimeout (c . parentContext , timeout , desc )
319+ ctx , cancel , finished = process .GetManager ().AddContextTimeout (ctx , timeout , desc )
321320 }
322321 defer finished ()
323322
@@ -410,8 +409,8 @@ func IsErrorExitCode(err error, code int) bool {
410409}
411410
412411// RunStdString runs the command with options and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
413- func (c * Command ) RunStdString (opts * RunOpts ) (stdout , stderr string , runErr RunStdError ) {
414- stdoutBytes , stderrBytes , err := c .runStdBytes (opts )
412+ func (c * Command ) RunStdString (ctx context. Context , opts * RunOpts ) (stdout , stderr string , runErr RunStdError ) {
413+ stdoutBytes , stderrBytes , err := c .runStdBytes (ctx , opts )
415414 stdout = util .UnsafeBytesToString (stdoutBytes )
416415 stderr = util .UnsafeBytesToString (stderrBytes )
417416 if err != nil {
@@ -422,11 +421,11 @@ func (c *Command) RunStdString(opts *RunOpts) (stdout, stderr string, runErr Run
422421}
423422
424423// RunStdBytes runs the command with options and returns stdout/stderr as bytes. and store stderr to returned error (err combined with stderr).
425- func (c * Command ) RunStdBytes (opts * RunOpts ) (stdout , stderr []byte , runErr RunStdError ) {
426- return c .runStdBytes (opts )
424+ func (c * Command ) RunStdBytes (ctx context. Context , opts * RunOpts ) (stdout , stderr []byte , runErr RunStdError ) {
425+ return c .runStdBytes (ctx , opts )
427426}
428427
429- func (c * Command ) runStdBytes (opts * RunOpts ) (stdout , stderr []byte , runErr RunStdError ) {
428+ func (c * Command ) runStdBytes (ctx context. Context , opts * RunOpts ) (stdout , stderr []byte , runErr RunStdError ) {
430429 if opts == nil {
431430 opts = & RunOpts {}
432431 }
@@ -449,7 +448,7 @@ func (c *Command) runStdBytes(opts *RunOpts) (stdout, stderr []byte, runErr RunS
449448 PipelineFunc : opts .PipelineFunc ,
450449 }
451450
452- err := c .run (2 , newOpts )
451+ err := c .run (ctx , 2 , newOpts )
453452 stderr = stderrBuf .Bytes ()
454453 if err != nil {
455454 return nil , stderr , & runStdError {err : err , stderr : util .UnsafeBytesToString (stderr )}
0 commit comments