]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rs/use-skip-prefix-more'
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2019 23:09:22 +0000 (15:09 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2019 23:09:22 +0000 (15:09 -0800)
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()

builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/name-rev.c
builtin/push.c
shell.c

index 46ce7c2710c02b1f64a40bf8cf43bdd7d6280cdd..f8765b385b60f175844682df9ea7c1fcc7ac105e 100644 (file)
@@ -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;
index a4615587fd7929e8fb49e65dbda30a40b8599cfd..736f666f644c7cf78b816888ba226693464fc331 100644 (file)
@@ -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);
index b0f0776947f05e551f5bd06a4a0e291aa19a56f3..e55a4f04eea2357eae0989df872bea080d92b615 100644 (file)
@@ -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;
 }
 
index 843f5b22a208886d20d34097d7f8bdc103cf89f8..6dbf0f0bb713f167947e8d3d3aa0b8ecae0dc44e 100644 (file)
@@ -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",
diff --git a/shell.c b/shell.c
index 40084a30130ef844899bc1f3321285afdda82607..54cca7439de636daa37b7f8627c5cdd8bb431703 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -16,10 +16,10 @@ static int do_generic_cmd(const char *me, char *arg)
        setup_path();
        if (!arg || !(arg = sq_dequote(arg)) || *arg == '-')
                die("bad argument");
-       if (!starts_with(me, "git-"))
+       if (!skip_prefix(me, "git-", &me))
                die("bad command");
 
-       my_argv[0] = me + 4;
+       my_argv[0] = me;
        my_argv[1] = arg;
        my_argv[2] = NULL;