* Rename char *remote to remote_name to distinguish it clearly from the struct remote pointer, also named remote. * There is no need to call sort_string_list() on branch_list, as its items are added to it via string_list_insert() which maintains its order. * Sort states->new and states->tracked so that we can use binary search string_list_has_string() on them instead of less efficient linear unsorted_string_list_has_string. This alters the output of "remote show" slightly, so update the tests to match. * Simplify get_ref_states(); nothing is using the pointer to states that is being copied into util. * Have get_remote_ref_states() populate states->tracked even when it is not querying the remote so that this need not be done by the caller. Signed-off-by: Jay Soffian <jaysoffian@xxxxxxxxx> --- I added a function prototype for get_remote_ref_states() so I didn't need to move its location in this diff, which kept the diff cleaner. The next patch then moves the function and gets rid of the prototype. builtin-remote.c | 45 ++++++++++++++++++++++----------------------- t/t5505-remote.sh | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/builtin-remote.c b/builtin-remote.c index d6958d4..ea5e808 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -23,6 +23,9 @@ static int verbose; static int show_all(void); +static int append_ref_to_tracked_list(const char *refname, + const unsigned char *sha1, int flags, void *cb_data); + static inline int postfixcmp(const char *string, const char *postfix) { int len1 = strlen(string), len2 = strlen(postfix); @@ -144,7 +147,7 @@ static int add(int argc, const char **argv) } struct branch_info { - char *remote; + char *remote_name; struct string_list merge; }; @@ -183,9 +186,9 @@ static int config_read_branches(const char *key, const char *value, void *cb) item->util = xcalloc(sizeof(struct branch_info), 1); info = item->util; if (type == REMOTE) { - if (info->remote) + if (info->remote_name) warning("more than one branch.%s", key); - info->remote = xstrdup(value); + info->remote_name = xstrdup(value); } else { char *space = strchr(value, ' '); value = abbrev_branch(value); @@ -207,7 +210,6 @@ static void read_branches(void) if (branch_list.nr) return; git_config(config_read_branches, NULL); - sort_string_list(&branch_list); } struct ref_states { @@ -228,10 +230,8 @@ static int handle_one_branch(const char *refname, const char *name = abbrev_branch(refspec.src); /* symbolic refs pointing nowhere were handled already */ if ((flags & REF_ISSYMREF) || - unsorted_string_list_has_string(&states->tracked, - name) || - unsorted_string_list_has_string(&states->new, - name)) + string_list_has_string(&states->tracked, name) || + string_list_has_string(&states->new, name)) return 0; item = string_list_append(name, &states->stale); item->util = xstrdup(refname); @@ -251,21 +251,16 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states) states->new.strdup_strings = states->tracked.strdup_strings = 1; for (ref = fetch_map; ref; ref = ref->next) { - struct string_list *target = &states->tracked; unsigned char sha1[20]; - void *util = NULL; - if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1)) - target = &states->new; - else { - target = &states->tracked; - if (hashcmp(sha1, ref->new_sha1)) - util = &states; - } - string_list_append(abbrev_branch(ref->name), target)->util = util; + string_list_append(abbrev_branch(ref->name), &states->new); + else + string_list_append(abbrev_branch(ref->name), &states->tracked); } free_refs(fetch_map); + sort_string_list(&states->new); + sort_string_list(&states->tracked); for_each_ref(handle_one_branch, states); sort_string_list(&states->stale); @@ -490,7 +485,7 @@ static int mv(int argc, const char **argv) for (i = 0; i < branch_list.nr; i++) { struct string_list_item *item = branch_list.items + i; struct branch_info *info = item->util; - if (info->remote && !strcmp(info->remote, rename.old)) { + if (info->remote_name && !strcmp(info->remote_name, rename.old)) { strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.remote", item->string); if (git_config_set(buf.buf, rename.new)) { @@ -600,7 +595,7 @@ static int rm(int argc, const char **argv) for (i = 0; i < branch_list.nr; i++) { struct string_list_item *item = branch_list.items + i; struct branch_info *info = item->util; - if (info->remote && !strcmp(info->remote, remote->name)) { + if (info->remote_name && !strcmp(info->remote_name, remote->name)) { const char *keys[] = { "remote", "merge", NULL }, **k; for (k = keys; *k; k++) { strbuf_reset(&buf); @@ -685,6 +680,9 @@ static int get_remote_ref_states(const char *name, get_head_names(ref, name, states); get_ref_states(ref, states); + } else { + for_each_ref(append_ref_to_tracked_list, states); + sort_string_list(&states->tracked); } return 0; @@ -696,6 +694,9 @@ static int append_ref_to_tracked_list(const char *refname, struct ref_states *states = cb_data; struct refspec refspec; + if (flags & REF_ISSYMREF) + return 0; + memset(&refspec, 0, sizeof(refspec)); refspec.dst = (char *)refname; if (!remote_find_tracking(states->remote, &refspec)) @@ -743,7 +744,7 @@ static int show(int argc, const char **argv) struct branch_info *info = branch->util; int j; - if (!info->merge.nr || strcmp(*argv, info->remote)) + if (!info->merge.nr || strcmp(*argv, info->remote_name)) continue; printf(" Remote branch%s merged with 'git pull' " "while on branch %s\n ", @@ -762,8 +763,6 @@ static int show(int argc, const char **argv) "prune')", &states.stale, ""); } - if (no_query) - for_each_ref(append_ref_to_tracked_list, &states); show_list(" Tracked remote branch%s", &states.tracked, ""); if (states.remote->push_refspec_nr) { diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 104433d..fdc4a29 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -142,8 +142,8 @@ cat > test/expect << EOF New remote branch (next fetch will store in remotes/origin) master Tracked remote branches - side master + side Local branches pushed with 'git push' master:upstream +refs/tags/lastbackup -- 1.6.2.rc1.218.g1b4fab -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html