File tree Expand file tree Collapse file tree 1 file changed +26
-11
lines changed
Expand file tree Collapse file tree 1 file changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -110,17 +110,37 @@ const (
110110)
111111
112112var (
113- setupStatus sync.Once
114- statusFile * os.File
113+ _setupStatus sync.Once
114+ statusFile * os.File
115115)
116116
117- func (s status ) emitf (format string , args ... interface {}) {
118- setupStatus .Do (func () {
119- if * statusFdOpt > 0 {
117+ func setupStatus () {
118+ _setupStatus .Do (func () {
119+ if * statusFdOpt <= 0 {
120+ return
121+ }
122+
123+ const (
124+ unixStdout = 1
125+ unixStderr = 2
126+ )
127+
128+ // Even though Windows uses different numbers, we always equate 1/2 with
129+ // stdout/stderr because Git always passes `--status-fd=1`.
130+ switch * statusFdOpt {
131+ case unixStdout :
132+ statusFile = os .Stdout
133+ case unixStderr :
134+ statusFile = os .Stderr
135+ default :
120136 // TODO: debugging output if this fails
121137 statusFile = os .NewFile (uintptr (* statusFdOpt ), "status" )
122138 }
123139 })
140+ }
141+
142+ func (s status ) emitf (format string , args ... interface {}) {
143+ setupStatus ()
124144
125145 if statusFile == nil {
126146 return
@@ -133,12 +153,7 @@ func (s status) emitf(format string, args ...interface{}) {
133153}
134154
135155func (s status ) emit () {
136- setupStatus .Do (func () {
137- if * statusFdOpt > 0 {
138- // TODO: debugging output if this fails
139- statusFile = os .NewFile (uintptr (* statusFdOpt ), "status" )
140- }
141- })
156+ setupStatus ()
142157
143158 if statusFile == nil {
144159 return
You can’t perform that action at this time.
0 commit comments