From ffd036b1286687589f5ce5513ee69c06ee53691e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 22 Jan 2016 17:27:33 -0500 Subject: clean: make is_git_repository a public function We have always had is_git_directory(), for looking at a specific directory to see if it contains a git repo. In 0179ca7 (clean: improve performance when removing lots of directories, 2015-06-15), we added is_git_repository() which checks for a non-bare repository by looking at its ".git" entry. However, the fix in 0179ca7 needs to be applied other places, too. Let's make this new helper globally available. We need to give it a better name, though, to avoid confusion with is_git_directory(). This patch does that, documents both functions with a comment to reduce confusion, and removes the clean-specific references in the comments. Based-on-a-patch-by: Andreas Krey Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- setup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'setup.c') diff --git a/setup.c b/setup.c index d34372520b..2c4b22c845 100644 --- a/setup.c +++ b/setup.c @@ -312,6 +312,23 @@ done: return ret; } +int is_nonbare_repository_dir(struct strbuf *path) +{ + int ret = 0; + int gitfile_error; + size_t orig_path_len = path->len; + assert(orig_path_len != 0); + strbuf_complete(path, '/'); + strbuf_addstr(path, ".git"); + if (read_gitfile_gently(path->buf, &gitfile_error) || is_git_directory(path->buf)) + ret = 1; + if (gitfile_error == READ_GITFILE_ERR_OPEN_FAILED || + gitfile_error == READ_GITFILE_ERR_READ_FAILED) + ret = 1; + strbuf_setlen(path, orig_path_len); + return ret; +} + int is_inside_git_dir(void) { if (inside_git_dir < 0) -- cgit v1.2.1