]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/string-list-cleanup' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 11 Aug 2022 04:52:36 +0000 (21:52 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Aug 2022 04:52:36 +0000 (21:52 -0700)
Code clean-up.
source: <xmqq7d471dns.fsf@gitster.g>

* jc/string-list-cleanup:
  builtin/remote.c: use the right kind of STRING_LIST_INIT

1  2 
builtin/remote.c

diff --combined builtin/remote.c
index d4b69fe77898977d4b4dead8059c667ee17110cd,ac3ab4495b09bd3a17a4933816ce4d41d8592f2a..a3a0c27d7a09da9f5df1f258d3c21fe426690ea0
  #include "object-store.h"
  #include "strvec.h"
  #include "commit-reach.h"
 +#include "progress.h"
  
  static const char * const builtin_remote_usage[] = {
 -      N_("git remote [-v | --verbose]"),
 +      "git remote [-v | --verbose]",
        N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"),
 -      N_("git remote rename <old> <new>"),
 +      N_("git remote rename [--[no-]progress] <old> <new>"),
        N_("git remote remove <name>"),
        N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"),
        N_("git remote [-v | --verbose] show [-n] <name>"),
@@@ -37,7 -36,7 +37,7 @@@ static const char * const builtin_remot
  };
  
  static const char * const builtin_remote_rename_usage[] = {
 -      N_("git remote rename <old> <new>"),
 +      N_("git remote rename [--[no-]progress] <old> <new>"),
        NULL
  };
  
@@@ -572,7 -571,6 +572,7 @@@ struct rename_info 
        const char *old_name;
        const char *new_name;
        struct string_list *remote_branches;
 +      uint32_t symrefs_nr;
  };
  
  static int read_remote_branches(const char *refname,
                item = string_list_append(rename->remote_branches, refname);
                symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
                                            NULL, &flag);
 -              if (symref && (flag & REF_ISSYMREF))
 +              if (symref && (flag & REF_ISSYMREF)) {
                        item->util = xstrdup(symref);
 -              else
 +                      rename->symrefs_nr++;
 +              } else {
                        item->util = NULL;
 +              }
        }
        strbuf_release(&buf);
  
@@@ -678,9 -674,7 +678,9 @@@ static void handle_push_default(const c
  
  static int mv(int argc, const char **argv)
  {
 +      int show_progress = isatty(2);
        struct option options[] = {
 +              OPT_BOOL(0, "progress", &show_progress, N_("force progress reporting")),
                OPT_END()
        };
        struct remote *oldremote, *newremote;
                old_remote_context = STRBUF_INIT;
        struct string_list remote_branches = STRING_LIST_INIT_DUP;
        struct rename_info rename;
 -      int i, refspec_updated = 0;
 +      int i, refs_renamed_nr = 0, refspec_updated = 0;
 +      struct progress *progress = NULL;
 +
 +      argc = parse_options(argc, argv, NULL, options,
 +                           builtin_remote_rename_usage, 0);
  
 -      if (argc != 3)
 +      if (argc != 2)
                usage_with_options(builtin_remote_rename_usage, options);
  
 -      rename.old_name = argv[1];
 -      rename.new_name = argv[2];
 +      rename.old_name = argv[0];
 +      rename.new_name = argv[1];
        rename.remote_branches = &remote_branches;
 +      rename.symrefs_nr = 0;
  
        oldremote = remote_get(rename.old_name);
        if (!remote_is_configured(oldremote, 1)) {
         * the new symrefs.
         */
        for_each_ref(read_remote_branches, &rename);
 +      if (show_progress) {
 +              /*
 +               * Count symrefs twice, since "renaming" them is done by
 +               * deleting and recreating them in two separate passes.
 +               */
 +              progress = start_progress(_("Renaming remote references"),
 +                                        rename.remote_branches->nr + rename.symrefs_nr);
 +      }
        for (i = 0; i < remote_branches.nr; i++) {
                struct string_list_item *item = remote_branches.items + i;
 -              int flag = 0;
 +              struct strbuf referent = STRBUF_INIT;
  
 -              read_ref_full(item->string, RESOLVE_REF_READING, NULL, &flag);
 -              if (!(flag & REF_ISSYMREF))
 +              if (refs_read_symbolic_ref(get_main_ref_store(the_repository), item->string,
 +                                         &referent))
                        continue;
                if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
                        die(_("deleting '%s' failed"), item->string);
 +
 +              strbuf_release(&referent);
 +              display_progress(progress, ++refs_renamed_nr);
        }
        for (i = 0; i < remote_branches.nr; i++) {
                struct string_list_item *item = remote_branches.items + i;
                                item->string, buf.buf);
                if (rename_ref(item->string, buf.buf, buf2.buf))
                        die(_("renaming '%s' failed"), item->string);
 +              display_progress(progress, ++refs_renamed_nr);
        }
        for (i = 0; i < remote_branches.nr; i++) {
                struct string_list_item *item = remote_branches.items + i;
                                item->string, buf.buf);
                if (create_symref(buf.buf, buf2.buf, buf3.buf))
                        die(_("creating '%s' failed"), buf.buf);
 +              display_progress(progress, ++refs_renamed_nr);
        }
 +      stop_progress(&progress);
        string_list_clear(&remote_branches, 1);
  
        handle_push_default(rename.old_name, rename.new_name);
@@@ -1185,22 -1160,14 +1185,22 @@@ static int show_push_info_item(struct s
  static int get_one_entry(struct remote *remote, void *priv)
  {
        struct string_list *list = priv;
 -      struct strbuf url_buf = STRBUF_INIT;
 +      struct strbuf remote_info_buf = STRBUF_INIT;
        const char **url;
        int i, url_nr;
  
        if (remote->url_nr > 0) {
 -              strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
 +              struct strbuf promisor_config = STRBUF_INIT;
 +              const char *partial_clone_filter = NULL;
 +
 +              strbuf_addf(&promisor_config, "remote.%s.partialclonefilter", remote->name);
 +              strbuf_addf(&remote_info_buf, "%s (fetch)", remote->url[0]);
 +              if (!git_config_get_string_tmp(promisor_config.buf, &partial_clone_filter))
 +                      strbuf_addf(&remote_info_buf, " [%s]", partial_clone_filter);
 +
 +              strbuf_release(&promisor_config);
                string_list_append(list, remote->name)->util =
 -                              strbuf_detach(&url_buf, NULL);
 +                              strbuf_detach(&remote_info_buf, NULL);
        } else
                string_list_append(list, remote->name)->util = NULL;
        if (remote->pushurl_nr) {
        }
        for (i = 0; i < url_nr; i++)
        {
 -              strbuf_addf(&url_buf, "%s (push)", url[i]);
 +              strbuf_addf(&remote_info_buf, "%s (push)", url[i]);
                string_list_append(list, remote->name)->util =
 -                              strbuf_detach(&url_buf, NULL);
 +                              strbuf_detach(&remote_info_buf, NULL);
        }
  
        return 0;
  
  static int show_all(void)
  {
-       struct string_list list = STRING_LIST_INIT_NODUP;
+       struct string_list list = STRING_LIST_INIT_DUP;
        int result;
  
-       list.strdup_strings = 1;
        result = for_each_remote(get_one_entry, &list);
  
        if (!result) {