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. In0179ca7
(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 in0179ca7
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 <a.krey@gmx.de> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1b0b6dd072
commit
ffd036b128
@ -147,30 +147,6 @@ static int exclude_cb(const struct option *opt, const char *arg, int unset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 1 if the given path is the root of a git repository or
|
||||
* submodule else 0. Will not return 1 for bare repositories with the
|
||||
* exception of creating a bare repository in "foo/.git" and calling
|
||||
* is_git_repository("foo").
|
||||
*/
|
||||
static int is_git_repository(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; /* This could be a real .git file, take the
|
||||
* safe option and avoid cleaning */
|
||||
strbuf_setlen(path, orig_path_len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
|
||||
int dry_run, int quiet, int *dir_gone)
|
||||
{
|
||||
@ -182,7 +158,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
|
||||
|
||||
*dir_gone = 1;
|
||||
|
||||
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) && is_git_repository(path)) {
|
||||
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) && is_nonbare_repository_dir(path)) {
|
||||
if (!quiet) {
|
||||
quote_path_relative(path->buf, prefix, "ed);
|
||||
printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
|
||||
|
Reference in New Issue
Block a user