mirror of
https://github.com/git/git
synced 2024-09-17 23:41:33 +00:00
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:
commit
391fb22ac7
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
4
shell.c
4
shell.c
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue