Message:
Hello golan...@googlecode.com, r...@golang.org (cc:
golan...@googlegroups.com),
I'd like you to review this change to
http://go.googlecode.com/hg/
Description:
hgpatch: workaround for 'hg -q incoming' on windows.
Mercurial provides binary package and source package for windows.
If using binary package, hg.exe return 1 for exit code correctly.
But hg.bat does not return 1.
This is workaround to get exit code from batch file like following.
cmd /v:on /c hg -q incoming & exit !ERRORLEVEL!
This is working fine for both packages.
Please review this at http://codereview.appspot.com/4969065/
Affected files:
M src/cmd/hgpatch/main.go
Index: src/cmd/hgpatch/main.go
===================================================================
--- a/src/cmd/hgpatch/main.go
+++ b/src/cmd/hgpatch/main.go
@@ -15,6 +15,7 @@
"path/filepath"
"sort"
"strings"
+ "syscall"
)
var checkSync = flag.Bool("checksync", true, "check whether repository is
out of sync")
@@ -269,7 +270,17 @@
// hgIncoming returns true if hg sync will pull in changes.
func hgIncoming() bool {
// hg -q incoming exits 0 when there is nothing incoming, 1 otherwise.
- _, err := run([]string{"hg", "-q", "incoming"}, nil)
+ var err os.Error
+ if syscall.OS == "windows" {
+ // Workaround for mercurial batch file.
+ // Mercurial provides binary package and source package for windows.
+ // If using binary package, hg.exe return 1 for exit code correctly.
+ // But batch file does not return 1. Below is a workarond to get
+ // exit code.
+ _, err = run([]string{"cmd", "/v:on", "/c", "hg -q incoming &
exit !ERRORLEVEL!"}, nil)
+ } else {
+ _, err = run([]string{"hg", "-q", "incoming"}, nil)
+ }
return err == nil
}
Russ
> GetExitCodeProcess() can't exit code from batch file.
> To get it, hg.bat should call following at last line.
> exit /b 1
> or
> exit /b 0
If someone creates hg.bat, that always return exitcode=0, I am happy for
hgpatch to report success all the time. That is what they are asking
for, aren't they?
Alex
If someone creates hg.bat, that always return exitcode=0, I am happy for
hgpatch to report success all the time. That is what they are asking
for, aren't they?
> No, As long as that hg is batch file, GetExitCodeProcess() can't get
exit
> code.
I know nothing about batch programming, but didn't you say that batch
should do
exit /b 1
?
> That's not the point. :)
What is the point?
Alex
Can we tell people developing on Windows
that hg.bat is buggy and they should use hg.exe?
There are certainly plenty of other hg bugs we
tell people to work around (usually by upgrading
to a different hg).
Russ
All I am saying is, if program (batch or otherwise) wants to report an
error, it must do so in a conventional way = "exit code". If program
always returns exit_code=0, then it, obviously, do not care about
informing its callers about results of execution.
> However, golang have a lot of problems for windows user.
> If user want to use hg.exe, they must do:
https://groups.google.com/d/msg/golang-dev/rr-7N-UJk-E/paNKZQD1h68J
> And If user want to use hg installed from source code, we must wait
next
> release of mercurial.
I have no argument here. Please, fix it, if you know how.
Alex
On 2011/09/08 03:34:12, mattn wrote:
> Are you saying mercurial MUST provide hg.bat using "exit /b" ?
I have no argument here. Please, fix it, if you know how.
Again, it's not windows users.
It is windows-based developers of Go - people
contributing code to the Go project, not just using Go.
If you are developing Go on Windows you already
have to do special things like install the right mingw.
It doesn't seem too bad that you have to install
the right Mercurial too. We should update the page
that describes a Windows development setup to point
out that you should use the binary Mercurial distribution
and not setup.py, because of a setup.py bug.
Russ
> ... it will take many times until that windows user can use hgpatch
> correctly.
I do not use codereview on windows. So, perhaps, I am not the right
person to say NO. But I always try to fix the cause, not the
consequences.
Alex
Russ
If we fix hg.bat to use exit instead of exit /b,
then there is no workaround needed, right?
Russ
Thanks for that clarification.
It is all slowly coming back to me, like a bad dream.
This problem seems bigger than hgpatch now.
What can we do to fix syscall.StartProcess so that
we can get the exit code from batch files, like bar.bat
in your example? The MSDN docs say that CreateProcess
on a batchfile should say 'cmd /c bar' instead of 'bar'
but I don't see that happening in syscall/exec_windows.go.
Maybe that is related to the problem?
Russ
On Thu, Sep 8, 2011 at 14:22, mattn <matt...@gmail.com> wrote:
> No, GetExitCodeProcess() can't get exit code from batch file.
> If use "exit" (not "exit /b"), we can get exit code. (as your said)
> But this destroy cmd.exe window.Thanks for that clarification.
It is all slowly coming back to me, like a bad dream.
This problem seems bigger than hgpatch now.
What can we do to fix syscall.StartProcess so that
we can get the exit code from batch files, like bar.bat
in your example? The MSDN docs say that CreateProcess
on a batchfile should say 'cmd /c bar' instead of 'bar'
but I don't see that happening in syscall/exec_windows.go.
Maybe that is related to the problem?
Sorry, .cmd files showed up after I left. :-)
Russ
On 2011/09/08 03:32:39, rsc wrote:
> Can we tell people developing on Windows
> that hg.bat is buggy and they should use hg.exe?
SGTM
Peter
> Russ