@matheusbsbs / matheus-bagliano / commits / 9881b451f3
Fork 0

merge: use skip_prefix to parse config key

Instead of using `starts_with()`, the magic number 7, `strlen()` and a fair number of additions to verify the three parts of the config key "branch.<branch>.mergeoptions", use `skip_prefix()` to jump through them more explicitly. We need to introduce a new variable for this (we certainly can't modify `k` just because we see "branch."!). With `skip_prefix()` we often use quite bland names like `p` or `str`. Let's do the same. If and when this function needs to do more prefix-skipping, we'll have a generic variable ready for this. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Apr 11, 2020 at 09:11 UTC 9881b451f33b7b0df247a4b28a9c08c65eb4ca95
1 file changed +5 -3
builtin/merge.c
+5 -3
@@ -597,10 +597,12 @@ static void parse_branch_merge_options(char *bmo)
597 static int git_merge_config(const char *k, const char *v, void *cb)
598 {
599 int status;
600 + const char *str;
601
601 - if (branch && starts_with(k, "branch.") &&
602 - starts_with(k + 7, branch) &&
603 - !strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
602 + if (branch &&
603 + skip_prefix(k, "branch.", &str) &&
604 + skip_prefix(str, branch, &str) &&
605 + !strcmp(str, ".mergeoptions")) {
606 free(branch_mergeoptions);
607 branch_mergeoptions = xstrdup(v);
608 return 0;