progress: filter out empty string

Summary:
Currently, the `render` function always return a non empty Vector, even for an empty string (shown as below), this behavior triggered a deadlock bug in `hg continue` (potentially other places as well when trying to lock a Rust mutex while holding the GIL), D43605596 fixed the bug.

```
lib/hgcommans/src/run.rs:458] &changes = [
    Text(
        "",
    ),
]
lib/hgcommands/src/run.rs:459] &last_changes = []
```
The non-empty vector makes many comparison checks fail, for example, [this logic](https://fburl.com/code/75u6gvuj) will never be executed, since `changes.is_empty()` is always `true`.

```
// Fast path: empty progress, unchanged.
if changes.is_empty() && !inner.progress_has_content {
    return Ok(());
}
```

This diff filters out empty strings from the Vector.

Reviewed By: sggutier

Differential Revision: D43611776

fbshipit-source-id: 67c07570dcd2176f05b8ab787a9f4860ea40a8c0
This commit is contained in:
Zhaolong Zhu 2023-02-27 13:36:02 -08:00 committed by Facebook GitHub Bot
parent e424f00ee6
commit b75037a4f5

View File

@ -21,7 +21,12 @@ use crate::RenderingConfig;
/// Render progress in to a list of termwiz changes.
pub fn render(registry: &Registry, config: &RenderingConfig) -> Vec<Change> {
vec![render_string(registry, config).into()]
let text = render_string(registry, config);
if text.is_empty() {
vec![]
} else {
vec![text.into()]
}
}
/// Render progress into a multi-line string.