Merge branch 'jc/skip-prefix'
Code simplification. * jc/skip-prefix: C: use skip_prefix() to avoid hardcoded string length
This commit is contained in:
commit
44cba9c4b3
@ -870,8 +870,7 @@ static void handle_tag(const char *name, struct tag *tag)
|
||||
printf("reset %s\nfrom %s\n\n",
|
||||
name, oid_to_hex(&null_oid));
|
||||
}
|
||||
if (starts_with(name, "refs/tags/"))
|
||||
name += 10;
|
||||
skip_prefix(name, "refs/tags/", &name);
|
||||
printf("tag %s\n", name);
|
||||
if (mark_tags) {
|
||||
mark_next_object(&tag->object);
|
||||
|
@ -560,15 +560,16 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
|
||||
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
|
||||
flags |= EXPIRE_REFLOGS_DRY_RUN;
|
||||
else if (starts_with(arg, "--expire=")) {
|
||||
if (parse_expiry_date(arg + 9, &cb.cmd.expire_total))
|
||||
else if (skip_prefix(arg, "--expire=", &arg)) {
|
||||
if (parse_expiry_date(arg, &cb.cmd.expire_total))
|
||||
die(_("'%s' is not a valid timestamp"), arg);
|
||||
explicit_expiry |= EXPIRE_TOTAL;
|
||||
}
|
||||
else if (starts_with(arg, "--expire-unreachable=")) {
|
||||
if (parse_expiry_date(arg + 21, &cb.cmd.expire_unreachable))
|
||||
else if (skip_prefix(arg, "--expire-unreachable=", &arg)) {
|
||||
if (parse_expiry_date(arg, &cb.cmd.expire_unreachable))
|
||||
die(_("'%s' is not a valid timestamp"), arg);
|
||||
explicit_expiry |= EXPIRE_UNREACH;
|
||||
}
|
||||
|
6
notes.c
6
notes.c
@ -1279,10 +1279,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
|
||||
if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
|
||||
strbuf_addstr(sb, "\nNotes:\n");
|
||||
} else {
|
||||
if (starts_with(ref, "refs/"))
|
||||
ref += 5;
|
||||
if (starts_with(ref, "notes/"))
|
||||
ref += 6;
|
||||
skip_prefix(ref, "refs/", &ref);
|
||||
skip_prefix(ref, "notes/", &ref);
|
||||
strbuf_addf(sb, "\nNotes (%s):\n", ref);
|
||||
}
|
||||
}
|
||||
|
@ -357,8 +357,7 @@ is_abbreviated:
|
||||
}
|
||||
/* negated? */
|
||||
if (!starts_with(arg, "no-")) {
|
||||
if (starts_with(long_name, "no-")) {
|
||||
long_name += 3;
|
||||
if (skip_prefix(long_name, "no-", &long_name)) {
|
||||
opt_flags |= OPT_UNSET;
|
||||
goto again;
|
||||
}
|
||||
|
@ -465,8 +465,7 @@ stat_ref:
|
||||
close(fd);
|
||||
strbuf_rtrim(&sb_contents);
|
||||
buf = sb_contents.buf;
|
||||
if (starts_with(buf, "ref:")) {
|
||||
buf += 4;
|
||||
if (skip_prefix(buf, "ref:", &buf)) {
|
||||
while (isspace(*buf))
|
||||
buf++;
|
||||
|
||||
|
@ -1255,8 +1255,9 @@ static void parse_push(struct strbuf *buf)
|
||||
int ret;
|
||||
|
||||
do {
|
||||
if (starts_with(buf->buf, "push "))
|
||||
argv_array_push(&specs, buf->buf + 5);
|
||||
const char *arg;
|
||||
if (skip_prefix(buf->buf, "push ", &arg))
|
||||
argv_array_push(&specs, arg);
|
||||
else
|
||||
die(_("http transport does not support %s"), buf->buf);
|
||||
|
||||
|
@ -908,14 +908,9 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
|
||||
real_ref, flags, at_time, nth, oid, NULL,
|
||||
&co_time, &co_tz, &co_cnt)) {
|
||||
if (!len) {
|
||||
if (starts_with(real_ref, "refs/heads/")) {
|
||||
str = real_ref + 11;
|
||||
len = strlen(real_ref + 11);
|
||||
} else {
|
||||
/* detached HEAD */
|
||||
if (!skip_prefix(real_ref, "refs/heads/", &str))
|
||||
str = "HEAD";
|
||||
len = 4;
|
||||
}
|
||||
len = strlen(str);
|
||||
}
|
||||
if (at_time) {
|
||||
if (!(flags & GET_OID_QUIETLY)) {
|
||||
|
@ -404,11 +404,12 @@ static int fetch_with_fetch(struct transport *transport,
|
||||
sendline(data, &buf);
|
||||
|
||||
while (1) {
|
||||
const char *name;
|
||||
|
||||
if (recvline(data, &buf))
|
||||
exit(128);
|
||||
|
||||
if (starts_with(buf.buf, "lock ")) {
|
||||
const char *name = buf.buf + 5;
|
||||
if (skip_prefix(buf.buf, "lock ", &name)) {
|
||||
if (transport->pack_lockfile)
|
||||
warning(_("%s also locked %s"), data->name, name);
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user