[PATCH 04/12] Replace some use of starts_with() with skip_prefix()

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

 



All the changes follow the pattern

  if (!starts_with(foo, "bar"))
    return;
  foo += 3;

which is turned into

  if ((foo = skip_prefix(foo, "bar")) == NULL)
    return;

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 builtin/branch.c | 3 +--
 pretty.c         | 3 +--
 setup.c          | 3 +--
 tag.c            | 7 +++----
 wt-status.c      | 3 +--
 5 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index b4d7716..d063de2 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -868,9 +868,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	if (!strcmp(head, "HEAD")) {
 		detached = 1;
 	} else {
-		if (!starts_with(head, "refs/heads/"))
+		if ((head = skip_prefix(head, "refs/heads/")) == NULL)
 			die(_("HEAD not found below refs/heads!"));
-		head += 11;
 	}
 	hashcpy(merge_filter_ref, head_sha1);
 
diff --git a/pretty.c b/pretty.c
index 87db08b..08e30ec 100644
--- a/pretty.c
+++ b/pretty.c
@@ -40,10 +40,9 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
 	const char *fmt;
 	int i;
 
-	if (!starts_with(var, "pretty."))
+	if ((name = skip_prefix(var, "pretty.")) == NULL)
 		return 0;
 
-	name = var + strlen("pretty.");
 	for (i = 0; i < builtin_formats_len; i++) {
 		if (!strcmp(commit_formats[i].name, name))
 			return 0;
diff --git a/setup.c b/setup.c
index 6c3f85f..debfaab 100644
--- a/setup.c
+++ b/setup.c
@@ -304,14 +304,13 @@ const char *read_gitfile(const char *path)
 	if (len != st.st_size)
 		die("Error reading %s", path);
 	buf[len] = '\0';
-	if (!starts_with(buf, "gitdir: "))
+	if ((dir = (char *)skip_prefix(buf, "gitdir: ")) == NULL)
 		die("Invalid gitfile format: %s", path);
 	while (buf[len - 1] == '\n' || buf[len - 1] == '\r')
 		len--;
 	if (len < 9)
 		die("No path in gitfile: %s", path);
 	buf[len] = '\0';
-	dir = buf + 8;
 
 	if (!is_absolute_path(dir) && (slash = strrchr(path, '/'))) {
 		size_t pathlen = slash+1 - path;
diff --git a/tag.c b/tag.c
index 7b07921..9b63d1b 100644
--- a/tag.c
+++ b/tag.c
@@ -86,9 +86,8 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 		return -1;
 	bufptr += 48; /* "object " + sha1 + "\n" */
 
-	if (!starts_with(bufptr, "type "))
+	if ((bufptr = skip_prefix(bufptr, "type ")) == NULL)
 		return -1;
-	bufptr += 5;
 	nl = memchr(bufptr, '\n', tail - bufptr);
 	if (!nl || sizeof(type) <= (nl - bufptr))
 		return -1;
@@ -109,11 +108,11 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 		item->tagged = NULL;
 	}
 
-	if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
+	if (bufptr + 4 < tail &&
+	    (bufptr = skip_prefix(bufptr, "tag ")) != NULL)
 		; 		/* good */
 	else
 		return -1;
-	bufptr += 4;
 	nl = memchr(bufptr, '\n', tail - bufptr);
 	if (!nl)
 		return -1;
diff --git a/wt-status.c b/wt-status.c
index 1f65039..185fa81 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1145,9 +1145,8 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
 	struct grab_1st_switch_cbdata *cb = cb_data;
 	const char *target = NULL, *end;
 
-	if (!starts_with(message, "checkout: moving from "))
+	if ((message = skip_prefix(message, "checkout: moving from ")) == NULL)
 		return 0;
-	message += strlen("checkout: moving from ");
 	target = strstr(message, " to ");
 	if (!target)
 		return 0;
-- 
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]