Re: [PATCH v2 1/2] commit: allow editing the commit message even in shared repos
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 7, 2016, 21:35 UTC
- Message-ID
- <xmqq8u413wee.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20160107124117.GA14421@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 30 quoted lines
> On Wed, Jan 06, 2016 at 02:09:43PM +0100, Johannes Schindelin wrote:
>
>> It was pointed out by Yaroslav Halchenko that the file containing the
>> commit message is writable only by the owner, which means that we have
>> to rewrite it from scratch in a shared repository.
>> [...]
>> diff --git a/wrapper.c b/wrapper.c
>> index b43d437..29a45d2 100644
>> --- a/wrapper.c
>> +++ b/wrapper.c
>> @@ -391,6 +391,19 @@ FILE *xfdopen(int fd, const char *mode)
>> return stream;
>> }
>>
>> +FILE *fopen_for_writing(const char *path)
>> +{
>> + FILE *ret = fopen(path, "w");
>> +
>> + if (!ret && errno == EPERM) {
>> + if (!unlink(path))
>> + ret = fopen(path, "w");
>> + else
>> + errno = EPERM;
>> + }
>> + return ret;
>> +}
>
> Thanks, this looks good to me. Having seen the implementation, it really
> is just "try harder to fopen()". I guess calling it "fopen_me_harder()"
> would be too obscure. :)obscure or you meant some other obsxxxx? fopen_harder() does not sound too bad, but fopen_for_writing() is OK to me.
And its use in this patch looks sensible.
Thanks.