From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 04/12] Replace some use of starts_with() with skip_prefix()
Date: Wed, 18 Dec 2013 21:53:49 +0700 [thread overview]
Message-ID: <1387378437-20646-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1387378437-20646-1-git-send-email-pclouds@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2013-12-18 14:54 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 14:53 [PATCH 00/12] Hard coded string length cleanup Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 01/12] Make starts_with() a wrapper of skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 17:50 ` Junio C Hamano
2013-12-18 18:16 ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing Nguyễn Thái Ngọc Duy
2013-12-20 6:51 ` Johannes Sixt
2013-12-20 7:04 ` Jeff King
2013-12-20 8:46 ` Christian Couder
2013-12-20 10:43 ` René Scharfe
2013-12-20 21:31 ` Junio C Hamano
2013-12-21 4:44 ` Duy Nguyen
2013-12-26 19:27 ` Junio C Hamano
2013-12-28 9:54 ` Jeff King
2013-12-18 14:53 ` [PATCH 03/12] Add and use skip_prefix_defval() Nguyễn Thái Ngọc Duy
2013-12-18 16:27 ` Kent R. Spillner
2013-12-18 17:51 ` Junio C Hamano
2013-12-18 14:53 ` Nguyễn Thái Ngọc Duy [this message]
2013-12-18 14:53 ` [PATCH 05/12] Convert a lot of starts_with() to skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 06/12] fetch.c: replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 07/12] connect.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 08/12] refs.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 09/12] diff.c: reduce code duplication in --stat-xxx parsing Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 10/12] environment.c: replace starts_with() in strip_namespace() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 11/12] diff.c: convert diff_scoreopt_parse to use skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 12/12] refs.c: use skip_prefix() in prune_ref() Nguyễn Thái Ngọc Duy
2013-12-18 18:06 ` [PATCH 00/12] Hard coded string length cleanup Junio C Hamano
2013-12-19 23:32 ` René Scharfe
2013-12-19 23:50 ` Duy Nguyen
2013-12-20 1:06 ` René Scharfe
2013-12-20 2:29 ` Duy Nguyen
2013-12-20 16:53 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1387378437-20646-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.