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
This commit is contained in:
commit
8a6444d50e
@ -178,11 +178,10 @@ static const char *find_next(const char *cp)
|
|||||||
static int verify_format(const char *format)
|
static int verify_format(const char *format)
|
||||||
{
|
{
|
||||||
const char *cp, *sp;
|
const char *cp, *sp;
|
||||||
static const char color_reset[] = "color:reset";
|
|
||||||
|
|
||||||
need_color_reset_at_eol = 0;
|
need_color_reset_at_eol = 0;
|
||||||
for (cp = format; *cp && (sp = find_next(cp)); ) {
|
for (cp = format; *cp && (sp = find_next(cp)); ) {
|
||||||
const char *ep = strchr(sp, ')');
|
const char *color, *ep = strchr(sp, ')');
|
||||||
int at;
|
int at;
|
||||||
|
|
||||||
if (!ep)
|
if (!ep)
|
||||||
@ -191,8 +190,8 @@ static int verify_format(const char *format)
|
|||||||
at = parse_atom(sp + 2, ep);
|
at = parse_atom(sp + 2, ep);
|
||||||
cp = ep + 1;
|
cp = ep + 1;
|
||||||
|
|
||||||
if (starts_with(used_atom[at], "color:"))
|
if (skip_prefix(used_atom[at], "color:", &color))
|
||||||
need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
|
need_color_reset_at_eol = !!strcmp(color, "reset");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
server_capabilities = xstrdup(name + name_len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extra_have &&
|
if (extra_have && !strcmp(name, ".have")) {
|
||||||
name_len == 5 && !memcmp(".have", name, 5)) {
|
|
||||||
sha1_array_append(extra_have, old_sha1);
|
sha1_array_append(extra_have, old_sha1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
2
pretty.c
2
pretty.c
@ -567,7 +567,7 @@ static char *replace_encoding_header(char *buf, const char *encoding)
|
|||||||
char *cp = buf;
|
char *cp = buf;
|
||||||
|
|
||||||
/* guess if there is an encoding header before a \n\n */
|
/* 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');
|
cp = strchr(cp, '\n');
|
||||||
if (!cp || *++cp == '\n')
|
if (!cp || *++cp == '\n')
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -1391,9 +1391,7 @@ static int get_sha1_with_context_1(const char *name,
|
|||||||
namelen = strlen(cp);
|
namelen = strlen(cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(oc->path, cp,
|
strlcpy(oc->path, cp, sizeof(oc->path));
|
||||||
sizeof(oc->path));
|
|
||||||
oc->path[sizeof(oc->path)-1] = '\0';
|
|
||||||
|
|
||||||
if (!active_cache)
|
if (!active_cache)
|
||||||
read_cache();
|
read_cache();
|
||||||
@ -1443,9 +1441,7 @@ static int get_sha1_with_context_1(const char *name,
|
|||||||
name, len);
|
name, len);
|
||||||
}
|
}
|
||||||
hashcpy(oc->tree, tree_sha1);
|
hashcpy(oc->tree, tree_sha1);
|
||||||
strncpy(oc->path, filename,
|
strlcpy(oc->path, filename, sizeof(oc->path));
|
||||||
sizeof(oc->path));
|
|
||||||
oc->path[sizeof(oc->path)-1] = '\0';
|
|
||||||
|
|
||||||
free(new_filename);
|
free(new_filename);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user