From 05e42eaea14eec34f937e193815f9a4fb5f0b80a Mon Sep 17 00:00:00 2001 From: Ben Toews Date: Thu, 29 Nov 2018 13:00:08 -0700 Subject: [PATCH 1/2] stdout/stderr aren't fd 1/2 in Windows. Work around this --- status.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/status.go b/status.go index 2cc1186..3c5de4d 100644 --- a/status.go +++ b/status.go @@ -110,17 +110,28 @@ const ( ) var ( - setupStatus sync.Once - statusFile *os.File + _setupStatus sync.Once + statusFile *os.File ) -func (s status) emitf(format string, args ...interface{}) { - setupStatus.Do(func() { +func setupStatus() { + _setupStatus.Do(func() { if *statusFdOpt > 0 { - // TODO: debugging output if this fails - statusFile = os.NewFile(uintptr(*statusFdOpt), "status") + switch *statusFdOpt { + case 1: + statusFile = os.Stdout + case 2: + statusFile = os.Stderr + default: + // TODO: debugging output if this fails + statusFile = os.NewFile(uintptr(*statusFdOpt), "status") + } } }) +} + +func (s status) emitf(format string, args ...interface{}) { + setupStatus() if statusFile == nil { return @@ -133,12 +144,7 @@ func (s status) emitf(format string, args ...interface{}) { } func (s status) emit() { - setupStatus.Do(func() { - if *statusFdOpt > 0 { - // TODO: debugging output if this fails - statusFile = os.NewFile(uintptr(*statusFdOpt), "status") - } - }) + setupStatus() if statusFile == nil { return From efb92bc773f1c33fd3c2ce7d58354140f5e264c3 Mon Sep 17 00:00:00 2001 From: Ben Toews Date: Tue, 4 Dec 2018 08:34:09 -0700 Subject: [PATCH 2/2] constants for unixStdout and unixStderr --- status.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/status.go b/status.go index 3c5de4d..2b68638 100644 --- a/status.go +++ b/status.go @@ -116,16 +116,25 @@ var ( func setupStatus() { _setupStatus.Do(func() { - if *statusFdOpt > 0 { - switch *statusFdOpt { - case 1: - statusFile = os.Stdout - case 2: - statusFile = os.Stderr - default: - // TODO: debugging output if this fails - statusFile = os.NewFile(uintptr(*statusFdOpt), "status") - } + if *statusFdOpt <= 0 { + return + } + + const ( + unixStdout = 1 + unixStderr = 2 + ) + + // Even though Windows uses different numbers, we always equate 1/2 with + // stdout/stderr because Git always passes `--status-fd=1`. + switch *statusFdOpt { + case unixStdout: + statusFile = os.Stdout + case unixStderr: + statusFile = os.Stderr + default: + // TODO: debugging output if this fails + statusFile = os.NewFile(uintptr(*statusFdOpt), "status") } }) }