@@ -222,8 +222,10 @@ type RunOpts struct {
222222
223223 PipelineFunc func (context.Context , context.CancelFunc ) error
224224
225- // for debugging purpose only, it means current function call depth, every caller should +1
226- LogDepth int
225+ // for debugging purpose only, it indicates how many stack frames to skip to find the caller info
226+ // it's mainly used to find the caller function name for logging
227+ // it should be 0 when the caller is the direct caller of Run/RunStdString/RunStdBytes
228+ LogSkip int
227229}
228230
229231func commonBaseEnvs () []string {
@@ -283,14 +285,14 @@ func (c *Command) Run(ctx context.Context, opts *RunOpts) error {
283285 }
284286
285287 cmdLogString := c .LogString ()
286- depth := 1 /* util */ + 1 /* this */ + opts .LogDepth /* parent */
287- callerInfo := util .CallerFuncName (depth )
288+ skip := 1 /* util */ + 1 /* this */ + opts .LogSkip /* parent */
289+ callerInfo := util .CallerFuncName (skip )
288290 if pos := strings .LastIndex (callerInfo , "/" ); pos >= 0 {
289291 callerInfo = callerInfo [pos + 1 :]
290292 }
291293 // these logs are for debugging purposes only, so no guarantee of correctness or stability
292294 desc := fmt .Sprintf ("git.Run(by:%s, repo:%s): %s" , callerInfo , logArgSanitize (opts .Dir ), cmdLogString )
293- log .DebugWithSkip (depth - 1 , "git.Command: %s" , desc )
295+ log .DebugWithSkip (opts . LogSkip + 1 , "git.Command: %s" , desc )
294296
295297 _ , span := gtprof .GetTracer ().Start (ctx , gtprof .TraceSpanGitRun )
296298 defer span .End ()
@@ -402,7 +404,7 @@ func (c *Command) RunStdString(ctx context.Context, opts *RunOpts) (stdout, stde
402404 if opts == nil {
403405 opts = & RunOpts {}
404406 }
405- opts .LogDepth += 1
407+ opts .LogSkip ++
406408 stdoutBytes , stderrBytes , err := c .RunStdBytes (ctx , opts )
407409 stdout = util .UnsafeBytesToString (stdoutBytes )
408410 stderr = util .UnsafeBytesToString (stderrBytes )
@@ -418,7 +420,7 @@ func (c *Command) RunStdBytes(ctx context.Context, opts *RunOpts) (stdout, stder
418420 if opts == nil {
419421 opts = & RunOpts {}
420422 }
421- opts .LogDepth += 1
423+ opts .LogSkip ++
422424 if opts .Stdout != nil || opts .Stderr != nil {
423425 // we must panic here, otherwise there would be bugs if developers set Stdin/Stderr by mistake, and it would be very difficult to debug
424426 panic ("stdout and stderr field must be nil when using RunStdBytes" )
@@ -436,7 +438,7 @@ func (c *Command) RunStdBytes(ctx context.Context, opts *RunOpts) (stdout, stder
436438 Stderr : stderrBuf ,
437439 Stdin : opts .Stdin ,
438440 PipelineFunc : opts .PipelineFunc ,
439- LogDepth : opts .LogDepth ,
441+ LogSkip : opts .LogSkip ,
440442 }
441443
442444 err := c .Run (ctx , newOpts )
0 commit comments