Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH v2 1/2] commit: allow editing the commit message even in shared repos

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:07:39

Jeff King [off-list ref] writes:
On Wed, Jan 06, 2016 at 02:09:43PM +0100, Johannes Schindelin wrote:
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help