Re: receive.denyNonNonFastForwards not denying force update

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: receive.denyNonNonFastForwards not denying force update

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:54:32

Junio C Hamano [off-list ref] writes:
Modulo the above "you might want to turn the call to warn() to
another helper that can be used from elsewhere", this patch looks
perfect to me.
And that "modulo" is fairly simple if we wanted to go that route.

 attr.c            | 2 +-
 dir.c             | 2 +-
 git-compat-util.h | 3 +++
 wrapper.c         | 7 ++++++-
 4 files changed, 11 insertions(+), 3 deletions(-)
diff --git c/attr.c w/attr.c
index cab01b8..f12c83f 100644
--- c/attr.c
+++ w/attr.c
@@ -354,7 +354,7 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
 
 	if (!fp) {
 		if (errno != ENOENT)
-			warning(_("unable to access '%s': %s"), path, strerror(errno));
+			warn_on_inaccessible(path);
 		return NULL;
 	}
 	res = xcalloc(1, sizeof(*res));
diff --git c/dir.c w/dir.c
index ea74048..4868339 100644
--- c/dir.c
+++ w/dir.c
@@ -398,7 +398,7 @@ int add_excludes_from_file_to_list(const char *fname,
 	fd = open(fname, O_RDONLY);
 	if (fd < 0 || fstat(fd, &st) < 0) {
 		if (errno != ENOENT)
-			warning(_("unable to access '%s': %s"), fname, strerror(errno));
+			warn_on_inaccessible(fname);
 		if (0 <= fd)
 			close(fd);
 		if (!check_index ||
diff --git c/git-compat-util.h w/git-compat-util.h
index 5a520e2..000042d 100644
--- c/git-compat-util.h
+++ w/git-compat-util.h
@@ -607,6 +607,9 @@ int remove_or_warn(unsigned int mode, const char *path);
 /* Call access(2), but warn for any error besides ENOENT. */
 int access_or_warn(const char *path, int mode);
 
+/* Warn on an inaccessible file that ought to be accessible */
+void warn_on_inaccessible(const char *path);
+
 /* Get the passwd entry for the UID of the current process. */
 struct passwd *xgetpwuid_self(void);
 
diff --git c/wrapper.c w/wrapper.c
index b40c7e7..68739aa 100644
--- c/wrapper.c
+++ w/wrapper.c
@@ -403,11 +403,16 @@ int remove_or_warn(unsigned int mode, const char *file)
 	return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
 }
 
+void warn_on_inaccessible(const char *path)
+{
+	warning(_("unable to access '%s': %s"), path, strerror(errno));
+}
+
 int access_or_warn(const char *path, int mode)
 {
 	int ret = access(path, mode);
 	if (ret && errno != ENOENT)
-		warning(_("unable to access '%s': %s"), path, strerror(errno));
+		warn_on_inaccessible(path);
 	return ret;
 }
 

Re: receive.denyNonNonFastForwards not denying force update

From: Jeff King <hidden>
Date: 2016-06-15 22:54:32

On Tue, Aug 21, 2012 at 02:52:02PM -0700, Junio C Hamano wrote:
Junio C Hamano [off-list ref] writes:
quoted
Modulo the above "you might want to turn the call to warn() to
another helper that can be used from elsewhere", this patch looks
perfect to me.
And that "modulo" is fairly simple if we wanted to go that route.

 attr.c            | 2 +-
 dir.c             | 2 +-
 git-compat-util.h | 3 +++
 wrapper.c         | 7 ++++++-
 4 files changed, 11 insertions(+), 3 deletions(-)
Yeah, that looks fine to me if you want to squash it in.

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