]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ps/ls-remote-out-of-repo-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)
A recent update broke "git ls-remote" used outside a repository,
which has been corrected.

* ps/ls-remote-out-of-repo-fix:
  builtin/ls-remote: fall back to SHA1 outside of a repo

1  2 
builtin/ls-remote.c
t/t5512-ls-remote.sh

index 5b61af5d789b543057dff4d83aa3e08fed1d79fd,6da63a67f569eb5351d29ce2b270b4edb1f36982..0a491595ca831c3caeb9721efd322f3027c1983d
@@@ -90,10 -91,30 +90,25 @@@ int cmd_ls_remote(int argc, const char 
                             PARSE_OPT_STOP_AT_NON_OPTION);
        dest = argv[0];
  
+       /*
+        * TODO: This is buggy, but required for transport helpers. When a
+        * transport helper advertises a "refspec", then we'd add that to a
+        * list of refspecs via `refspec_append()`, which transitively depends
+        * on `the_hash_algo`. Thus, when the hash algorithm isn't properly set
+        * up, this would lead to a segfault.
+        *
+        * We really should fix this in the transport helper logic such that we
+        * lazily parse refspec capabilities _after_ we have learned about the
+        * remote's object format. Otherwise, we may end up misparsing refspecs
+        * depending on what object hash the remote uses.
+        */
+       if (!the_repository->hash_algo)
+               repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
        packet_trace_identity("ls-remote");
  
 -      if (argc > 1) {
 -              int i;
 -              CALLOC_ARRAY(pattern, argc);
 -              for (i = 1; i < argc; i++) {
 -                      pattern[i - 1] = xstrfmt("*/%s", argv[i]);
 -              }
 -      }
 +      for (int i = 1; i < argc; i++)
 +              strvec_pushf(&pattern, "*/%s", argv[i]);
  
        if (flags & REF_TAGS)
                strvec_push(&transport_options.ref_prefixes, "refs/tags/");
Simple merge