transport-helper: avoid dependency on thread-utils.h
PATCH 1/1 transport-helper: avoid dependency on thread-utils.h
Since the transport-helper does not use recursive mutexes or ask the number of cores, it does not require any declarations from the thread-utils lib. Removing the unnecessary #include avoids false positives from "make CHECK_HEADER_DEPENDENCIES=1".
---
The #include directive in question was added in 7851b1e60 (remote-fd/ext: finishing touches after code review, 2010-11-17), at the same times as the necessary #include for <pthread.h>. This patch seems to work for me, but I wouldn't be surprised if to be missing something.
transport-helper.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
transport-helper.c +0 -1
@@ -11,7 +11,6 @@#ifndef NO_PTHREADS #include <pthread.h> -#include "thread-utils.h" #endif static int debug;
Signature · 1 line
1.7.2.4
Quoted 4 lines · Jonathan Nieder
Since the transport-helper does not use recursive mutexes or ask the number of cores, it does not require any declarations from the thread-utils lib. Removing the unnecessary #include avoids false positives from "make CHECK_HEADER_DEPENDENCIES=1".
Sorry, I was slow and took me some time to realize what is going on.
Isn't it more like "Makefile does not say transport-helper.o depends on thread-utils.h, but transport-helper.c does include it"? IOW, it not a false positive; perhaps a real but an unnecessary positive.
Quoted 3 lines
The #include directive in question was added in
7851b1e60(remote-fd/ext: finishing touches after code review, 2010-11-17), at the same times as the necessary #include for <pthread.h>.
I think the whole four-line block was cut & paste from other places that use the threading, namely grep.c and pack-objects.c.
I wonder if it is better to do something like this instead. This way, we can later add more things that threaded part of the system would need to thread-utils.h inside "ifndef NO_PTHREADS" and they will automatically get included by all the threaders.
builtin/grep.c | 4 ---- builtin/pack-objects.c | 4 ---- thread-utils.h | 4 ++++ transport-helper.c | 4 ---- 4 files changed, 4 insertions(+), 12 deletions(-)
builtin/grep.c +0 -4
@@ -17,11 +17,7 @@#include "grep.h" #include "quote.h" #include "dir.h" - -#ifndef NO_PTHREADS -#include <pthread.h> #include "thread-utils.h" -#endif static char const *const grep_usage[] = {"git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]" ,
builtin/pack-objects.c +0 -4
@@ -16,11 +16,7 @@#include "list-objects.h" #include "progress.h" #include "refs.h" - -#ifndef NO_PTHREADS -#include <pthread.h> #include "thread-utils.h" -#endif static const char pack_usage[] ="git pack-objects [ -q | --progress | --all-progress ]\n"
thread-utils.h +4 -0
@@ -1,7 +1,11 @@#ifndef THREAD_COMPAT_H #define THREAD_COMPAT_H +#ifndef NO_PTHREADS +#include <pthread.h> +extern int online_cpus (void );extern int init_recursive_mutex (pthread_mutex_t *); +#endif #endif /* THREAD_COMPAT_H */
transport-helper.c +0 -4
@@ -8,11 +8,7 @@#include "quote.h" #include "remote.h" #include "string-list.h" - -#ifndef NO_PTHREADS -#include <pthread.h> #include "thread-utils.h" -#endif static int debug;
Quoted 1 line · Junio C Hamano
I wonder if it is better to do something like this instead.
Yes, I think so. How about this?
Jonathan Nieder (1):
Makefile: transport-helper uses thread-utils.h
Junio C Hamano (1):
simplify inclusion of pthread.h
Makefile | 3 +-- builtin/grep.c | 4 ---- builtin/pack-objects.c | 4 ---- thread-utils.h | 4 ++++ transport-helper.c | 4 ---- 5 files changed, 5 insertions(+), 14 deletions(-)
Signature · 1 line
1.7.2.4
PATCH 1/2 simplify inclusion of pthread.h
In v1.7.1.1~56^2 (Thread-safe xmalloc and xrealloc needs a recursive mutex, 2010-04-08), the thread-utils header started using pthread_mutex_t, so callers, which generally had been using
#ifndef NO_PTHREADS #include "thread-utils.h" #include <pthread.h> #endif
before, were changed to include <pthread.h> first. It is simpler to let thread-utils.h take care of the whole matter. This way, we can later add more things that the threaded part of the system would need to thread-utils.h inside "ifndef NO_PTHREADS" and they will automatically get included by all headers.
--- builtin/grep.c | 4 ---- builtin/pack-objects.c | 4 ---- thread-utils.h | 4 ++++ transport-helper.c | 4 ---- 4 files changed, 4 insertions(+), 12 deletions(-)
builtin/grep.c +0 -4
@@ -17,11 +17,7 @@#include "grep.h" #include "quote.h" #include "dir.h" - -#ifndef NO_PTHREADS -#include <pthread.h> #include "thread-utils.h" -#endif static char const *const grep_usage[] = {"git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]" ,
builtin/pack-objects.c +0 -4
@@ -16,11 +16,7 @@#include "list-objects.h" #include "progress.h" #include "refs.h" - -#ifndef NO_PTHREADS -#include <pthread.h> #include "thread-utils.h" -#endif static const char pack_usage[] ="git pack-objects [ -q | --progress | --all-progress ]\n"
thread-utils.h +4 -0
@@ -1,7 +1,11 @@#ifndef THREAD_COMPAT_H #define THREAD_COMPAT_H +#ifndef NO_PTHREADS +#include <pthread.h> +extern int online_cpus (void );extern int init_recursive_mutex (pthread_mutex_t *); +#endif #endif /* THREAD_COMPAT_H */
transport-helper.c +0 -4
@@ -8,11 +8,7 @@#include "quote.h" #include "remote.h" #include "string-list.h" - -#ifndef NO_PTHREADS -#include <pthread.h> #include "thread-utils.h" -#endif static int debug;
Signature · 1 line
1.7.2.4
Re: [PATCH 1/2] simplify inclusion of pthread.h
Quoted 1 line · Jonathan Nieder
Signed-off-by Jonathan Nieder <[email protected]>
This one is of course
From: Junio C Hamano <[email protected]>
Often enough I remind myself to include the pseudo-header but when the rapid cutting-and-pasting time comes it is easy to forget. :/
PATCH 2/2 Makefile: transport-helper uses thread-utils.h
In reply to Jonathan Niedertransport-helper.o gained a dependency on thread-utils.h in 7851b1e (remote-fd/ext: finishing touches after code review, 2010-11-17).
--- Makefile | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
Makefile +1 -2
@@ -1937,13 +1937,12 @@ builtin/branch.o builtin/checkout.o builtin/clone.o builtin/reset.o branch.o tra builtin/bundle.o bundle.o transport.o: bundle.h builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h -builtin/grep.o: thread-utils.h +builtin/grep.o builtin/pack-objects.o transport-helper.o: thread-utils.h builtin/send-pack.o transport.o: send-pack.h builtin/log.o builtin/shortlog.o: shortlog.h builtin/prune.o builtin/reflog.o reachable.o: reachable.h builtin/commit.o builtin/revert.o wt-status.o: wt-status.h builtin/tar-tree.o archive-tar.o: tar.h -builtin/pack-objects.o: thread-utils.h connect.o transport.o http-backend.o: url.h http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h
Signature · 1 line
1.7.2.4