builtin/apply: avoid parameter shadowing 'p_value' global

Let's just rename the global 'state_p_value' as it will become 'state->p_value' in a following patch. This also avoid errors when compiling with -Wshadow and makes it safer to later move global variables into a "state" struct. Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 11, 2016 at 15:16 UTC 560e35468feea3b471418dfe48d753f433141e10
1 file changed +17 -17
builtin/apply.c
+17 -17
@@ -35,7 +35,7 @@ static int prefix_length = -1;
35 static int newfd = -1;
36
37 static int unidiff_zero;
38 -static int p_value = 1;
38 +static int state_p_value = 1;
39 static int p_value_known;
40 static int check_index;
41 static int update_index;
@@ -872,24 +872,24 @@ static void parse_traditional_patch(const char *first, const char *second, struc
872 q = guess_p_value(second);
873 if (p < 0) p = q;
874 if (0 <= p && p == q) {
875 - p_value = p;
875 + state_p_value = p;
876 p_value_known = 1;
877 }
878 }
879 if (is_dev_null(first)) {
880 patch->is_new = 1;
881 patch->is_delete = 0;
882 - name = find_name_traditional(second, NULL, p_value);
882 + name = find_name_traditional(second, NULL, state_p_value);
883 patch->new_name = name;
884 } else if (is_dev_null(second)) {
885 patch->is_new = 0;
886 patch->is_delete = 1;
887 - name = find_name_traditional(first, NULL, p_value);
887 + name = find_name_traditional(first, NULL, state_p_value);
888 patch->old_name = name;
889 } else {
890 char *first_name;
891 - first_name = find_name_traditional(first, NULL, p_value);
892 - name = find_name_traditional(second, first_name, p_value);
891 + first_name = find_name_traditional(first, NULL, state_p_value);
892 + name = find_name_traditional(second, first_name, state_p_value);
893 free(first_name);
894 if (has_epoch_timestamp(first)) {
895 patch->is_new = 1;
@@ -928,7 +928,7 @@ static int gitdiff_hdrend(const char *line, struct patch *patch)
928 static void gitdiff_verify_name(const char *line, int isnull, char **name, int side)
929 {
930 if (!*name && !isnull) {
931 - *name = find_name(line, NULL, p_value, TERM_TAB);
931 + *name = find_name(line, NULL, state_p_value, TERM_TAB);
932 return;
933 }
934
@@ -938,7 +938,7 @@ static void gitdiff_verify_name(const char *line, int isnull, char **name, int s
938 if (isnull)
939 die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
940 *name, linenr);
941 - another = find_name(line, NULL, p_value, TERM_TAB);
941 + another = find_name(line, NULL, state_p_value, TERM_TAB);
942 if (!another || memcmp(another, *name, len + 1))
943 die((side == DIFF_NEW_NAME) ?
944 _("git apply: bad git-diff - inconsistent new filename on line %d") :
@@ -997,7 +997,7 @@ static int gitdiff_copysrc(const char *line, struct patch *patch)
997 {
998 patch->is_copy = 1;
999 free(patch->old_name);
1000 - patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0);
1000 + patch->old_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
1001 return 0;
1002 }
1003
@@ -1005,7 +1005,7 @@ static int gitdiff_copydst(const char *line, struct patch *patch)
1005 {
1006 patch->is_copy = 1;
1007 free(patch->new_name);
1008 - patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0);
1008 + patch->new_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
1009 return 0;
1010 }
1011
@@ -1013,7 +1013,7 @@ static int gitdiff_renamesrc(const char *line, struct patch *patch)
1013 {
1014 patch->is_rename = 1;
1015 free(patch->old_name);
1016 - patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0);
1016 + patch->old_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
1017 return 0;
1018 }
1019
@@ -1021,7 +1021,7 @@ static int gitdiff_renamedst(const char *line, struct patch *patch)
1021 {
1022 patch->is_rename = 1;
1023 free(patch->new_name);
1024 - patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0);
1024 + patch->new_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
1025 return 0;
1026 }
1027
@@ -1092,10 +1092,10 @@ static const char *skip_tree_prefix(const char *line, int llen)
1092 int nslash;
1093 int i;
1094
1095 - if (!p_value)
1095 + if (!state_p_value)
1096 return (llen && line[0] == '/') ? NULL : line;
1097
1098 - nslash = p_value;
1098 + nslash = state_p_value;
1099 for (i = 0; i < llen; i++) {
1100 int ch = line[i];
1101 if (ch == '/' && --nslash <= 0)
@@ -1481,8 +1481,8 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
1481 "%d leading pathname component (line %d)",
1482 "git diff header lacks filename information when removing "
1483 "%d leading pathname components (line %d)",
1484 - p_value),
1485 - p_value, linenr);
1484 + state_p_value),
1485 + state_p_value, linenr);
1486 patch->old_name = xstrdup(patch->def_name);
1487 patch->new_name = xstrdup(patch->def_name);
1488 }
@@ -4461,7 +4461,7 @@ static int option_parse_include(const struct option *opt,
4461 static int option_parse_p(const struct option *opt,
4462 const char *arg, int unset)
4463 {
4464 - p_value = atoi(arg);
4464 + state_p_value = atoi(arg);
4465 p_value_known = 1;
4466 return 0;
4467 }