summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 10708a9)
raw | patch | inline | side by side (parent: 10708a9)
author | Junio C Hamano <gitster@pobox.com> | |
Tue, 9 Sep 2008 08:27:07 +0000 (01:27 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 9 Sep 2008 16:27:45 +0000 (09:27 -0700) |
A simple "grep -e stat --and -e S_ISDIR" revealed there are many
open-coded implementations of this function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
open-coded implementations of this function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
abspath.c | patch | blob | history | |
builtin-clone.c | patch | blob | history | |
cache.h | patch | blob | history | |
daemon.c | patch | blob | history | |
rerere.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
diff --git a/abspath.c b/abspath.c
index 0d561246e0a958d9a7284409b1900a82876eebf3..8194ce1256525105d07eedf2f964ad51d9162d95 100644 (file)
--- a/abspath.c
+++ b/abspath.c
#include "cache.h"
+/*
+ * Do not use this for inspecting *tracked* content. When path is a
+ * symlink to a directory, we do not want to say it is a directory when
+ * dealing with tracked content in the working tree.
+ */
+int is_directory(const char *path)
+{
+ struct stat st;
+ return (!stat(path, &st) && S_ISDIR(st.st_mode));
+}
+
/* We allow "recursive" symbolic links. Only within reason, though. */
#define MAXDEPTH 5
die ("Too long path: %.*s", 60, path);
while (depth--) {
- if (stat(buf, &st) || !S_ISDIR(st.st_mode)) {
+ if (!is_directory(buf)) {
char *last_slash = strrchr(buf, '/');
if (last_slash) {
*last_slash = '\0';
diff --git a/builtin-clone.c b/builtin-clone.c
index c8435295cedd920f34a13ec686c73d6b835b28ee..a4b87904fc7ad387cf5748327186ec23e2164829 100644 (file)
--- a/builtin-clone.c
+++ b/builtin-clone.c
for (i = 0; i < ARRAY_SIZE(suffix); i++) {
const char *path;
path = mkpath("%s%s", repo, suffix[i]);
- if (!stat(path, &st) && S_ISDIR(st.st_mode)) {
+ if (is_directory(path)) {
*is_bundle = 0;
return xstrdup(make_nonrelative_path(path));
}
return xstrndup(start, end - start);
}
-static int is_directory(const char *path)
-{
- struct stat buf;
-
- return !stat(path, &buf) && S_ISDIR(buf.st_mode);
-}
-
static void strip_trailing_slashes(char *dir)
{
char *end = dir + strlen(dir);
index de8c2b6266ee96d0958cb2c1430b2b2da99f1e86..ce1f63090dd86b12898fc4083444d5a38ca0cb60 100644 (file)
--- a/cache.h
+++ b/cache.h
{
return path[0] == '/' || has_dos_drive_prefix(path);
}
+int is_directory(const char *);
const char *make_absolute_path(const char *path);
const char *make_nonrelative_path(const char *path);
const char *make_relative_path(const char *abs, const char *base);
diff --git a/daemon.c b/daemon.c
index c315932ced825f96f669003616a9fb304309c75d..ab7a273859b66f5f2ae09deb0e2203121fb0c12e 100644 (file)
--- a/daemon.c
+++ b/daemon.c
if (strict_paths && (!ok_paths || !*ok_paths))
die("option --strict-paths requires a whitelist");
- if (base_path) {
- struct stat st;
-
- if (stat(base_path, &st) || !S_ISDIR(st.st_mode))
- die("base-path '%s' does not exist or "
- "is not a directory", base_path);
- }
+ if (base_path && !is_directory(base_path))
+ die("base-path '%s' does not exist or is not a directory",
+ base_path);
if (inetd_mode) {
struct sockaddr_storage ss;
diff --git a/rerere.c b/rerere.c
index 323e493dafee46c0d3f95e3c4cd9c4c9b463bbef..c38886b22af677083e749148604320fcada1ee75 100644 (file)
--- a/rerere.c
+++ b/rerere.c
static int is_rerere_enabled(void)
{
- struct stat st;
const char *rr_cache;
int rr_cache_exists;
return 0;
rr_cache = git_path("rr-cache");
- rr_cache_exists = !stat(rr_cache, &st) && S_ISDIR(st.st_mode);
+ rr_cache_exists = is_directory(rr_cache);
if (rerere_enabled < 0)
return rr_cache_exists;
diff --git a/sha1_file.c b/sha1_file.c
index 9ee1ed16ad2df8847bd5008a5d61c807c145357a..ae550e89c0942bb9e34b252b653c40e869a074a4 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
*/
static int link_alt_odb_entry(const char * entry, int len, const char * relative_base, int depth)
{
- struct stat st;
const char *objdir = get_object_directory();
struct alternate_object_database *ent;
struct alternate_object_database *alt;
@@ -281,7 +280,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
ent->base[pfxlen] = ent->base[entlen-1] = 0;
/* Detect cases where alternate disappeared */
- if (stat(ent->base, &st) || !S_ISDIR(st.st_mode)) {
+ if (!is_directory(ent->base)) {
error("object directory %s does not exist; "
"check .git/objects/info/alternates.",
ent->base);