コード例 #1
0
ファイル: scan-tree.c プロジェクト: tim-nordell-lpd/cgit
static void scan_path(const char *base, const char *path, repo_config_fn fn)
{
	DIR *dir = opendir(path);
	struct dirent *ent;
	struct strbuf pathbuf = STRBUF_INIT;
	size_t pathlen = strlen(path);
	struct stat st;

	if (!dir) {
		fprintf(stderr, "Error opening directory %s: %s (%d)\n",
			path, strerror(errno), errno);
		return;
	}

	strbuf_add(&pathbuf, path, strlen(path));
	if (is_git_dir(pathbuf.buf)) {
		add_repo(base, &pathbuf, fn);
		goto end;
	}
	strbuf_addstr(&pathbuf, "/.git");
	if (is_git_dir(pathbuf.buf)) {
		add_repo(base, &pathbuf, fn);
		goto end;
	}
	/*
	 * Add one because we don't want to lose the trailing '/' when we
	 * reset the length of pathbuf in the loop below.
	 */
	pathlen++;
	while ((ent = readdir(dir)) != NULL) {
		if (ent->d_name[0] == '.') {
			if (ent->d_name[1] == '\0')
				continue;
			if (ent->d_name[1] == '.' && ent->d_name[2] == '\0')
				continue;
			if (!ctx.cfg.scan_hidden_path)
				continue;
		}
		strbuf_setlen(&pathbuf, pathlen);
		strbuf_addstr(&pathbuf, ent->d_name);
		if (stat(pathbuf.buf, &st)) {
			fprintf(stderr, "Error checking path %s: %s (%d)\n",
				pathbuf.buf, strerror(errno), errno);
			continue;
		}
		if (S_ISDIR(st.st_mode))
			scan_path(base, pathbuf.buf, fn);
	}
end:
	strbuf_release(&pathbuf);
	closedir(dir);
}
コード例 #2
0
ファイル: scan-tree.c プロジェクト: 5victor/cgit
static void scan_path(const char *base, const char *path, repo_config_fn fn)
{
	DIR *dir = opendir(path);
	struct dirent *ent;
	char *buf;
	struct stat st;

	if (!dir) {
		fprintf(stderr, "Error opening directory %s: %s (%d)\n",
			path, strerror(errno), errno);
		return;
	}
	if (is_git_dir(path)) {
		add_repo(base, path, fn);
		goto end;
	}
	if (is_git_dir(fmt("%s/.git", path))) {
		add_repo(base, fmt("%s/.git", path), fn);
		goto end;
	}
	while ((ent = readdir(dir)) != NULL) {
		if (ent->d_name[0] == '.') {
			if (ent->d_name[1] == '\0')
				continue;
			if (ent->d_name[1] == '.' && ent->d_name[2] == '\0')
				continue;
			if (!ctx.cfg.scan_hidden_path)
				continue;
		}
		buf = malloc(strlen(path) + strlen(ent->d_name) + 2);
		if (!buf) {
			fprintf(stderr, "Alloc error on %s: %s (%d)\n",
				path, strerror(errno), errno);
			exit(1);
		}
		sprintf(buf, "%s/%s", path, ent->d_name);
		if (stat(buf, &st)) {
			fprintf(stderr, "Error checking path %s: %s (%d)\n",
				buf, strerror(errno), errno);
			free(buf);
			continue;
		}
		if (S_ISDIR(st.st_mode))
			scan_path(base, buf, fn);
		free(buf);
	}
end:
	closedir(dir);
}
コード例 #3
0
ファイル: gitcore.cpp プロジェクト: ruhollahpython/gitManager
void gitCore::addDirectory(QString dir)
{
 is_git_dir(dir);
}