1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! `core.fsmonitor` UX helpers: the one-time tip printed when git change
//! detection is slow, and the opt-in enable path used by `st init --fsmonitor`.
//!
//! Split from `freshness.rs` to keep that file under the 400-line quality gate.
//! Re-exported from `freshness` so existing `freshness::enable_fsmonitor` /
//! `freshness::maybe_print_fsmonitor_tip` call sites (and the `freshness_tests`
//! module, via `use super::*`) resolve unchanged.
use Path;
use ;
/// Name of the stamp file (relative to the index dir) written the first time
/// the `core.fsmonitor` tip is printed, so it prints at most once per index.
pub const FSMONITOR_TIP_STAMP: &str = "fsmonitor-tip-shown";
/// Print a one-time tip suggesting `git config core.fsmonitor true` when
/// git change detection is taking a large share of the auto-update time
/// budget, and detection could be made near-instant by fsmonitor.
///
/// Fires only when all of the following hold:
/// - `detect_elapsed_ms` is more than half of `budget_ms` (a zero budget
/// never fires: there is no meaningful "half" of zero).
/// - the stamp file (`<index_dir>/fsmonitor-tip-shown`) does not already
/// exist -- this makes the tip print at most once per index.
/// - `core.fsmonitor` is not already set to `true` in `repo_root`.
///
/// This function only ever reads git config and writes the stamp file; it
/// never sets `core.fsmonitor` itself (see `cmd_init`'s `--fsmonitor` flag
/// for the only place that does, since enabling fsmonitor starts a
/// background daemon and must be explicit, opt-in consent).
///
/// Errors probing `core.fsmonitor` or writing the stamp file are swallowed:
/// this is a best-effort UX hint, never something that should affect the
/// search/update outcome or its exit code.
/// Returns `true` when `git config core.fsmonitor` resolves to `true` in
/// `repo_root`. Any error (no git, non-git dir, unset config) is treated as
/// "not enabled" so the tip can still be offered.
pub
/// Set `core.fsmonitor = true` in `repo_root` via `git config`.
///
/// This is the only place in `syntext` that enables fsmonitor: enabling it
/// starts a background watchman-style daemon, so it must only ever happen
/// from explicit, opt-in user consent (`st init --fsmonitor`), never as a
/// side effect of the bounded auto-update tip (see `maybe_print_fsmonitor_tip`,
/// which only reads config and never writes it).
///
/// Returns `true` when `git config` exits successfully, `false` on any
/// error (no git, non-git directory, or a failed git invocation).