-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch config to YAML #239
Conversation
src/intermediate_config.rs
Outdated
} | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
pub struct IntermediateCompression { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t we use the same value for both channels? I’m already forgetting what is the benefit of having different ones. Yes, it can be a bit faster to send sources uncompressed, but I believe compression does not eat a lot of resources in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Text is very compressible compared to compiled binaries, thus we recommend at least 3
for local compression and 1
for remote
But obviously, each project can be different — thus it's a setting
As well as different use cases, for example when you have limited connection you might prefer compression over latency
It does eat quite a lot of resources, try 9
:)
src/config.rs
Outdated
#[derive(Debug, Eq, PartialEq)] | ||
pub struct Compression { | ||
pub local: i64, | ||
pub remote: i64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t it be i8
though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, it's a slip of YAML impl details, I guess I should use proper type here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not done yet, I'll track it separately, value is validated anyway and realistically i8 is going to still be i32 at least on actual hardware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/intermediate_config.rs
Outdated
|
||
let compression = match &yaml["compression"] { | ||
Yaml::Hash(compression) => { | ||
let local = match compression.get(&Yaml::String(String::from("local"))).cloned() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dude, YAML parsing in Rust sucks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, could have been worse lol
After internal discussion we decided to pursue the following.
|
@ming13 updated PR with new YAML structure |
src/config.rs
Outdated
pub local: i64, | ||
pub remote: i64, | ||
pub struct Push { | ||
pub compression: i64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still — i64
is too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to u8
src/config.rs
Outdated
pub compression: i64, | ||
} | ||
|
||
#[derive(Debug, Eq, PartialEq)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need both Eq
and PartialEq
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great question my friend!
I need equality for unit tests (assert_eq!()
)
In Rust Eq
seems to be special case of PartialEq
and most of things like assert_eq!()
need PartialEq
thus I definitely need to have PartialEq
Removed Eq
👍
pub compression: Option<IntermediateCompression>, | ||
pub remote: Option<IntermediateRemote>, | ||
pub push: Option<IntermediatePush>, | ||
pub pull: Option<IntermediatePull>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really weird, but I like that both push
and pull
have the same horizontal space...
Some(local) => match local { | ||
Yaml::Integer(local) => if local >= 1 && local <= 9 { | ||
Some(local) | ||
let push = match &yaml["push"] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is time to move push
and pull
reading to a single function since essentially they are the same. Maybe even replace struct Pull
and struct Push
with struct Sync
or whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not same, Pull
will support parallel
mode soon, common fields can be extracted though
src/intermediate_config.rs
Outdated
pub local: Option<i64>, | ||
pub remote: Option<i64>, | ||
pub struct IntermediatePush { | ||
pub compression: Option<i64> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compressionLevel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why though, it's called compression
in YAML, I mean we can have different name in code but I don't see much value in that atm
Updated PR, @ming13 let's do YAML for ignore files in separate PR, it will be a pretty big change |
All right, I’ll try not to leave any comments since the next time you’ll have time to make changes is approximately March 26. |
use std::path::Path; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
#[derive(Debug, PartialEq)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have no idea why language has PartialEq
and Eq
.
@@ -9,3 +9,5 @@ version = "3.0.0-dev" | |||
authors = ["Artem Zinnatullin <[email protected]>", "Artur Dryomov <[email protected]>", "Mainframer Developers and Contributors"] | |||
|
|||
[dependencies] | |||
yaml-rust = "0.4.2" | |||
linked-hash-map = "0.5.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, what? No maps in Rust?
}; | ||
|
||
file.read_to_string(&mut content) | ||
.unwrap_or_else(|_| panic!("Could not read config file '{}'", file_path.to_string_lossy())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot?
}; | ||
|
||
let pull = match &yaml["pull"] { | ||
Yaml::Hash(pull) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, YAML parsing is so weird...
|
||
assert_eq!(parse_config_from_str(content), Ok(IntermediateConfig { | ||
remote: Some(IntermediateRemote { | ||
host: Some(String::from("computer1")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn’t it better to define expected variables beforehand and put them into the content
?
compression: yooo | ||
"; | ||
assert_eq!(parse_config_from_str(content), Err(String::from("'pull.compression\' must be a positive integer from 1 to 9, but was String(\n \"yooo\"\n)"))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty good test suite.
Closes #225, part of #213
This change switches config format that used to be some sort of
.ini
file to YAML as discussed in #225Example of
.mainframer/config.yml
:Code is also getting ready for config files merging #213.
IntermediateConfig
represents one of possibly multiple config files, thus everything is optional.Config
represents finalized config, thus only actually optional fields are optionalNote that
remote.user
andremote.port
are not implemented yet (we continue to rely on~/.ssh/config
read byssh
for now)Description was updated to reflect changes after review, you can see edit history.