Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
@ -96,7 +96,7 @@ int get_ack(int fd, unsigned char *result_sha1)
|
||||
line[--len] = 0;
|
||||
if (!strcmp(line, "NAK"))
|
||||
return 0;
|
||||
if (!strncmp(line, "ACK ", 4)) {
|
||||
if (!prefixcmp(line, "ACK ")) {
|
||||
if (!get_sha1_hex(line+4, result_sha1)) {
|
||||
if (strstr(line+45, "continue"))
|
||||
return 2;
|
||||
@ -196,8 +196,8 @@ static int count_refspec_match(const char *pattern,
|
||||
*/
|
||||
if (namelen != patlen &&
|
||||
patlen != namelen - 5 &&
|
||||
strncmp(name, "refs/heads/", 11) &&
|
||||
strncmp(name, "refs/tags/", 10)) {
|
||||
prefixcmp(name, "refs/heads/") &&
|
||||
prefixcmp(name, "refs/tags/")) {
|
||||
/* We want to catch the case where only weak
|
||||
* matches are found and there are multiple
|
||||
* matches, and where more than one strong
|
||||
|
Reference in New Issue
Block a user