Skip to content

Commit a2124db

Browse files
committed
Merge branch 'rs/use-skip-prefix-more' into next
Code cleanup. * rs/use-skip-prefix-more: name-rev: use skip_prefix() instead of starts_with() push: use skip_prefix() instead of starts_with() shell: use skip_prefix() instead of starts_with() fmt-merge-msg: use skip_prefix() instead of starts_with() fetch: use skip_prefix() instead of starts_with()
2 parents 12e1a9e + 2059e79 commit a2124db

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

builtin/fetch.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -957,18 +957,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
957957
kind = "";
958958
what = "";
959959
}
960-
else if (starts_with(rm->name, "refs/heads/")) {
960+
else if (skip_prefix(rm->name, "refs/heads/", &what))
961961
kind = "branch";
962-
what = rm->name + 11;
963-
}
964-
else if (starts_with(rm->name, "refs/tags/")) {
962+
else if (skip_prefix(rm->name, "refs/tags/", &what))
965963
kind = "tag";
966-
what = rm->name + 10;
967-
}
968-
else if (starts_with(rm->name, "refs/remotes/")) {
964+
else if (skip_prefix(rm->name, "refs/remotes/", &what))
969965
kind = "remote-tracking branch";
970-
what = rm->name + 13;
971-
}
972966
else {
973967
kind = "";
974968
what = rm->name;

builtin/fmt-merge-msg.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
106106
int i, len = strlen(line);
107107
struct origin_data *origin_data;
108108
char *src;
109-
const char *origin;
109+
const char *origin, *tag_name;
110110
struct src_data *src_data;
111111
struct string_list_item *item;
112112
int pulling_head = 0;
@@ -162,14 +162,13 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
162162
if (pulling_head) {
163163
origin = src;
164164
src_data->head_status |= 1;
165-
} else if (starts_with(line, "branch ")) {
165+
} else if (skip_prefix(line, "branch ", &origin)) {
166166
origin_data->is_local_branch = 1;
167-
origin = line + 7;
168167
string_list_append(&src_data->branch, origin);
169168
src_data->head_status |= 2;
170-
} else if (starts_with(line, "tag ")) {
169+
} else if (skip_prefix(line, "tag ", &tag_name)) {
171170
origin = line;
172-
string_list_append(&src_data->tag, origin + 4);
171+
string_list_append(&src_data->tag, tag_name);
173172
src_data->head_status |= 2;
174173
} else if (skip_prefix(line, "remote-tracking branch ", &origin)) {
175174
string_list_append(&src_data->r_branch, origin);

builtin/name-rev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
161161
{
162162
if (shorten_unambiguous)
163163
refname = shorten_unambiguous_ref(refname, 0);
164-
else if (starts_with(refname, "refs/heads/"))
165-
refname = refname + 11;
166-
else if (starts_with(refname, "refs/"))
167-
refname = refname + 5;
164+
else if (skip_prefix(refname, "refs/heads/", &refname))
165+
; /* refname already advanced */
166+
else
167+
skip_prefix(refname, "refs/", &refname);
168168
return refname;
169169
}
170170

builtin/push.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;
6464
static const char *map_refspec(const char *ref,
6565
struct remote *remote, struct ref *local_refs)
6666
{
67+
const char *branch_name;
6768
struct ref *matched = NULL;
6869

6970
/* Does "ref" uniquely name our ref? */
@@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,
8485
}
8586

8687
if (push_default == PUSH_DEFAULT_UPSTREAM &&
87-
starts_with(matched->name, "refs/heads/")) {
88-
struct branch *branch = branch_get(matched->name + 11);
88+
skip_prefix(matched->name, "refs/heads/", &branch_name)) {
89+
struct branch *branch = branch_get(branch_name);
8990
if (branch->merge_nr == 1 && branch->merge[0]->src) {
9091
struct strbuf buf = STRBUF_INIT;
9192
strbuf_addf(&buf, "%s:%s",

shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ static int do_generic_cmd(const char *me, char *arg)
1616
setup_path();
1717
if (!arg || !(arg = sq_dequote(arg)) || *arg == '-')
1818
die("bad argument");
19-
if (!starts_with(me, "git-"))
19+
if (!skip_prefix(me, "git-", &me))
2020
die("bad command");
2121

22-
my_argv[0] = me + 4;
22+
my_argv[0] = me;
2323
my_argv[1] = arg;
2424
my_argv[2] = NULL;
2525

0 commit comments

Comments
 (0)