diff mbox series

[v3,4/4] progress.c: silence cgcc suggestion about internal linkage

Message ID d66d9aa677944205cdd5af77192c35ec929692ea.1587996766.git.congdanhqx@gmail.com (mailing list archive)
State New, archived
Headers show
Series Partial fix `make sparse` | expand

Commit Message

Đoàn Trần Công Danh April 27, 2020, 2:22 p.m. UTC
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---

Notes:
    Unify all declaration together and keep them under an ifdef.
    
    With the hope that no other static analysis tools complain.

 progress.c               | 2 +-
 progress.h               | 8 ++++++++
 t/helper/test-progress.c | 9 +--------
 3 files changed, 10 insertions(+), 9 deletions(-)

Comments

Johannes Schindelin May 1, 2020, 8:09 p.m. UTC | #1
Hi,

On Mon, 27 Apr 2020, Đoàn Trần Công Danh wrote:

> diff --git a/progress.h b/progress.h
> index 847338911f..f1913acf73 100644
> --- a/progress.h
> +++ b/progress.h
> @@ -3,6 +3,14 @@
>
>  struct progress;
>
> +#ifdef GIT_TEST_PROGRESS_ONLY
> +
> +extern int progress_testing;
> +extern uint64_t progress_test_ns;
> +void progress_test_force_update(void);
> +
> +#endif
> +
>  void display_throughput(struct progress *progress, uint64_t total);
>  void display_progress(struct progress *progress, uint64_t n);
>  struct progress *start_progress(const char *title, uint64_t total);

A slightly cleaner strategy would be to add a separate header file, say,
`progress-internal.h` or `internal/progress.h` to declare the variables
and the function.

I guess at some stage we really need to define a proper API of libgit.a.
Just because we refuse to declare such an API doesn't mean that people
don't use libgit.a in that way (e.g. cgit, cinnabar). We might just as
well face reality and split up `cache.h` and put the API part into header
files in a subdirectory `include/`.

Ciao,
Dscho
diff mbox series

Patch

diff --git a/progress.c b/progress.c
index 19805ac646..75633e9c5e 100644
--- a/progress.c
+++ b/progress.c
@@ -8,6 +8,7 @@ 
  * published by the Free Software Foundation.
  */
 
+#define GIT_TEST_PROGRESS_ONLY
 #include "cache.h"
 #include "gettext.h"
 #include "progress.h"
@@ -52,7 +53,6 @@  static volatile sig_atomic_t progress_update;
  */
 int progress_testing;
 uint64_t progress_test_ns = 0;
-void progress_test_force_update(void); /* To silence -Wmissing-prototypes */
 void progress_test_force_update(void)
 {
 	progress_update = 1;
diff --git a/progress.h b/progress.h
index 847338911f..f1913acf73 100644
--- a/progress.h
+++ b/progress.h
@@ -3,6 +3,14 @@ 
 
 struct progress;
 
+#ifdef GIT_TEST_PROGRESS_ONLY
+
+extern int progress_testing;
+extern uint64_t progress_test_ns;
+void progress_test_force_update(void);
+
+#endif
+
 void display_throughput(struct progress *progress, uint64_t total);
 void display_progress(struct progress *progress, uint64_t n);
 struct progress *start_progress(const char *title, uint64_t total);
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 42b96cb103..5d05cbe789 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -13,20 +13,13 @@ 
  *
  * See 't0500-progress-display.sh' for examples.
  */
+#define GIT_TEST_PROGRESS_ONLY
 #include "test-tool.h"
 #include "gettext.h"
 #include "parse-options.h"
 #include "progress.h"
 #include "strbuf.h"
 
-/*
- * These are defined in 'progress.c', but are not exposed in 'progress.h',
- * because they are exclusively for testing.
- */
-extern int progress_testing;
-extern uint64_t progress_test_ns;
-void progress_test_force_update(void);
-
 int cmd__progress(int argc, const char **argv)
 {
 	int total = 0;