]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/diff: explicitly set hash algo when there is no repo
authorPatrick Steinhardt <ps@pks.im>
Tue, 7 May 2024 04:53:29 +0000 (06:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2024 05:50:49 +0000 (22:50 -0700)
commitab274909d440a43cc03f9f815e9f8d4bba705f1e
tree4edb8919a91091bb9d3b37cfce7b01ccd196f038
parent332b56b7623c641dbf2f7712e338c0ca2dd423be
builtin/diff: explicitly set hash algo when there is no repo

The git-diff(1) command can be used outside repositories to diff two
files with each other. But even if there is no repository we will end up
hashing the files that we are diffing so that we can print the "index"
line:

    ```
    diff --git a/a b/b
    index 7898192..6178079 100644
    --- a/a
    +++ b/b
    @@ -1 +1 @@
    -a
    +b
    ```

We implicitly use SHA1 to calculate the hash here, which is because
`the_repository` gets initialized with SHA1 during the startup routine.
We are about to stop doing this though such that `the_repository` only
ever has a hash function when it was properly initialized via a repo's
configuration.

To give full control to our users, we would ideally add a new switch to
git-diff(1) that allows them to specify the hash function when executed
outside of a repository. But for now, we only convert the code to make
this explicit such that we can stop setting the default hash algorithm
for `the_repository`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff.c