]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/ls-remote: initialize repository based on fetch
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 25 May 2020 19:59:19 +0000 (19:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 May 2020 17:07:07 +0000 (10:07 -0700)
ls-remote may or may not operate within a repository, and as such will
not have been initialized with the repository's hash algorithm.  Even if
it were, the remote side could be using a different algorithm and we
would still want to display those refs properly.  Find the hash
algorithm used by the remote side by querying the transport object and
set our hash algorithm accordingly.

Without this change, if the remote side is using SHA-256, we truncate
the refs to 40 hex characters, since that's the length of the default
hash algorithm (SHA-1).

Note that technically this is not a correct setting of the repository
hash algorithm since, if we are in a repository, it might be one of a
different hash algorithm from the remote side.  However, our current
code paths don't handle multiple algorithms and won't for some time, so
this is the best we can do.  We rely on the fact that ls-remote never
modifies the current repository, which is a reasonable assumption to
make.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-remote.c

index 6ef519514bd1a4dfc39b149967ee60dcf14dfbaa..3a4dd12903206ae47fd4683e3bef1a7371d67d55 100644 (file)
@@ -118,6 +118,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                transport->server_options = &server_options;
 
        ref = transport_get_remote_refs(transport, &ref_prefixes);
+       if (ref) {
+               int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
+               repo_set_hash_algo(the_repository, hash_algo);
+       }
        if (transport_disconnect(transport)) {
                UNLEAK(sorting);
                return 1;