{"thread":{"id":"35287","subject":"[PATCH v3 1/2] builtin/remote: remove postfixcmp() and use suffixcmp() instead","startedAt":"2013-11-05T21:02:35Z","lastAt":"2013-11-05T21:02:35Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"230130","messageId":"20131105210237.21525.57546.chriscool@tuxfamily.org","threadId":"35287","inReplyTo":null,"subject":"[PATCH v3 1/2] builtin/remote: remove postfixcmp() and use suffixcmp() instead","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-05T21:02:35Z","receivedAt":"2013-11-05T21:02:35Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Commit 8cc5b290 (git merge -X<option>, 25 Nov 2009) introduced\nsuffixcmp() with nearly the same implementation as postfixcmp()\nthat already existed since commit 211c8968 (Make git-remote a\nbuiltin, 29 Feb 2008).\n\nThe only difference between the two implementations is that,\nwhen the string is smaller than the suffix, one implementation\nreturns 1 while the other one returns -1.\n\nBut, as postfixcmp() is only used to compare for equality, the\ndistinction does not matter and does not affect the correctness of\nthis patch.\n\nAs postfixcmp() has always been static in builtin/remote.c\nand is used nowhere else, it makes more sense to remove it\nand use suffixcmp() instead in builtin/remote.c, rather than\nto remove suffixcmp().\n\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\nHi everyone,\n\nHere is another version of the series.\nThe first patch did not change.\nThe second patch has been changed according to the latest\nsuggestions by Max Horn and Junio.\n\nThanks,\nChristian.\n\n builtin/remote.c | 14 +++-----------\n 1 file changed, 3 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 4e14891..9b3a98e 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -80,14 +80,6 @@ static int verbose;\n static int show_all(void);\n static int prune_remote(const char *remote, int dry_run);\n \n-static inline int postfixcmp(const char *string, const char *postfix)\n-{\n-\tint len1 = strlen(string), len2 = strlen(postfix);\n-\tif (len1 < len2)\n-\t\treturn 1;\n-\treturn strcmp(string + len1 - len2, postfix);\n-}\n-\n static int fetch_remote(const char *name)\n {\n \tconst char *argv[] = { \"fetch\", name, NULL, NULL };\n@@ -277,13 +269,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)\n \t\tenum { REMOTE, MERGE, REBASE } type;\n \n \t\tkey += 7;\n-\t\tif (!postfixcmp(key, \".remote\")) {\n+\t\tif (!suffixcmp(key, \".remote\")) {\n \t\t\tname = xstrndup(key, strlen(key) - 7);\n \t\t\ttype = REMOTE;\n-\t\t} else if (!postfixcmp(key, \".merge\")) {\n+\t\t} else if (!suffixcmp(key, \".merge\")) {\n \t\t\tname = xstrndup(key, strlen(key) - 6);\n \t\t\ttype = MERGE;\n-\t\t} else if (!postfixcmp(key, \".rebase\")) {\n+\t\t} else if (!suffixcmp(key, \".rebase\")) {\n \t\t\tname = xstrndup(key, strlen(key) - 7);\n \t\t\ttype = REBASE;\n \t\t} else\n-- \n1.8.4.1.561.g186b3da.dirty\n"}]}