Merge branch 'ms/send-pack-honor-config'
authorJunio C Hamano <gitster@pobox.com>
Thu, 28 Jun 2018 19:53:30 +0000 (12:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Jun 2018 19:53:30 +0000 (12:53 -0700)
"git send-pack --signed" (hence "git push --signed" over the http
transport) did not read user ident from the config mechanism to
determine whom to sign the push certificate as, which has been
corrected.

* ms/send-pack-honor-config:
builtin/send-pack: populate the default configs

1  2 
builtin/send-pack.c
diff --combined builtin/send-pack.c
index 4923b1058c667bd45282c0930e1089594a3f4731,997a8488957a469acdfa3ebae41f5ccf56ddc045..42fd8d1a3528c3ea0b30007407b2ae38f240f4c7
@@@ -14,7 -14,6 +14,7 @@@
  #include "sha1-array.h"
  #include "gpg-interface.h"
  #include "gettext.h"
 +#include "protocol.h"
  
  static const char * const send_pack_usage[] = {
        N_("git send-pack [--all | --mirror] [--dry-run] [--force] "
@@@ -121,12 -120,13 +121,12 @@@ static int send_pack_config(const char 
                        }
                }
        }
-       return 0;
+       return git_default_config(k, v, cb);
  }
  
  int cmd_send_pack(int argc, const char **argv, const char *prefix)
  {
 -      int i, nr_refspecs = 0;
 -      const char **refspecs = NULL;
 +      struct refspec rs = REFSPEC_INIT_PUSH;
        const char *remote_name = NULL;
        struct remote *remote = NULL;
        const char *dest = NULL;
        int progress = -1;
        int from_stdin = 0;
        struct push_cas_option cas = {0};
 +      struct packet_reader reader;
  
        struct option options[] = {
                OPT__VERBOSITY(&verbose),
        argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
        if (argc > 0) {
                dest = argv[0];
 -              refspecs = (const char **)(argv + 1);
 -              nr_refspecs = argc - 1;
 +              refspec_appendn(&rs, argv + 1, argc - 1);
        }
  
        if (!dest)
        args.push_options = push_options.nr ? &push_options : NULL;
  
        if (from_stdin) {
 -              struct argv_array all_refspecs = ARGV_ARRAY_INIT;
 -
 -              for (i = 0; i < nr_refspecs; i++)
 -                      argv_array_push(&all_refspecs, refspecs[i]);
 -
                if (args.stateless_rpc) {
                        const char *buf;
                        while ((buf = packet_read_line(0, NULL)))
 -                              argv_array_push(&all_refspecs, buf);
 +                              refspec_append(&rs, buf);
                } else {
                        struct strbuf line = STRBUF_INIT;
                        while (strbuf_getline(&line, stdin) != EOF)
 -                              argv_array_push(&all_refspecs, line.buf);
 +                              refspec_append(&rs, line.buf);
                        strbuf_release(&line);
                }
 -
 -              refspecs = all_refspecs.argv;
 -              nr_refspecs = all_refspecs.argc;
        }
  
        /*
         * --all and --mirror are incompatible; neither makes sense
         * with any refspecs.
         */
 -      if ((nr_refspecs > 0 && (send_all || args.send_mirror)) ||
 +      if ((rs.nr > 0 && (send_all || args.send_mirror)) ||
            (send_all && args.send_mirror))
                usage_with_options(send_pack_usage, options);
  
                        args.verbose ? CONNECT_VERBOSE : 0);
        }
  
 -      get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL,
 -                       &extra_have, &shallow);
 -
 -      transport_verify_remote_names(nr_refspecs, refspecs);
 +      packet_reader_init(&reader, fd[0], NULL, 0,
 +                         PACKET_READ_CHOMP_NEWLINE |
 +                         PACKET_READ_GENTLE_ON_EOF);
 +
 +      switch (discover_version(&reader)) {
 +      case protocol_v2:
 +              die("support for protocol v2 not implemented yet");
 +              break;
 +      case protocol_v1:
 +      case protocol_v0:
 +              get_remote_heads(&reader, &remote_refs, REF_NORMAL,
 +                               &extra_have, &shallow);
 +              break;
 +      case protocol_unknown_version:
 +              BUG("unknown protocol version");
 +      }
  
        local_refs = get_local_heads();
  
                flags |= MATCH_REFS_MIRROR;
  
        /* match them up */
 -      if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags))
 +      if (match_push_refs(local_refs, &remote_refs, &rs, flags))
                return -1;
  
        if (!is_empty_cas(&cas))