]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge: use skip_prefix to parse config key
authorMartin Ågren <martin.agren@gmail.com>
Sat, 11 Apr 2020 07:11:45 +0000 (09:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 11 Apr 2020 21:21:12 +0000 (14:21 -0700)
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>
builtin/merge.c

index d127d2225f897f111124fb55b12cd1aae7db7a8e..df83ba2a807a88fa5904a2acbe64a7caa7188224 100644 (file)
@@ -597,10 +597,12 @@ static void parse_branch_merge_options(char *bmo)
 static int git_merge_config(const char *k, const char *v, void *cb)
 {
        int status;
+       const char *str;
 
-       if (branch && starts_with(k, "branch.") &&
-               starts_with(k + 7, branch) &&
-               !strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
+       if (branch &&
+           skip_prefix(k, "branch.", &str) &&
+           skip_prefix(str, branch, &str) &&
+           !strcmp(str, ".mergeoptions")) {
                free(branch_mergeoptions);
                branch_mergeoptions = xstrdup(v);
                return 0;