mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-13 13:17:43 +03:00
sd-boot: simplify the implementation of entry uniquification
There's a slight change in implementation: we first try to append the version, then look for any non-unique pairs again. Before, we would only mark as possibly unique those entries we changed. But if there are two entries that e.g. have the same title and version, but only one has the machine-id specified, we would treat one of them as still non-unique after appending the machine-id to the other one. So the new algorithm is simpler but more robust (not that it matters).
This commit is contained in:
parent
02fa054dc4
commit
a2fa605a65
@ -1305,10 +1305,29 @@ static VOID config_default_entry_select(Config *config) {
|
||||
config->idx_default = -1;
|
||||
}
|
||||
|
||||
static BOOLEAN find_nonunique(ConfigEntry **entries, UINTN entry_count) {
|
||||
BOOLEAN non_unique = FALSE;
|
||||
UINTN i, k;
|
||||
|
||||
for (i = 0; i < entry_count; i++)
|
||||
entries[i]->non_unique = FALSE;
|
||||
|
||||
for (i = 0; i < entry_count; i++)
|
||||
for (k = 0; k < entry_count; k++) {
|
||||
if (i == k)
|
||||
continue;
|
||||
if (StrCmp(entries[i]->title_show, entries[k]->title_show) != 0)
|
||||
continue;
|
||||
|
||||
non_unique = entries[i]->non_unique = entries[k]->non_unique = TRUE;
|
||||
}
|
||||
|
||||
return non_unique;
|
||||
}
|
||||
|
||||
/* generate a unique title, avoiding non-distinguishable menu entries */
|
||||
static VOID config_title_generate(Config *config) {
|
||||
UINTN i, k;
|
||||
BOOLEAN unique;
|
||||
UINTN i;
|
||||
|
||||
/* set title */
|
||||
for (i = 0; i < config->entry_count; i++) {
|
||||
@ -1321,20 +1340,7 @@ static VOID config_title_generate(Config *config) {
|
||||
config->entries[i]->title_show = StrDuplicate(title);
|
||||
}
|
||||
|
||||
unique = TRUE;
|
||||
for (i = 0; i < config->entry_count; i++) {
|
||||
for (k = 0; k < config->entry_count; k++) {
|
||||
if (i == k)
|
||||
continue;
|
||||
if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0)
|
||||
continue;
|
||||
|
||||
unique = FALSE;
|
||||
config->entries[i]->non_unique = TRUE;
|
||||
config->entries[k]->non_unique = TRUE;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
if (!find_nonunique(config->entries, config->entry_count))
|
||||
return;
|
||||
|
||||
/* add version to non-unique titles */
|
||||
@ -1349,23 +1355,9 @@ static VOID config_title_generate(Config *config) {
|
||||
s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, config->entries[i]->version);
|
||||
FreePool(config->entries[i]->title_show);
|
||||
config->entries[i]->title_show = s;
|
||||
config->entries[i]->non_unique = FALSE;
|
||||
}
|
||||
|
||||
unique = TRUE;
|
||||
for (i = 0; i < config->entry_count; i++) {
|
||||
for (k = 0; k < config->entry_count; k++) {
|
||||
if (i == k)
|
||||
continue;
|
||||
if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0)
|
||||
continue;
|
||||
|
||||
unique = FALSE;
|
||||
config->entries[i]->non_unique = TRUE;
|
||||
config->entries[k]->non_unique = TRUE;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
if (!find_nonunique(config->entries, config->entry_count))
|
||||
return;
|
||||
|
||||
/* add machine-id to non-unique titles */
|
||||
@ -1383,24 +1375,10 @@ static VOID config_title_generate(Config *config) {
|
||||
s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, m);
|
||||
FreePool(config->entries[i]->title_show);
|
||||
config->entries[i]->title_show = s;
|
||||
config->entries[i]->non_unique = FALSE;
|
||||
FreePool(m);
|
||||
}
|
||||
|
||||
unique = TRUE;
|
||||
for (i = 0; i < config->entry_count; i++) {
|
||||
for (k = 0; k < config->entry_count; k++) {
|
||||
if (i == k)
|
||||
continue;
|
||||
if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0)
|
||||
continue;
|
||||
|
||||
unique = FALSE;
|
||||
config->entries[i]->non_unique = TRUE;
|
||||
config->entries[k]->non_unique = TRUE;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
if (!find_nonunique(config->entries, config->entry_count))
|
||||
return;
|
||||
|
||||
/* add file name to non-unique titles */
|
||||
|
Loading…
Reference in New Issue
Block a user