remote-helpers: point at their upstream repositories
[gitweb.git] / entry.c
diff --git a/entry.c b/entry.c
index 20d291918f540e411916a86f56826946afacb10b..77c688262477e783b4bcbc237ef281eecab0661d 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -44,33 +44,33 @@ static void create_directories(const char *path, int path_len,
        free(buf);
 }
 
-static void remove_subtree(const char *path)
+static void remove_subtree(struct strbuf *path)
 {
-       DIR *dir = opendir(path);
+       DIR *dir = opendir(path->buf);
        struct dirent *de;
-       char pathbuf[PATH_MAX];
-       char *name;
+       int origlen = path->len;
 
        if (!dir)
-               die_errno("cannot opendir '%s'", path);
-       strcpy(pathbuf, path);
-       name = pathbuf + strlen(path);
-       *name++ = '/';
+               die_errno("cannot opendir '%s'", path->buf);
        while ((de = readdir(dir)) != NULL) {
                struct stat st;
+
                if (is_dot_or_dotdot(de->d_name))
                        continue;
-               strcpy(name, de->d_name);
-               if (lstat(pathbuf, &st))
-                       die_errno("cannot lstat '%s'", pathbuf);
+
+               strbuf_addch(path, '/');
+               strbuf_addstr(path, de->d_name);
+               if (lstat(path->buf, &st))
+                       die_errno("cannot lstat '%s'", path->buf);
                if (S_ISDIR(st.st_mode))
-                       remove_subtree(pathbuf);
-               else if (unlink(pathbuf))
-                       die_errno("cannot unlink '%s'", pathbuf);
+                       remove_subtree(path);
+               else if (unlink(path->buf))
+                       die_errno("cannot unlink '%s'", path->buf);
+               strbuf_setlen(path, origlen);
        }
        closedir(dir);
-       if (rmdir(path))
-               die_errno("cannot rmdir '%s'", path);
+       if (rmdir(path->buf))
+               die_errno("cannot rmdir '%s'", path->buf);
 }
 
 static int create_file(const char *path, unsigned int mode)
@@ -234,6 +234,14 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
        return lstat(path, st);
 }
 
+/*
+ * Write the contents from ce out to the working tree.
+ *
+ * When topath[] is not NULL, instead of writing to the working tree
+ * file named by ce, a temporary file is created by this function and
+ * its name is returned in topath[], which must be able to hold at
+ * least TEMPORARY_FILENAME_LENGTH bytes long.
+ */
 int checkout_entry(struct cache_entry *ce,
                   const struct checkout *state, char *topath)
 {
@@ -271,7 +279,7 @@ int checkout_entry(struct cache_entry *ce,
                                return 0;
                        if (!state->force)
                                return error("%s is a directory", path.buf);
-                       remove_subtree(path.buf);
+                       remove_subtree(&path);
                } else if (unlink(path.buf))
                        return error("unable to unlink old '%s' (%s)",
                                     path.buf, strerror(errno));