bcpierce00 / unison

Unison file synchronizer
GNU General Public License v3.0
4.01k stars 227 forks source link

Allow substrings in `force`, `prefer`, ... preferences #854

Closed tleedjarv closed 1 year ago

tleedjarv commented 1 year ago

It always annoyed me that preferences like force require a complete root specification. When your root looks like ssh://user@host.domain.com:port//a/long/path/to/the/actual/root/and/then/some, you need to copy this whole thing to every single force, prefer, ... (there are many preferences like this) preference value, and it has to match exactly.

This patch makes all those preferences accept a substring of the root to identify it. To identify a root, the following unique substrings are allowed:

Examples:

Note that a prefix or suffix of an arbitrary length is accepted, so the examples above would also work with longer and shorter values, as long as one of the roots is uniquely identified.

This PR contains another change. Partially to remove any negative performance impacts caused by the substring matching, partially an improvement in its own right, results of two recurring operations are cached (the first two commits). Without this patch, clroots and values of force, prefer, ... preferences were reparsed every single time they were needed.

(For reviewers: actual code changes are rather small; much of the diff is due to doc changes.)