[PATCH 06/12] fetch.c: replace some use of starts_with() with skip_prefix()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Variable "what" is set in an if/else chain. If all fails (and "what"
is set to NULL) it'll be reset in the final "else" block.

in get_remote_group(), "key" is only used once. So changing it does
not harm.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 builtin/fetch.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 1e7d617..38f4f7b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -589,18 +589,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				kind = "";
 				what = "";
 			}
-			else if (starts_with(rm->name, "refs/heads/")) {
+			else if ((what = skip_prefix(rm->name, "refs/heads/")) != NULL)
 				kind = "branch";
-				what = rm->name + 11;
-			}
-			else if (starts_with(rm->name, "refs/tags/")) {
+			else if ((what = skip_prefix(rm->name, "refs/tags/")) != NULL)
 				kind = "tag";
-				what = rm->name + 10;
-			}
-			else if (starts_with(rm->name, "refs/remotes/")) {
+			else if ((what = skip_prefix(rm->name, "refs/remotes/")) != NULL)
 				kind = "remote-tracking branch";
-				what = rm->name + 13;
-			}
 			else {
 				kind = "";
 				what = rm->name;
@@ -896,8 +890,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)
 {
 	struct remote_group_data *g = priv;
 
-	if (starts_with(key, "remotes.") &&
-			!strcmp(key + 8, g->name)) {
+	if ((key = skip_prefix(key, "remotes.")) != NULL &&
+	    !strcmp(key, g->name)) {
 		/* split list by white space */
 		int space = strcspn(value, " \t\n");
 		while (*value) {
-- 
1.8.5.1.208.g019362e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]