[PATCH STABLE] transplant: handle non-empty patches doing nothing (issue2806)
Patrick Mézard
patrick at mezard.eu
Tue Jul 31 13:21:34 CDT 2012
Le 31/07/12 18:28, Mads Kiilerich a écrit :
> On 31/07/12 17:46, Patrick Mezard wrote:
>> # HG changeset patch
>> # User Patrick Mezard <patrick at mezard.eu>
>> # Date 1343749172 -7200
>> # Branch stable
>> # Node ID 3fc1bd37e77731208359259575ac6ed06726189b
>> # Parent 7d2967de2c04489f9ce64308eb39d8a55d66af7c
>> transplant: handle non-empty patches doing nothing (issue2806)
>>
>> If patch.patch() reports patched files when applying a changeset and the
>> following commit says nothing changed, transplant used to abort with a
>> RuntimeError, assuming something went wrong with patching.
>>
>> The mismatch is patch.patch() reports patched files, not changed ones.
>> It could be modified to report changed files but it means duplicating
>> work from status, may be expensive in the case of binary files, and is
>> probably not that useful at API level. For instance, if two patches are
>> applied on the working directory, the outcome may be nothing changed
>> while each call would have returned modified files. The caller would
>> have to call status() itself again.
>>
>> This patch fixes the issue by trusting patching code: if the patch
>> succeeded and commit reports nothing changed, then nothing changed,
>> patch() did not "dropped changes on the floor".
>>
>> diff --git a/hgext/transplant.py b/hgext/transplant.py
>> --- a/hgext/transplant.py
>> +++ b/hgext/transplant.py
>> @@ -263,9 +263,6 @@
>> files = set()
>> patch.patch(self.ui, repo, patchfile, files=files, eolmode=None)
>> files = list(files)
>> - if not files:
>> - self.ui.warn(_('%s: empty changeset') % revlog.hex(node))
>> - return None
>> except Exception, inst:
>> seriespath = os.path.join(self.path, 'series')
>> if os.path.exists(seriespath):
>> @@ -288,14 +285,8 @@
>> n = repo.commit(message, user, date, extra=extra, match=m,
>> editor=self.editor)
>> if not n:
>> - # Crash here to prevent an unclear crash later, in
>> - # transplants.write(). This can happen if patch.patch()
>> - # does nothing but claims success or if repo.status() fails
>> - # to report changes done by patch.patch(). These both
>> - # appear to be bugs in other parts of Mercurial, but dying
>> - # here, as soon as we can detect the problem, is preferable
>> - # to silently dropping changesets on the floor.
>> - raise RuntimeError('nothing committed after transplant')
>> + self.ui.warn(_('%s: empty changeset') % revlog.hex(node))
>
> You could consider adding \n when you are touching that line anyway. (That would add a new string for translation which would be a bit unfortunate now. It should however be feasible to fix the translations for all languages ;-) )
>
> It would be helpful if the message not only stated the fact but also described the consequences - e.g. "skipping empty changeset" or some rephrasing of "transplanted changeset became empty and is skipped".
This patch was just moving things around really, but I haven't noticed the missing EOL. I will resend with a followup patch tweaking the warning message.
--
Patrick Mézard
More information about the Mercurial-devel
mailing list