The sound distributed version control system

#864 If there is no [author] block global config doesn't appear to be loaded, so root level settings are ignored

Opened by ryanbooker on January 8, 2024
ryanbooker on January 9, 2024

Author is a required block in the global config. Should it be?

It is possible to leave empty (or indeed have no config file at all) which implies it could be an Option

ryanbooker added a change on January 9, 2024
EVDVNQJMBGXYEX6FI34K45C2Z55JFCK6WJBSFZ2GHFZEQFDCS6IAC
ryanbooker added a change on January 9, 2024
HRB4ZDWXHB2ZNBCV7LOE6O6KT4PECDMHR5QIB5SR4D6AOVD2OR3AC
ryanbooker on January 9, 2024

I’ve made Author optional if that’s something you think is a good idea. Cheers.

tankf33der on January 9, 2024

+1

dblsaiko on January 11, 2024

Also linking back to #861 here which solves this in a different way. :)

pmeunier on February 11, 2024

I’ve applied the patches from #861 to main, can these still be applied?

ryanbooker on February 11, 2024

These definitely conflict now. The main question to answer is: Do we want the Author block to be an Option like all other settings?

If we do, I’ll remake the change on the latest. There has been a lot of refactoring since this was made.

dblsaiko on February 11, 2024

Do we want the Author block to be an Option like all other settings?

I think the question should rather be: Should an empty author section mean something different than no author section at all? Because otherwise, you have two variants that mean the same thing (None vs default author struct) and that you’re always going to convert into the latter anyway via an otherwise unnecessary unwrap_or_default() or something comparable, so distinguishing them is pointless.

ryanbooker on February 11, 2024

@dblsaiko So you always generate a default with your change? That seems fine to me.

NOTE: When I originally made this change, I also noticed that the “default” Author was different in a couple of places. I don’t know if that was intentional or a potential issue.

i.e. repair.rs populates Author.username where mod.rs only uses Author::default().

Additionally, if we unwrap and use defaults for other config options in other places, would we benefit from coalescing all the config options to their defaults directly so we always have genuine values?

dblsaiko on February 11, 2024

Yep, the default is all empty fields. It’s fine since everything in Author is options as well.

Additionally, if we unwrap and use defaults for other config options in other places, would we benefit from coalescing all the config options to their defaults directly so we always have genuine values?

If you mean actually filling in real default values instead of leaving the values as options, that depends on whether the struct is ever saved back to disk or otherwise serialized (IIRC it is marked #[derive(Serialize)]). Because then every time it would save the file, it’d fill in the default values for each of the config values instead of leaving them unset. Getting the actual value would probably be better done via a method on the Config struct that handles that.

repair.rs populates Author.username

in Complete::from_old_format? From a quick look that actually does look like it’s eventually writing the config file, so yeah, you will want to keep the options in the struct around. But that seems intentional and fine since it’s setting the username from the old configuration.

ryanbooker on February 11, 2024

I think what I’m driving at or thinking about is a common approach to all the configuration options, if it makes sense to do so…

The problem this PR originally set out to fix was that if the Author block is missing the whole config was being thrown away. If that’s already fixed by your PRs then I think whatever else comes of this discussion is not urgent. 😀