[PATCH 2 of 2 STABLE] merge: improve error detection and reporting

Greg Ward greg-hg at gerg.ca
Tue May 4 15:15:31 CDT 2010


On Mon, May 3, 2010 at 5:00 PM, Matt Mackall <mpm at selenic.com> wrote:
>> merge: improve error detection and reporting.
>> - make hg exit with non-zero status when branch has 1 or >2 heads
>> - tweak the error messages for those cases
>> - add explicit detection of merging current changeset with itself
>> - rewrite messages for attempting to merge with ancestor or descendant
>>   of current changeset
>
> This could probably be a few separate changes for clarity.

OK, I'll split it up and resend.  And shoehorn my tests into an existing script.

>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -2225,19 +2225,20 @@
>>          branch = repo.changectx(None).branch()
>>          bheads = repo.branchheads(branch)
>>          if len(bheads) > 2:
>> -            ui.warn(_("abort: branch '%s' has %d heads - "
>> -                      "please merge with an explicit rev\n")
>> -                    % (branch, len(bheads)))
>> -            ui.status(_("(run 'hg heads .' to see heads)\n"))
>> -            return False
>> +            raise util.Abort(_(
>> +                'branch \'%s\' has %d heads -- '
>> +                'please merge with explicit rev\n'
>> +                '(run "hg heads %s" to see all branch heads)')
>> +                % (branch, len(bheads), branch))
>
> a) Why is the warn changing to an abort? Is this a workaround for the
> -caller- failing to propagate an error code?

But this is a top-level function in commands.py -- I thought they were
supposed to return the process status, i.e. 0 for success and non-zero
for failure.  False == 0, so a command that returns False is claiming
success.  Right now the only top-level function in commands.py that
returns a boolean is merge().

> b) Why is the quoting changing?

Just trying follow BasicCodingStyle.  (I noticed other error messages
that use double quotes when recommending the command to run.)

>>              msg = _('there is nothing to merge')
>>              if parent != repo.lookup(repo[None].branch()):
>>                  msg = _('%s - use "hg update" instead') % msg
>> diff --git a/mercurial/merge.py b/mercurial/merge.py
>> --- a/mercurial/merge.py
>> +++ b/mercurial/merge.py
>> @@ -408,7 +408,7 @@
>>
>>  def update(repo, node, branchmerge, force, partial):
>>      """
>> -    Perform a merge between the working directory and the given node
>> +    Perform a merge between the working directory and the given node.
>
> Unrelated change..?

Well, err, yeah, I suppose so.  But it is a string-only change to a
merge-related function, so I thought it worth squeezing in. I'll undo
it if you wish.

Greg


More information about the Mercurial-devel mailing list