diff mbox series

[v6,19/30] help: include fsmonitor--daemon feature flag in version info

Message ID bc240a9e665841a622c96b8a245ce033684394f6.1646160212.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Commit 3d4b8e1137f1dae3193787444dab8f204dad6216
Headers show
Series Builtin FSMonitor Part 2 | expand

Commit Message

Jeff Hostetler March 1, 2022, 6:43 p.m. UTC
From: Jeff Hostetler <jeffhost@microsoft.com>

Add the "feature: fsmonitor--daemon" message to the output of
`git version --build-options`.

The builtin FSMonitor is only available on certain platforms and
even then only when certain Makefile flags are enabled, so print
a message in the verbose version output when it is available.

This can be used by test scripts for prereq testing.  Granted, tests
could just try `git fsmonitor--daemon status` and look for a 128 exit
code or grep for a "not supported" message on stderr, but these
methods are rather obscure.

The main advantage is that the feature message will automatically
appear in bug reports and other support requests.

This concept was also used during the development of Scalar for
similar reasons.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 help.c        | 4 ++++
 t/test-lib.sh | 6 ++++++
 2 files changed, 10 insertions(+)

Comments

Ævar Arnfjörð Bjarmason March 7, 2022, 10:51 a.m. UTC | #1
On Tue, Mar 01 2022, Jeff Hostetler via GitGitGadget wrote:

> From: Jeff Hostetler <jeffhost@microsoft.com>
>
> Add the "feature: fsmonitor--daemon" message to the output of
> `git version --build-options`.
>
> The builtin FSMonitor is only available on certain platforms and
> even then only when certain Makefile flags are enabled, so print
> a message in the verbose version output when it is available.
>
> This can be used by test scripts for prereq testing.  Granted, tests
> could just try `git fsmonitor--daemon status` and look for a 128 exit
> code or grep for a "not supported" message on stderr, but these
> methods are rather obscure.
>
> The main advantage is that the feature message will automatically
> appear in bug reports and other support requests.
>
> This concept was also used during the development of Scalar for
> similar reasons.
>
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  help.c        | 4 ++++
>  t/test-lib.sh | 6 ++++++
>  2 files changed, 10 insertions(+)
>
> diff --git a/help.c b/help.c
> index 71444906ddf..9112a51e84b 100644
> --- a/help.c
> +++ b/help.c
> @@ -12,6 +12,7 @@
>  #include "refs.h"
>  #include "parse-options.h"
>  #include "prompt.h"
> +#include "fsmonitor-ipc.h"
>  
>  struct category_description {
>  	uint32_t category;
> @@ -695,6 +696,9 @@ void get_version_info(struct strbuf *buf, int show_build_options)
>  		strbuf_addf(buf, "sizeof-size_t: %d\n", (int)sizeof(size_t));
>  		strbuf_addf(buf, "shell-path: %s\n", SHELL_PATH);
>  		/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
> +
> +		if (fsmonitor_ipc__is_supported())
> +			strbuf_addstr(buf, "feature: fsmonitor--daemon\n");
>  	}
>  }
>  
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index e4716b0b867..46cd596e7f5 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1799,3 +1799,9 @@ test_lazy_prereq SHA1 '
>  # Tests that verify the scheduler integration must set this locally
>  # to avoid errors.
>  GIT_TEST_MAINT_SCHEDULER="none:exit 1"
> +
> +# Does this platform support `git fsmonitor--daemon`
> +#
> +test_lazy_prereq FSMONITOR_DAEMON '
> +	git version --build-options | grep "feature:" | grep "fsmonitor--daemon"
> +'

As I found recently (referenced in another series) the test_lazy_prereq
doesn't currently catch segfaults etc. in git even if test_must_fail and
friends are used.

But it's still better to future-proof things and not add more cases of
git on the LHS of a pipe. So instead:

    git version .. >out &&
    grep ...

The prereqs are run in their own temporary directory, so creating those
files is OK.

Also: You run "grep" here twice, but as the code context shown we could
just run it once.
Jeff Hostetler March 8, 2022, 9:19 p.m. UTC | #2
On 3/7/22 5:51 AM, Ævar Arnfjörð Bjarmason wrote:
> 
> On Tue, Mar 01 2022, Jeff Hostetler via GitGitGadget wrote:
> 
>> From: Jeff Hostetler <jeffhost@microsoft.com>
>>
[...]
>> +# Does this platform support `git fsmonitor--daemon`
>> +#
>> +test_lazy_prereq FSMONITOR_DAEMON '
>> +	git version --build-options | grep "feature:" | grep "fsmonitor--daemon"
>> +'
> 
> As I found recently (referenced in another series) the test_lazy_prereq
> doesn't currently catch segfaults etc. in git even if test_must_fail and
> friends are used.
> 
> But it's still better to future-proof things and not add more cases of
> git on the LHS of a pipe. So instead:
> 
>      git version .. >out &&
>      grep ...
> 
> The prereqs are run in their own temporary directory, so creating those
> files is OK.

Yes, I think I saw a series on this topic in my inbox recently.

This command is very safe, so I'd rather not reroll just for this.


> 
> Also: You run "grep" here twice, but as the code context shown we could
> just run it once.
> 

True, but I think this can wait too.

Thanks,
Jeff
diff mbox series

Patch

diff --git a/help.c b/help.c
index 71444906ddf..9112a51e84b 100644
--- a/help.c
+++ b/help.c
@@ -12,6 +12,7 @@ 
 #include "refs.h"
 #include "parse-options.h"
 #include "prompt.h"
+#include "fsmonitor-ipc.h"
 
 struct category_description {
 	uint32_t category;
@@ -695,6 +696,9 @@  void get_version_info(struct strbuf *buf, int show_build_options)
 		strbuf_addf(buf, "sizeof-size_t: %d\n", (int)sizeof(size_t));
 		strbuf_addf(buf, "shell-path: %s\n", SHELL_PATH);
 		/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
+
+		if (fsmonitor_ipc__is_supported())
+			strbuf_addstr(buf, "feature: fsmonitor--daemon\n");
 	}
 }
 
diff --git a/t/test-lib.sh b/t/test-lib.sh
index e4716b0b867..46cd596e7f5 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1799,3 +1799,9 @@  test_lazy_prereq SHA1 '
 # Tests that verify the scheduler integration must set this locally
 # to avoid errors.
 GIT_TEST_MAINT_SCHEDULER="none:exit 1"
+
+# Does this platform support `git fsmonitor--daemon`
+#
+test_lazy_prereq FSMONITOR_DAEMON '
+	git version --build-options | grep "feature:" | grep "fsmonitor--daemon"
+'