Thread (34 messages) 34 messages, 6 authors, 2019-05-29

Re: [PATCH v2 1/7] run-command: add preliminary support for multiple hooks

From: Johannes Schindelin <hidden>
Date: 2019-05-17 20:31:12

Hi Hannes,

On Thu, 16 May 2019, Johannes Sixt wrote:
Am 16.05.19 um 00:44 schrieb brian m. carlson:
quoted
On Tue, May 14, 2019 at 05:12:39PM +0200, Johannes Schindelin wrote:
quoted
On Tue, 14 May 2019, brian m. carlson wrote:
quoted
+/*
+ * Return 1 if a hook exists at path (which may be modified) using access(2)
+ * with check (which should be F_OK or X_OK), 0 otherwise. If strip is true,
+ * additionally consider the same filename but with STRIP_EXTENSION added.
+ * If check is X_OK, warn if the hook exists but is not executable.
+ */
+static int has_hook(struct strbuf *path, int strip, int check)
+{
+	if (access(path->buf, check) < 0) {
+		int err = errno;
+
+		if (strip) {
+#ifdef STRIP_EXTENSION
+			strbuf_addstr(path, STRIP_EXTENSION);
+			if (access(path->buf, check) >= 0)
+				return 1;
+			if (errno == EACCES)
+				err = errno;
+#endif
+		}
How about simply guarding the entire `if()`? It is a bit unusual to guard
*only* the inside block ;-)
I can make that change.
But then we'll have an unused argument in some build configurations.
That's a valid point.

Thanks,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help