Skip to content

Commit

Permalink
config: preserve definition order of table items
Browse files Browse the repository at this point in the history
toml_edit uses IndexMap internally, so the order of table items is
deterministic.
  • Loading branch information
yuja committed Dec 9, 2024
1 parent 2ea75a8 commit abcea5c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,7 @@ fn load_template_aliases(
.into());
}
};
// TODO: remove sorting after migrating to toml_edit
for (decl, item) in table.iter().sorted_by_key(|&(decl, _)| decl) {
for (decl, item) in table.iter() {
let r = item
.as_str()
.ok_or_else(|| format!("Expected a string, but is {}", item.type_name()))
Expand Down
15 changes: 7 additions & 8 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ pub fn resolved_config_values(
// table.iter() does not implement DoubleEndedIterator as of
// toml_edit 0.22.22.
let frame = config_stack.len();
// TODO: Remove sorting
for (k, v) in table.iter().sorted_by_key(|(k, _)| *k) {
for (k, v) in table.iter() {
let mut sub_name = name.clone();
sub_name.push(k);
config_stack.push((sub_name, v));
Expand Down Expand Up @@ -771,7 +770,7 @@ mod tests {
dotted_decor: Decor { .. },
},
Key {
key: "email",
key: "name",
repr: None,
leaf_decor: Decor { .. },
dotted_decor: Decor { .. },
Expand All @@ -780,13 +779,13 @@ mod tests {
),
value: String(
Formatted {
value: "base@user.email",
value: "base-user-name",
repr: "default",
decor: Decor { .. },
},
),
source: EnvBase,
is_overridden: true,
is_overridden: false,
},
AnnotatedValue {
name: ConfigNamePathBuf(
Expand All @@ -798,7 +797,7 @@ mod tests {
dotted_decor: Decor { .. },
},
Key {
key: "name",
key: "email",
repr: None,
leaf_decor: Decor { .. },
dotted_decor: Decor { .. },
Expand All @@ -807,13 +806,13 @@ mod tests {
),
value: String(
Formatted {
value: "base-user-name",
value: "base@user.email",
repr: "default",
decor: Decor { .. },
},
),
source: EnvBase,
is_overridden: false,
is_overridden: true,
},
AnnotatedValue {
name: ConfigNamePathBuf(
Expand Down
3 changes: 1 addition & 2 deletions cli/src/revset_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ pub fn load_revset_aliases(
.into());
}
};
// TODO: remove sorting after migrating to toml_edit
for (decl, item) in table.iter().sorted_by_key(|&(decl, _)| decl) {
for (decl, item) in table.iter() {
warn_user_redefined_builtin(ui, layer.source, decl)?;

let r = item
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fn test_config_list_table() {
stdout,
@r###"
test-table.x = true
test-table.y.bar = 123
test-table.y.foo = "abc"
test-table.y.bar = 123
test-table.z."with space"."function()" = 5
"###);
}
Expand Down Expand Up @@ -133,10 +133,10 @@ fn test_config_list_all() {
insta::assert_snapshot!(
find_stdout_lines(r"(test-val|test-table\b[^=]*)", &stdout),
@r###"
test-val = [1, 2, 3]
test-table.x = true
test-table.y.bar = 123
test-table.y.foo = "abc"
test-val = [1, 2, 3]
test-table.y.bar = 123
"###);
}

Expand Down

0 comments on commit abcea5c

Please sign in to comment.