*/
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
#include "cache-tree.h"
int size, len;
struct cache_entry *ce, *ret;
- if (!verify_path(path, mode)) {
+ if (!verify_path(path)) {
error("Invalid path '%s'", path);
return NULL;
}
* Also, we don't want double slashes or slashes at the
* end that can make pathnames ambiguous.
*/
-static int verify_dotfile(const char *rest, unsigned mode)
+static int verify_dotfile(const char *rest)
{
/*
* The first character was '.', but that
switch (*rest) {
/*
- * ".git" followed by NUL or slash is bad. Note that we match
- * case-insensitively here, even if ignore_case is not set.
- * This outlaws ".GIT" everywhere out of an abundance of caution,
- * since there's really no good reason to allow it.
- *
- * Once we've seen ".git", we can also find ".gitmodules", etc (also
- * case-insensitively).
+ * ".git" followed by NUL or slash is bad. This
+ * shares the path end test with the ".." case.
*/
case 'g':
case 'G':
break;
if (rest[2] != 't' && rest[2] != 'T')
break;
- if (rest[3] == '\0' || is_dir_sep(rest[3]))
- return 0;
- if (S_ISLNK(mode)) {
- rest += 3;
- if (skip_iprefix(rest, "modules", &rest) &&
- (*rest == '\0' || is_dir_sep(*rest)))
- return 0;
- }
- break;
+ rest += 2;
+ /* fallthrough */
case '.':
if (rest[1] == '\0' || is_dir_sep(rest[1]))
return 0;
return 1;
}
-int verify_path(const char *path, unsigned mode)
+int verify_path(const char *path)
{
char c;
return 1;
if (is_dir_sep(c)) {
inside:
- if (protect_hfs) {
- if (is_hfs_dotgit(path))
- return 0;
- if (S_ISLNK(mode)) {
- if (is_hfs_dotgitmodules(path))
- return 0;
- }
- }
- if (protect_ntfs) {
- if (is_ntfs_dotgit(path))
- return 0;
- if (S_ISLNK(mode)) {
- if (is_ntfs_dotgitmodules(path))
- return 0;
- }
- }
-
+ if (protect_hfs && is_hfs_dotgit(path))
+ return 0;
+ if (protect_ntfs && is_ntfs_dotgit(path))
+ return 0;
c = *path++;
- if ((c == '.' && !verify_dotfile(path, mode)) ||
+ if ((c == '.' && !verify_dotfile(path)) ||
is_dir_sep(c) || c == '\0')
return 0;
}
if (!ok_to_add)
return -1;
- if (!verify_path(ce->name, ce->ce_mode))
+ if (!verify_path(ce->name))
return error("Invalid path '%s'", ce->name);
if (!skip_df_check &&
free_name_hash(istate);
cache_tree_free(&(istate->cache_tree));
istate->initialized = 0;
- free(istate->cache);
- istate->cache = NULL;
+ FREE_AND_NULL(istate->cache);
istate->cache_alloc = 0;
discard_split_index(istate);
free_untracked_cache(istate->untracked);
int entries = istate->cache_nr;
struct stat st;
struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
+ int drop_cache_tree = 0;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
warning(msg, ce->name);
else
return error(msg, ce->name);
+
+ drop_cache_tree = 1;
}
if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
return -1;
if (err)
return -1;
}
- if (!strip_extensions && istate->cache_tree) {
+ if (!strip_extensions && !drop_cache_tree && istate->cache_tree) {
struct strbuf sb = STRBUF_INIT;
cache_tree_write(&sb, istate->cache_tree);
void stat_validity_clear(struct stat_validity *sv)
{
- free(sv->sd);
- sv->sd = NULL;
+ FREE_AND_NULL(sv->sd);
}
int stat_validity_check(struct stat_validity *sv, const char *path)
fill_stat_data(sv->sd, &st);
}
}
+
+void move_index_extensions(struct index_state *dst, struct index_state *src)
+{
+ dst->untracked = src->untracked;
+ src->untracked = NULL;
+}