summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-03-05 12:45:42 -0800
committerJunio C Hamano <gitster@pobox.com>2015-03-05 12:45:42 -0800
commit8a6444d50ea73350ae7e6083ecc63393749e5bb0 (patch)
tree949f413a7105dc06326fc3fc5108ebff92397f57
parentca704731b1fdf77b8f6d296bcde206c67ed9d73a (diff)
parent2ce63e9fac242a70cd6d9e1325063bbb2e5091f8 (diff)
downloadgit-8a6444d50ea73350ae7e6083ecc63393749e5bb0.tar.gz
Merge branch 'rs/simple-cleanups'
Code cleanups. * rs/simple-cleanups: sha1_name: use strlcpy() to copy strings pretty: use starts_with() to check for a prefix for-each-ref: use skip_prefix() to avoid duplicate string comparison connect: use strcmp() for string comparison
-rw-r--r--builtin/for-each-ref.c7
-rw-r--r--connect.c3
-rw-r--r--pretty.c2
-rw-r--r--sha1_name.c8
4 files changed, 7 insertions, 13 deletions
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 19be78a943..83f9cf9163 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -178,11 +178,10 @@ static const char *find_next(const char *cp)
static int verify_format(const char *format)
{
const char *cp, *sp;
- static const char color_reset[] = "color:reset";
need_color_reset_at_eol = 0;
for (cp = format; *cp && (sp = find_next(cp)); ) {
- const char *ep = strchr(sp, ')');
+ const char *color, *ep = strchr(sp, ')');
int at;
if (!ep)
@@ -191,8 +190,8 @@ static int verify_format(const char *format)
at = parse_atom(sp + 2, ep);
cp = ep + 1;
- if (starts_with(used_atom[at], "color:"))
- need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
+ if (skip_prefix(used_atom[at], "color:", &color))
+ need_color_reset_at_eol = !!strcmp(color, "reset");
}
return 0;
}
diff --git a/connect.c b/connect.c
index 372ac5ad9d..d50f52ad8b 100644
--- a/connect.c
+++ b/connect.c
@@ -157,8 +157,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
server_capabilities = xstrdup(name + name_len + 1);
}
- if (extra_have &&
- name_len == 5 && !memcmp(".have", name, 5)) {
+ if (extra_have && !strcmp(name, ".have")) {
sha1_array_append(extra_have, old_sha1);
continue;
}
diff --git a/pretty.c b/pretty.c
index 9d34d02db1..7b49304181 100644
--- a/pretty.c
+++ b/pretty.c
@@ -567,7 +567,7 @@ static char *replace_encoding_header(char *buf, const char *encoding)
char *cp = buf;
/* guess if there is an encoding header before a \n\n */
- while (strncmp(cp, "encoding ", strlen("encoding "))) {
+ while (!starts_with(cp, "encoding ")) {
cp = strchr(cp, '\n');
if (!cp || *++cp == '\n')
return buf;
diff --git a/sha1_name.c b/sha1_name.c
index cf2a83b143..95f9f8fa1a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1391,9 +1391,7 @@ static int get_sha1_with_context_1(const char *name,
namelen = strlen(cp);
}
- strncpy(oc->path, cp,
- sizeof(oc->path));
- oc->path[sizeof(oc->path)-1] = '\0';
+ strlcpy(oc->path, cp, sizeof(oc->path));
if (!active_cache)
read_cache();
@@ -1443,9 +1441,7 @@ static int get_sha1_with_context_1(const char *name,
name, len);
}
hashcpy(oc->tree, tree_sha1);
- strncpy(oc->path, filename,
- sizeof(oc->path));
- oc->path[sizeof(oc->path)-1] = '\0';
+ strlcpy(oc->path, filename, sizeof(oc->path));
free(new_filename);
return ret;