From cf622817441614106b80eda669126d7a6c31c276 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 19 Feb 2021 19:59:24 +0100 Subject: [PATCH 5/6] ruleup: purge unused ruleset entities by default. Make ruleup clean up the mess after the ruleset upgrade by attempting to purge unused entities unless it is told that the dirty result is wanted. See osdn #41615 --- tools/ruleup.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/ruleup.c b/tools/ruleup.c index edcb3d1d67..8cbda6df32 100644 --- a/tools/ruleup.c +++ b/tools/ruleup.c @@ -46,6 +46,7 @@ static char *rs_selected = NULL; static char *od_selected = NULL; static int fatal_assertions = -1; +static bool dirty = FALSE; /**********************************************************************//** Parse freeciv-ruleup commandline parameters. @@ -76,6 +77,8 @@ static void rup_parse_cmdline(int argc, char *argv[]) /* TRANS: "output" is exactly what user must type, do not translate. */ _("output DIRECTORY"), _("Create directory DIRECTORY for output")); + cmdhelp_add(help, "d", "dirty", + _("Don't clean up the ruleset before saving it")); /* The function below prints a header and footer for the options. * Furthermore, the options are sorted. */ @@ -112,6 +115,8 @@ static void rup_parse_cmdline(int argc, char *argv[]) exit(EXIT_FAILURE); } #endif /* FREECIV_NDEBUG */ + } else if (is_option("--dirty", argv[i])) { + dirty = TRUE; } else { fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]); cmdline_option_values_free(); @@ -194,6 +199,16 @@ int main(int argc, char **argv) log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME); } + /* Clean up unused entities added during the ruleset upgrade. */ + if (!dirty) { + int purged = ruleset_purge_unused_entities(); + + if (purged > 0) { + log_normal("Purged %d unused entities after the ruleset upgrade", + purged); + } + } + save_ruleset(tgt_dir, game.control.name, &data); log_normal("Saved %s", tgt_dir); comments_free(); -- 2.20.1