Move index-related variables into a structure.
[gitweb.git] / read-cache.c
index b8b6d11dba3c08b6746fe7e141d9ad53fa3dee4b..9b4385ea5cfd23ac07b460557cf296650983794d 100644 (file)
 #define CACHE_EXT(s) ( (s[0]<<24)|(s[1]<<16)|(s[2]<<8)|(s[3]) )
 #define CACHE_EXT_TREE 0x54524545      /* "TREE" */
 
-struct cache_entry **active_cache;
-static time_t index_file_timestamp;
-unsigned int active_nr, active_alloc, active_cache_changed;
-
-struct cache_tree *active_cache_tree;
-
-static void *cache_mmap;
-static size_t cache_mmap_size;
+struct index_state the_index;
+#define index_file_timestamp (the_index.timestamp)
+#define cache_mmap (the_index.mmap)
+#define cache_mmap_size (the_index.mmap_size)
 
 /*
  * This only updates the "non-critical" parts of the directory
@@ -120,9 +116,9 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
                if (ce_compare_link(ce, xsize_t(st->st_size)))
                        return DATA_CHANGED;
                break;
-       case S_IFDIRLNK:
-               /* No need to do anything, we did the exact compare in "match_stat_basic" */
-               break;
+       case S_IFDIR:
+               if (S_ISDIRLNK(ntohl(ce->ce_mode)))
+                       return 0;
        default:
                return TYPE_CHANGED;
        }
@@ -153,7 +149,7 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
                        changed |= TYPE_CHANGED;
                else if (ce_compare_gitlink(ce))
                        changed |= DATA_CHANGED;
-               break;
+               return changed;
        default:
                die("internal error: ce_mode is %o", ntohl(ce->ce_mode));
        }
@@ -365,6 +361,10 @@ int add_file_to_cache(const char *path, int verbose)
                die("%s: can only add regular files, symbolic links or git-directories", path);
 
        namelen = strlen(path);
+       if (S_ISDIR(st.st_mode)) {
+               while (namelen && path[namelen-1] == '/')
+                       namelen--;
+       }
        size = cache_entry_size(namelen);
        ce = xcalloc(1, size);
        memcpy(ce->name, path, namelen);