clone: factor out dir_exists() helper
authorJeff King <peff@peff.net>
Tue, 2 Jan 2018 21:10:14 +0000 (16:10 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Jan 2018 21:33:05 +0000 (13:33 -0800)
commitf9e377adc0b1ed06e35d2c77a6c9f2687c5b950b
treecb29b25bdd12900c391055777544d44134e82802
parent8486b84f0ea4d7f943fdbe81050553d69d198742
clone: factor out dir_exists() helper

Two parts of git-clone's setup logic check whether a
directory exists, and they both call stat directly with the
same scratch "struct stat" buffer. Let's pull that into a
helper, which has a few advantages:

  - it makes the purpose of the stat calls more obvious

  - it makes it clear that we don't care about the
    information in "buf" remaining valid

  - if we later decide to make the check more robust (e.g.,
    complaining about non-directories), we can do it in one
    place

Note that we could just use file_exists() for this, which
has identical code. But we specifically care about
directories, so this future-proofs us against that function
later getting more picky about seeing actual files.

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