diff options
author | 2019-12-06 15:09:22 -0800 | |
---|---|---|
committer | 2019-12-06 15:09:22 -0800 | |
commit | 391fb22ac760042fd1cffe451f4ec9a4eb57e39e (patch) | |
tree | a933c90fefc73a2e6625ceec79043330b870c128 /builtin | |
parent | Merge branch 'rs/simplify-prepare-cmd' (diff) | |
parent | name-rev: use skip_prefix() instead of starts_with() (diff) | |
download | tgif-391fb22ac760042fd1cffe451f4ec9a4eb57e39e.tar.xz |
Merge branch 'rs/use-skip-prefix-more'
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()
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/fetch.c | 12 | ||||
-rw-r--r-- | builtin/fmt-merge-msg.c | 9 | ||||
-rw-r--r-- | builtin/name-rev.c | 8 | ||||
-rw-r--r-- | builtin/push.c | 5 |
4 files changed, 14 insertions, 20 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index 46ce7c2710..f8765b385b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -957,18 +957,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, kind = ""; what = ""; } - else if (starts_with(rm->name, "refs/heads/")) { + else if (skip_prefix(rm->name, "refs/heads/", &what)) kind = "branch"; - what = rm->name + 11; - } - else if (starts_with(rm->name, "refs/tags/")) { + else if (skip_prefix(rm->name, "refs/tags/", &what)) kind = "tag"; - what = rm->name + 10; - } - else if (starts_with(rm->name, "refs/remotes/")) { + else if (skip_prefix(rm->name, "refs/remotes/", &what)) kind = "remote-tracking branch"; - what = rm->name + 13; - } else { kind = ""; what = rm->name; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index a4615587fd..736f666f64 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents) int i, len = strlen(line); struct origin_data *origin_data; char *src; - const char *origin; + const char *origin, *tag_name; struct src_data *src_data; struct string_list_item *item; int pulling_head = 0; @@ -162,14 +162,13 @@ static int handle_line(char *line, struct merge_parents *merge_parents) if (pulling_head) { origin = src; src_data->head_status |= 1; - } else if (starts_with(line, "branch ")) { + } else if (skip_prefix(line, "branch ", &origin)) { origin_data->is_local_branch = 1; - origin = line + 7; string_list_append(&src_data->branch, origin); src_data->head_status |= 2; - } else if (starts_with(line, "tag ")) { + } else if (skip_prefix(line, "tag ", &tag_name)) { origin = line; - string_list_append(&src_data->tag, origin + 4); + string_list_append(&src_data->tag, tag_name); src_data->head_status |= 2; } else if (skip_prefix(line, "remote-tracking branch ", &origin)) { string_list_append(&src_data->r_branch, origin); diff --git a/builtin/name-rev.c b/builtin/name-rev.c index b0f0776947..e55a4f04ee 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -161,10 +161,10 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous) { if (shorten_unambiguous) refname = shorten_unambiguous_ref(refname, 0); - else if (starts_with(refname, "refs/heads/")) - refname = refname + 11; - else if (starts_with(refname, "refs/")) - refname = refname + 5; + else if (skip_prefix(refname, "refs/heads/", &refname)) + ; /* refname already advanced */ + else + skip_prefix(refname, "refs/", &refname); return refname; } diff --git a/builtin/push.c b/builtin/push.c index 843f5b22a2..6dbf0f0bb7 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP; static const char *map_refspec(const char *ref, struct remote *remote, struct ref *local_refs) { + const char *branch_name; struct ref *matched = NULL; /* Does "ref" uniquely name our ref? */ @@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref, } if (push_default == PUSH_DEFAULT_UPSTREAM && - starts_with(matched->name, "refs/heads/")) { - struct branch *branch = branch_get(matched->name + 11); + skip_prefix(matched->name, "refs/heads/", &branch_name)) { + struct branch *branch = branch_get(branch_name); if (branch->merge_nr == 1 && branch->merge[0]->src) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s:%s", |