builtin/apply: avoid parameter shadowing 'linenr' global
Let's just rename the global 'state_linenr' as it will become 'state->linenr' 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. 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
eb8fdbff3c26639912e73a01cfa2a86ce787d4b2
1 file changed
+24
-24
builtin/apply.c
+24
-24
@@ -144,7 +144,7 @@ static int max_change, max_len;
144
* file (and how) we're patching right now.. The "is_xxxx"
145
* things are flags, where -1 means "don't know yet".
146
*/
147
-static int linenr = 1;
147
+static int state_linenr = 1;
148
149
/*
150
* This represents one "hunk" from a patch, starting with
@@ -905,7 +905,7 @@ static void parse_traditional_patch(const char *first, const char *second, struc
905
}
906
}
907
if (!name)
908
- die(_("unable to find filename in patch at line %d"), linenr);
908
+ die(_("unable to find filename in patch at line %d"), state_linenr);
909
}
910
911
static int gitdiff_hdrend(const char *line, struct patch *patch)
@@ -937,17 +937,17 @@ static void gitdiff_verify_name(const char *line, int isnull, char **name, int s
937
char *another;
938
if (isnull)
939
die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
940
- *name, linenr);
940
+ *name, state_linenr);
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") :
945
- _("git apply: bad git-diff - inconsistent old filename on line %d"), linenr);
945
+ _("git apply: bad git-diff - inconsistent old filename on line %d"), state_linenr);
946
free(another);
947
} else {
948
/* expect "/dev/null" */
949
if (memcmp("/dev/null", line, 9) || line[9] != '\n')
950
- die(_("git apply: bad git-diff - expected /dev/null on line %d"), linenr);
950
+ die(_("git apply: bad git-diff - expected /dev/null on line %d"), state_linenr);
951
}
952
}
953
@@ -1272,8 +1272,8 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
1272
1273
line += len;
1274
size -= len;
1275
- linenr++;
1276
- for (offset = len ; size > 0 ; offset += len, size -= len, line += len, linenr++) {
1275
+ state_linenr++;
1276
+ for (offset = len ; size > 0 ; offset += len, size -= len, line += len, state_linenr++) {
1277
static const struct opentry {
1278
const char *str;
1279
int (*fn)(const char *, struct patch *);
@@ -1440,7 +1440,7 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
1440
patch->is_new = patch->is_delete = -1;
1441
patch->old_mode = patch->new_mode = 0;
1442
patch->old_name = patch->new_name = NULL;
1443
- for (offset = 0; size > 0; offset += len, size -= len, line += len, linenr++) {
1443
+ for (offset = 0; size > 0; offset += len, size -= len, line += len, state_linenr++) {
1444
unsigned long nextlen;
1445
1446
len = linelen(line, size);
@@ -1461,7 +1461,7 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
1461
if (parse_fragment_header(line, len, &dummy) < 0)
1462
continue;
1463
die(_("patch fragment without header at line %d: %.*s"),
1464
- linenr, (int)len-1, line);
1464
+ state_linenr, (int)len-1, line);
1465
}
1466
1467
if (size < len + 6)
@@ -1482,13 +1482,13 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
1482
"git diff header lacks filename information when removing "
1483
"%d leading pathname components (line %d)",
1484
state_p_value),
1485
- state_p_value, linenr);
1485
+ state_p_value, state_linenr);
1486
patch->old_name = xstrdup(patch->def_name);
1487
patch->new_name = xstrdup(patch->def_name);
1488
}
1489
if (!patch->is_delete && !patch->new_name)
1490
die("git diff header lacks filename information "
1491
- "(line %d)", linenr);
1491
+ "(line %d)", state_linenr);
1492
patch->is_toplevel_relative = 1;
1493
*hdrsize = git_hdr_len;
1494
return offset;
@@ -1510,7 +1510,7 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
1510
/* Ok, we'll consider it a patch */
1511
parse_traditional_patch(line, line+len, patch);
1512
*hdrsize = len + nextlen;
1513
- linenr += 2;
1513
+ state_linenr += 2;
1514
return offset;
1515
}
1516
return -1;
@@ -1538,7 +1538,7 @@ static void check_whitespace(const char *line, int len, unsigned ws_rule)
1538
{
1539
unsigned result = ws_check(line + 1, len - 1, ws_rule);
1540
1541
- record_ws_error(result, line + 1, len - 2, linenr);
1541
+ record_ws_error(result, line + 1, len - 2, state_linenr);
1542
}
1543
1544
/*
@@ -1568,11 +1568,11 @@ static int parse_fragment(const char *line, unsigned long size,
1568
/* Parse the thing.. */
1569
line += len;
1570
size -= len;
1571
- linenr++;
1571
+ state_linenr++;
1572
added = deleted = 0;
1573
for (offset = len;
1574
0 < size;
1575
- offset += len, size -= len, line += len, linenr++) {
1575
+ offset += len, size -= len, line += len, state_linenr++) {
1576
if (!oldlines && !newlines)
1577
break;
1578
len = linelen(line, size);
@@ -1668,10 +1668,10 @@ static int parse_single_patch(const char *line, unsigned long size, struct patch
1668
int len;
1669
1670
fragment = xcalloc(1, sizeof(*fragment));
1671
- fragment->linenr = linenr;
1671
+ fragment->linenr = state_linenr;
1672
len = parse_fragment(line, size, patch, fragment);
1673
if (len <= 0)
1674
- die(_("corrupt patch at line %d"), linenr);
1674
+ die(_("corrupt patch at line %d"), state_linenr);
1675
fragment->patch = line;
1676
fragment->size = len;
1677
oldlines += fragment->oldlines;
@@ -1799,13 +1799,13 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1799
else
1800
return NULL;
1801
1802
- linenr++;
1802
+ state_linenr++;
1803
buffer += llen;
1804
while (1) {
1805
int byte_length, max_byte_length, newsize;
1806
llen = linelen(buffer, size);
1807
used += llen;
1808
- linenr++;
1808
+ state_linenr++;
1809
if (llen == 1) {
1810
/* consume the blank line */
1811
buffer++;
@@ -1859,7 +1859,7 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1859
free(data);
1860
*status_p = -1;
1861
error(_("corrupt binary patch at line %d: %.*s"),
1862
- linenr-1, llen-1, buffer);
1862
+ state_linenr-1, llen-1, buffer);
1863
return NULL;
1864
}
1865
@@ -1892,7 +1892,7 @@ static int parse_binary(char *buffer, unsigned long size, struct patch *patch)
1892
forward = parse_binary_hunk(&buffer, &size, &status, &used);
1893
if (!forward && !status)
1894
/* there has to be one hunk (forward hunk) */
1895
- return error(_("unrecognized binary patch at line %d"), linenr-1);
1895
+ return error(_("unrecognized binary patch at line %d"), state_linenr-1);
1896
if (status)
1897
/* otherwise we already gave an error message */
1898
return status;
@@ -2010,7 +2010,7 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
2010
if (llen == sizeof(git_binary) - 1 &&
2011
!memcmp(git_binary, buffer + hd, llen)) {
2012
int used;
2013
- linenr++;
2013
+ state_linenr++;
2014
used = parse_binary(buffer + hd + llen,
2015
size - hd - llen, patch);
2016
if (used < 0)
@@ -2031,7 +2031,7 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
2031
int len = strlen(binhdr[i]);
2032
if (len < size - hd &&
2033
!memcmp(binhdr[i], buffer + hd, len)) {
2034
- linenr++;
2034
+ state_linenr++;
2035
patch->is_binary = 1;
2036
patchsize = llen;
2037
break;
@@ -2045,7 +2045,7 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
2045
*/
2046
if ((apply || check) &&
2047
(!patch->is_binary && !metadata_changes(patch)))
2048
- die(_("patch with only garbage at line %d"), linenr);
2048
+ die(_("patch with only garbage at line %d"), state_linenr);
2049
}
2050
2051
return offset + hdrsize + patchsize;