Skip to content

Commit f6f348a

Browse files
avargitster
authored andcommitted
versioncmp.c: refactor config reading next commit
Refactor the reading of the versionSort.suffix and versionSort.prereleaseSuffix configuration variables to stay within the bounds of our CodingGuidelines when it comes to line length, and to avoid repeating ourselves. Renaming "deprecated_prereleases" to "oldl" doesn't help us to avoid line wrapping now, but it will in a subsequent commit. Let's also split out the names of the config variables into variables of our own, and refactor the nested if/else to avoid indenting it, and the existing bracing style issue. This all helps with the subsequent commit, where we'll need to start checking different git_config_get_value_multi() return value. See c026557 (versioncmp: generalize version sort suffix reordering, 2016-12-08) for the original implementation of most of this. Moving the "initialized = 1" assignment allows us to move some of this to the variable declarations in the subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b83efce commit f6f348a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

versioncmp.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,18 @@ int versioncmp(const char *s1, const char *s2)
160160
}
161161

162162
if (!initialized) {
163-
const struct string_list *deprecated_prereleases;
163+
const char *const newk = "versionsort.suffix";
164+
const char *const oldk = "versionsort.prereleasesuffix";
165+
const struct string_list *oldl;
166+
167+
prereleases = git_config_get_value_multi(newk);
168+
oldl = git_config_get_value_multi(oldk);
169+
if (prereleases && oldl)
170+
warning("ignoring %s because %s is set", oldk, newk);
171+
else if (!prereleases)
172+
prereleases = oldl;
173+
164174
initialized = 1;
165-
prereleases = git_config_get_value_multi("versionsort.suffix");
166-
deprecated_prereleases = git_config_get_value_multi("versionsort.prereleasesuffix");
167-
if (prereleases) {
168-
if (deprecated_prereleases)
169-
warning("ignoring versionsort.prereleasesuffix because versionsort.suffix is set");
170-
} else
171-
prereleases = deprecated_prereleases;
172175
}
173176
if (prereleases && swap_prereleases(s1, s2, (const char *) p1 - s1 - 1,
174177
&diff))

0 commit comments

Comments
 (0)