]> git.ipfire.org Git - thirdparty/git.git/commit - diff.c
diff: handle sha1 abbreviations outside of repository
authorJeff King <peff@peff.net>
Thu, 20 Oct 2016 06:21:25 +0000 (02:21 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Oct 2016 20:30:51 +0000 (13:30 -0700)
commit4f03666ac69ec4799998f010d04916c12e38edf8
tree66b6e511bcabfb6d06417725714ed6f5f34c4198
parentd6cece51b83db5d8a523c4ba857013c4242e310e
diff: handle sha1 abbreviations outside of repository

When generating diffs outside a repository (e.g., with "diff
--no-index"), we may write abbreviated sha1s as part of
"--raw" output or the "index" lines of "--patch" output.
Since we have no object database, we never find any
collisions, and these sha1s get whatever static abbreviation
length is configured (typically 7).

However, we do blindly look in ".git/objects" to see if any
objects exist, even though we know we are not in a
repository. This is usually harmless because such a
directory is unlikely to exist, but could be wrong in rare
circumstances.

Let's instead notice when we are not in a repository and
behave as if the object database is empty (i.e., just use
the default abbrev length). It would perhaps make sense to
be conservative and show full sha1s in that case, but
showing the default abbreviation is what we've always done
(and is certainly less ugly).

Note that this does mean that:

  cd /not/a/repo
  GIT_OBJECT_DIRECTORY=/some/real/objdir git diff --no-index ...

used to look for collisions in /some/real/objdir but now
does not. This could be considered either a bugfix (we do
not look at objects if we have no repository) or a
regression, but it seems unlikely that anybody would care
much either way.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c