Message ID | 20211015041851.2122952-2-dominique.martinet@atmark-techno.com |
---|---|
State | Accepted |
Headers | show |
Series | core/artifacts_version: compare oldstyle versions directly | expand |
On 15.10.21 06:18, Dominique Martinet wrote: > The if branch would always return so else is useless. > No code change apart from reindentation > > Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> > --- > core/artifacts_versions.c | 56 +++++++++++++++++++-------------------- > 1 file changed, 27 insertions(+), 29 deletions(-) > > diff --git a/core/artifacts_versions.c b/core/artifacts_versions.c > index 14abdb420498..e8dac70c45e0 100644 > --- a/core/artifacts_versions.c > +++ b/core/artifacts_versions.c > @@ -235,41 +235,39 @@ int compare_versions(const char* left_version, const char* right_version) > else > return 0; > } > - else > - { > - semver_t left_sem = {}; > - semver_t right_sem = {}; > - int comparison; > > - /* > - * Check if semantic version is possible > - */ > - if (!semver_parse(left_version, &left_sem) && !semver_parse(right_version, &right_sem)) { > - DEBUG("Comparing semantic versions '%s' <-> '%s'", left_version, right_version); > - if (loglevel >= TRACELEVEL) > - { > - char left_rendered[SWUPDATE_GENERAL_STRING_SIZE]; > - char right_rendered[SWUPDATE_GENERAL_STRING_SIZE]; > + semver_t left_sem = {}; > + semver_t right_sem = {}; > + int comparison; > > - left_rendered[0] = right_rendered[0] = '\0'; > + /* > + * Check if semantic version is possible > + */ > + if (!semver_parse(left_version, &left_sem) && !semver_parse(right_version, &right_sem)) { > + DEBUG("Comparing semantic versions '%s' <-> '%s'", left_version, right_version); > + if (loglevel >= TRACELEVEL) > + { > + char left_rendered[SWUPDATE_GENERAL_STRING_SIZE]; > + char right_rendered[SWUPDATE_GENERAL_STRING_SIZE]; > > - semver_render(&left_sem, left_rendered); > - semver_render(&right_sem, right_rendered); > - TRACE("Parsed: '%s' <-> '%s'", left_rendered, right_rendered); > - } > + left_rendered[0] = right_rendered[0] = '\0'; > > - comparison = semver_compare(left_sem, right_sem); > - semver_free(&left_sem); > - semver_free(&right_sem); > - return comparison; > + semver_render(&left_sem, left_rendered); > + semver_render(&right_sem, right_rendered); > + TRACE("Parsed: '%s' <-> '%s'", left_rendered, right_rendered); > } > + > + comparison = semver_compare(left_sem, right_sem); > semver_free(&left_sem); > semver_free(&right_sem); > - > - /* > - * Last attempt: just compare the two strings > - */ > - DEBUG("Comparing lexicographically '%s' <-> '%s'", left_version, right_version); > - return strcmp(left_version, right_version); > + return comparison; > } > + semver_free(&left_sem); > + semver_free(&right_sem); > + > + /* > + * Last attempt: just compare the two strings > + */ > + DEBUG("Comparing lexicographically '%s' <-> '%s'", left_version, right_version); > + return strcmp(left_version, right_version); > } > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/core/artifacts_versions.c b/core/artifacts_versions.c index 14abdb420498..e8dac70c45e0 100644 --- a/core/artifacts_versions.c +++ b/core/artifacts_versions.c @@ -235,41 +235,39 @@ int compare_versions(const char* left_version, const char* right_version) else return 0; } - else - { - semver_t left_sem = {}; - semver_t right_sem = {}; - int comparison; - /* - * Check if semantic version is possible - */ - if (!semver_parse(left_version, &left_sem) && !semver_parse(right_version, &right_sem)) { - DEBUG("Comparing semantic versions '%s' <-> '%s'", left_version, right_version); - if (loglevel >= TRACELEVEL) - { - char left_rendered[SWUPDATE_GENERAL_STRING_SIZE]; - char right_rendered[SWUPDATE_GENERAL_STRING_SIZE]; + semver_t left_sem = {}; + semver_t right_sem = {}; + int comparison; - left_rendered[0] = right_rendered[0] = '\0'; + /* + * Check if semantic version is possible + */ + if (!semver_parse(left_version, &left_sem) && !semver_parse(right_version, &right_sem)) { + DEBUG("Comparing semantic versions '%s' <-> '%s'", left_version, right_version); + if (loglevel >= TRACELEVEL) + { + char left_rendered[SWUPDATE_GENERAL_STRING_SIZE]; + char right_rendered[SWUPDATE_GENERAL_STRING_SIZE]; - semver_render(&left_sem, left_rendered); - semver_render(&right_sem, right_rendered); - TRACE("Parsed: '%s' <-> '%s'", left_rendered, right_rendered); - } + left_rendered[0] = right_rendered[0] = '\0'; - comparison = semver_compare(left_sem, right_sem); - semver_free(&left_sem); - semver_free(&right_sem); - return comparison; + semver_render(&left_sem, left_rendered); + semver_render(&right_sem, right_rendered); + TRACE("Parsed: '%s' <-> '%s'", left_rendered, right_rendered); } + + comparison = semver_compare(left_sem, right_sem); semver_free(&left_sem); semver_free(&right_sem); - - /* - * Last attempt: just compare the two strings - */ - DEBUG("Comparing lexicographically '%s' <-> '%s'", left_version, right_version); - return strcmp(left_version, right_version); + return comparison; } + semver_free(&left_sem); + semver_free(&right_sem); + + /* + * Last attempt: just compare the two strings + */ + DEBUG("Comparing lexicographically '%s' <-> '%s'", left_version, right_version); + return strcmp(left_version, right_version); }
The if branch would always return so else is useless. No code change apart from reindentation Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> --- core/artifacts_versions.c | 56 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 29 deletions(-)