apply: only pass required data to find_name_*
Currently the 'find_name_*()' functions take 'struct apply_state' as parameter, even though they only need the 'root' member from that struct. These functions are in the callchain of 'parse_git_header()', which we want to make more generally useful in a subsequent commit. To make that happen we only want to pass in the required data to 'parse_git_header()', and not the whole 'struct apply_state', and thus we want functions in the callchain of 'parse_git_header()' to only take arguments they really need. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Gummerer committed
Jul 8, 2019 at 17:33 UTC
877a833b5126f9a06dad07db169b770f898cc7b9
1 file changed
+24
-24
apply.c
+24
-24
@@ -469,7 +469,7 @@ static char *squash_slash(char *name)
469
return name;
470
}
471
472
-static char *find_name_gnu(struct apply_state *state,
472
+static char *find_name_gnu(struct strbuf *root,
473
const char *line,
474
int p_value)
475
{
@@ -495,8 +495,8 @@ static char *find_name_gnu(struct apply_state *state,
495
}
496
497
strbuf_remove(&name, 0, cp - name.buf);
498
- if (state->root.len)
499
- strbuf_insert(&name, 0, state->root.buf, state->root.len);
498
+ if (root->len)
499
+ strbuf_insert(&name, 0, root->buf, root->len);
500
return squash_slash(strbuf_detach(&name, NULL));
501
}
502
@@ -659,7 +659,7 @@ static size_t diff_timestamp_len(const char *line, size_t len)
659
return line + len - end;
660
}
661
662
-static char *find_name_common(struct apply_state *state,
662
+static char *find_name_common(struct strbuf *root,
663
const char *line,
664
const char *def,
665
int p_value,
@@ -702,30 +702,30 @@ static char *find_name_common(struct apply_state *state,
702
return squash_slash(xstrdup(def));
703
}
704
705
- if (state->root.len) {
706
- char *ret = xstrfmt("%s%.*s", state->root.buf, len, start);
705
+ if (root->len) {
706
+ char *ret = xstrfmt("%s%.*s", root->buf, len, start);
707
return squash_slash(ret);
708
}
709
710
return squash_slash(xmemdupz(start, len));
711
}
712
713
-static char *find_name(struct apply_state *state,
713
+static char *find_name(struct strbuf *root,
714
const char *line,
715
char *def,
716
int p_value,
717
int terminate)
718
{
719
if (*line == '"') {
720
- char *name = find_name_gnu(state, line, p_value);
720
+ char *name = find_name_gnu(root, line, p_value);
721
if (name)
722
return name;
723
}
724
725
- return find_name_common(state, line, def, p_value, NULL, terminate);
725
+ return find_name_common(root, line, def, p_value, NULL, terminate);
726
}
727
728
-static char *find_name_traditional(struct apply_state *state,
728
+static char *find_name_traditional(struct strbuf *root,
729
const char *line,
730
char *def,
731
int p_value)
@@ -734,7 +734,7 @@ static char *find_name_traditional(struct apply_state *state,
734
size_t date_len;
735
736
if (*line == '"') {
737
- char *name = find_name_gnu(state, line, p_value);
737
+ char *name = find_name_gnu(root, line, p_value);
738
if (name)
739
return name;
740
}
@@ -742,10 +742,10 @@ static char *find_name_traditional(struct apply_state *state,
742
len = strchrnul(line, '\n') - line;
743
date_len = diff_timestamp_len(line, len);
744
if (!date_len)
745
- return find_name_common(state, line, def, p_value, NULL, TERM_TAB);
745
+ return find_name_common(root, line, def, p_value, NULL, TERM_TAB);
746
len -= date_len;
747
748
- return find_name_common(state, line, def, p_value, line + len, 0);
748
+ return find_name_common(root, line, def, p_value, line + len, 0);
749
}
750
751
/*
@@ -759,7 +759,7 @@ static int guess_p_value(struct apply_state *state, const char *nameline)
759
760
if (is_dev_null(nameline))
761
return -1;
762
- name = find_name_traditional(state, nameline, NULL, 0);
762
+ name = find_name_traditional(&state->root, nameline, NULL, 0);
763
if (!name)
764
return -1;
765
cp = strchr(name, '/');
@@ -883,17 +883,17 @@ static int parse_traditional_patch(struct apply_state *state,
883
if (is_dev_null(first)) {
884
patch->is_new = 1;
885
patch->is_delete = 0;
886
- name = find_name_traditional(state, second, NULL, state->p_value);
886
+ name = find_name_traditional(&state->root, second, NULL, state->p_value);
887
patch->new_name = name;
888
} else if (is_dev_null(second)) {
889
patch->is_new = 0;
890
patch->is_delete = 1;
891
- name = find_name_traditional(state, first, NULL, state->p_value);
891
+ name = find_name_traditional(&state->root, first, NULL, state->p_value);
892
patch->old_name = name;
893
} else {
894
char *first_name;
895
- first_name = find_name_traditional(state, first, NULL, state->p_value);
896
- name = find_name_traditional(state, second, first_name, state->p_value);
895
+ first_name = find_name_traditional(&state->root, first, NULL, state->p_value);
896
+ name = find_name_traditional(&state->root, second, first_name, state->p_value);
897
free(first_name);
898
if (has_epoch_timestamp(first)) {
899
patch->is_new = 1;
@@ -940,7 +940,7 @@ static int gitdiff_verify_name(struct apply_state *state,
940
int side)
941
{
942
if (!*name && !isnull) {
943
- *name = find_name(state, line, NULL, state->p_value, TERM_TAB);
943
+ *name = find_name(&state->root, line, NULL, state->p_value, TERM_TAB);
944
return 0;
945
}
946
@@ -949,7 +949,7 @@ static int gitdiff_verify_name(struct apply_state *state,
949
if (isnull)
950
return error(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
951
*name, state->linenr);
952
- another = find_name(state, line, NULL, state->p_value, TERM_TAB);
952
+ another = find_name(&state->root, line, NULL, state->p_value, TERM_TAB);
953
if (!another || strcmp(another, *name)) {
954
free(another);
955
return error((side == DIFF_NEW_NAME) ?
@@ -1032,7 +1032,7 @@ static int gitdiff_copysrc(struct apply_state *state,
1032
{
1033
patch->is_copy = 1;
1034
free(patch->old_name);
1035
- patch->old_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1035
+ patch->old_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1036
return 0;
1037
}
1038
@@ -1042,7 +1042,7 @@ static int gitdiff_copydst(struct apply_state *state,
1042
{
1043
patch->is_copy = 1;
1044
free(patch->new_name);
1045
- patch->new_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1045
+ patch->new_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1046
return 0;
1047
}
1048
@@ -1052,7 +1052,7 @@ static int gitdiff_renamesrc(struct apply_state *state,
1052
{
1053
patch->is_rename = 1;
1054
free(patch->old_name);
1055
- patch->old_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1055
+ patch->old_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1056
return 0;
1057
}
1058
@@ -1062,7 +1062,7 @@ static int gitdiff_renamedst(struct apply_state *state,
1062
{
1063
patch->is_rename = 1;
1064
free(patch->new_name);
1065
- patch->new_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1065
+ patch->new_name = find_name(&state->root, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
1066
return 0;
1067
}
1068