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()
This commit is contained in:
Junio C Hamano 2019-12-06 15:09:22 -08:00
commit 391fb22ac7
5 changed files with 16 additions and 22 deletions

View file

@ -957,18 +957,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
kind = ""; kind = "";
what = ""; what = "";
} }
else if (starts_with(rm->name, "refs/heads/")) { else if (skip_prefix(rm->name, "refs/heads/", &what))
kind = "branch"; kind = "branch";
what = rm->name + 11; else if (skip_prefix(rm->name, "refs/tags/", &what))
}
else if (starts_with(rm->name, "refs/tags/")) {
kind = "tag"; kind = "tag";
what = rm->name + 10; else if (skip_prefix(rm->name, "refs/remotes/", &what))
}
else if (starts_with(rm->name, "refs/remotes/")) {
kind = "remote-tracking branch"; kind = "remote-tracking branch";
what = rm->name + 13;
}
else { else {
kind = ""; kind = "";
what = rm->name; what = rm->name;

View file

@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
int i, len = strlen(line); int i, len = strlen(line);
struct origin_data *origin_data; struct origin_data *origin_data;
char *src; char *src;
const char *origin; const char *origin, *tag_name;
struct src_data *src_data; struct src_data *src_data;
struct string_list_item *item; struct string_list_item *item;
int pulling_head = 0; int pulling_head = 0;
@ -162,14 +162,13 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
if (pulling_head) { if (pulling_head) {
origin = src; origin = src;
src_data->head_status |= 1; 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_data->is_local_branch = 1;
origin = line + 7;
string_list_append(&src_data->branch, origin); string_list_append(&src_data->branch, origin);
src_data->head_status |= 2; src_data->head_status |= 2;
} else if (starts_with(line, "tag ")) { } else if (skip_prefix(line, "tag ", &tag_name)) {
origin = line; origin = line;
string_list_append(&src_data->tag, origin + 4); string_list_append(&src_data->tag, tag_name);
src_data->head_status |= 2; src_data->head_status |= 2;
} else if (skip_prefix(line, "remote-tracking branch ", &origin)) { } else if (skip_prefix(line, "remote-tracking branch ", &origin)) {
string_list_append(&src_data->r_branch, origin); string_list_append(&src_data->r_branch, origin);

View file

@ -161,10 +161,10 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
{ {
if (shorten_unambiguous) if (shorten_unambiguous)
refname = shorten_unambiguous_ref(refname, 0); refname = shorten_unambiguous_ref(refname, 0);
else if (starts_with(refname, "refs/heads/")) else if (skip_prefix(refname, "refs/heads/", &refname))
refname = refname + 11; ; /* refname already advanced */
else if (starts_with(refname, "refs/")) else
refname = refname + 5; skip_prefix(refname, "refs/", &refname);
return refname; return refname;
} }

View file

@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;
static const char *map_refspec(const char *ref, static const char *map_refspec(const char *ref,
struct remote *remote, struct ref *local_refs) struct remote *remote, struct ref *local_refs)
{ {
const char *branch_name;
struct ref *matched = NULL; struct ref *matched = NULL;
/* Does "ref" uniquely name our ref? */ /* Does "ref" uniquely name our ref? */
@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,
} }
if (push_default == PUSH_DEFAULT_UPSTREAM && if (push_default == PUSH_DEFAULT_UPSTREAM &&
starts_with(matched->name, "refs/heads/")) { skip_prefix(matched->name, "refs/heads/", &branch_name)) {
struct branch *branch = branch_get(matched->name + 11); struct branch *branch = branch_get(branch_name);
if (branch->merge_nr == 1 && branch->merge[0]->src) { if (branch->merge_nr == 1 && branch->merge[0]->src) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "%s:%s", strbuf_addf(&buf, "%s:%s",

View file

@ -16,10 +16,10 @@ static int do_generic_cmd(const char *me, char *arg)
setup_path(); setup_path();
if (!arg || !(arg = sq_dequote(arg)) || *arg == '-') if (!arg || !(arg = sq_dequote(arg)) || *arg == '-')
die("bad argument"); die("bad argument");
if (!starts_with(me, "git-")) if (!skip_prefix(me, "git-", &me))
die("bad command"); die("bad command");
my_argv[0] = me + 4; my_argv[0] = me;
my_argv[1] = arg; my_argv[1] = arg;
my_argv[2] = NULL; my_argv[2] = NULL;