FS#28248 - Mercurial 2.1 Might Return With Non-Zero Exit Codes After Pulling And Break The Build Process

Attached to Project: Pacman
Opened by Bastien Dejean (baskerville) - Saturday, 04 February 2012, 16:15 GMT
Last edited by Dan McGee (toofishes) - Saturday, 11 February 2012, 21:53 GMT
Task Type Bug Report
Category makepkg
Status Closed
Assigned To Allan McRae (Allan)
Dave Reisner (falconindy)
Architecture All
Severity Medium
Priority Normal
Reported Version 4.0.1
Due in Version 4.0.2
Due Date Undecided
Percent Complete 100%
Votes 13
Private No

Details

The current version of mercurial returns with non-zero exit codes on numerous occasions. This behavior is intended [1].

For example, the following command will return with an exit code of 1 if there's nothing to pull:
hg pull

When it happens, the build process fails since the makepkg script traps non-zero exit codes:
trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR

A patch suggested[2] on the Main Arch Linux Mailing List is attached.

[1] http://selenic.com/hg/rev/093b75c7b44b
[2] http://mailman.archlinux.org/pipermail/arch-general/2012-February/024835.html
This task depends upon

Closed by  Dan McGee (toofishes)
Saturday, 11 February 2012, 21:53 GMT
Reason for closing:  Fixed
Additional comments about closing:  commit 9b1ab3d76713d99
Comment by Jakob Matthes (jakobm) - Saturday, 04 February 2012, 16:28 GMT
Why do you want a "|| true" for "hg update"?
> Returns 0 on success, 1 if there are unresolved files.
(man hg, description of update)
Comment by Anton Shestakov (engored) - Saturday, 04 February 2012, 16:33 GMT
Isn't there any way to trap exit code 1 only? "hg pull" returns 255 if something went really wrong, so doing "|| true" to that would be wrong, I think.
Comment by Bastien Dejean (baskerville) - Saturday, 04 February 2012, 17:08 GMT
@jakobm:
Yes you're right, I went too far.

@engored:
Maybe capturing "hg pull"'s stderr might tell if something really went wrong?
Comment by Bastien Dejean (baskerville) - Saturday, 04 February 2012, 17:28 GMT
An improved patch is attached.
Comment by Anton Shestakov (engored) - Saturday, 04 February 2012, 18:26 GMT
I was actually thinking about something like this (works for me).
Comment by Stefan Husmann (stefanhusmann) - Saturday, 04 February 2012, 19:43 GMT
Both patches do not solve the problem for me.
Comment by Bastien Dejean (baskerville) - Saturday, 04 February 2012, 20:01 GMT
@engored:
Yes, it seems cleaner.

@stefanhusmann:
You also have to take care of the problem in the PKGBUILD itself...
Comment by Stefan Husmann (stefanhusmann) - Saturday, 04 February 2012, 20:14 GMT
I see. Now makepkg_mercurial2.diff works for me, will test the other one later.
Comment by Stefan Husmann (stefanhusmann) - Saturday, 04 February 2012, 20:18 GMT
Also the second patch sems to work.
Comment by Jonathan (Da_Coynul) - Saturday, 04 February 2012, 23:12 GMT
Shouldn't the patch be against pacman/src/pacman-4.0.1/scripts/makepkg.sh.in?

Anyway, I can also confirm this works when combined with modification of the PKGBUILD.

Thanks guys!
Comment by Allan McRae (Allan) - Tuesday, 07 February 2012, 04:37 GMT
So... this is the upstream change:

- Returns 0 on success, 1 if an update had unresolved files.
+ Returns 0 on success, 1 if no changes found or an update had
+ unresolved files.

It seems there is no straightforward way to distinguish genuine failure for lack of changes.
Comment by alessandro (alelinuxbsd) - Tuesday, 07 February 2012, 10:19 GMT
I have a similar problem https://aur.archlinux.org/packages.php?ID=42421 i think caused from mercurial.
An user said that his problem was resolved simply downgrading mercurial to version 2.0.2, so i wonder if at this moment we are looking in the wrong direction for fix this issue.
Because at that point would be a mistake due to the mercurial package and nothing else.
I have this issue on the 64 bit system and don't on the 32 bit system where i tried few day before, but i haven't checked, at that time, which version of mercurial was present on the 32 bit system.
For the moment i haven't tried the solution proposal from that user because i never downgrade a package so i should understand how proceed ( https://wiki.archlinux.org/index.php/Downgrade_packages ) and since at that moment I have no compelling need to use that package if possible i prefer a clean fix.
On summary i hope that the problem resides in the package mercurial.

Comment by Bastien Dejean (baskerville) - Tuesday, 07 February 2012, 11:09 GMT
@Allan:
Yes I think this commit should be reverted.
Would it be conceivable to provide a patched mercurial package?
Alas, some AUR maintainers have already started to change their PKGBUILD (they removed the underscore in the hg variables and append the 'test $? ...' to the 'hg pull' lines) and the irony is: it breaks the build process with mercurial 2.0.2!
Comment by alessandro (alelinuxbsd) - Tuesday, 07 February 2012, 15:13 GMT
Update.
I fixed my problem with the downgrade of mercurial suggested from one user.
This leaves me lean even more than before that this is a bug in the program and that the above solutions proposed (a modification of the makepkg and PKGBUILD on program that use mercurial) are a workaround to that problem but the solution lies in fixing bugs in the program mercurial.
Comment by Dave Reisner (falconindy) - Tuesday, 07 February 2012, 15:20 GMT
No, the real fix is in makepkg. We really shouldn't care about program exit statuses unless we explicitly catch them. I've already started a branch that does this, but it's 4.1 material, assuming I can convince Dan and Allan that this is a Good Idea™.
Comment by Bastien Dejean (baskerville) - Tuesday, 07 February 2012, 16:51 GMT
Agreed.
If you go in that direction, maybe you could remove the automatic actions performed when _foorepo and _fooroot are defined: I find counterintuitive the fact that a PKGBUILD with an empty 'build' function doesn't do nothing?
Comment by Allan McRae (Allan) - Tuesday, 07 February 2012, 19:21 GMT
The problem here is that we can no longer catch the situation where there is a failure updating an hg repo as mercurial returns the same when the update succeeds but with no file changes. So even if we catch the error explicitly, it ma not be an error...
Comment by portix (portix) - Wednesday, 08 February 2012, 00:08 GMT
@Allan
If hg pull is called without -u it will only return 1 if there are no file changes, if hg pull fails it returns 255. Only hg pull -u also returns 1 if the update fails.
Comment by Allan McRae (Allan) - Wednesday, 08 February 2012, 00:28 GMT
So... if I understand hg correctly (big assumption!), this patch should do what we want.

Basically, run "hg pull" and check the return status:
0 - run "hg update"
1 - do nothing
all others - error exit.
   hg.patch (0.6 KiB)
Comment by Sean Zimmermann (szim90) - Thursday, 09 February 2012, 23:14 GMT
Since this requires all mercurial package build scripts be changed, should a separate task be opened against abs to change the PKGBUILD-hg.proto file?
Comment by Vladimir (_v_l) - Sunday, 12 February 2012, 03:44 GMT
Surprize!
http://selenic.com/hg/rev/a3dcc59054ca
so 'pull' will again return 0.

Loading...