]> asedeno.scripts.mit.edu Git - git.git/blobdiff - read-cache.c
builtin-commit.c: do not remove COMMIT_EDITMSG
[git.git] / read-cache.c
index 15e1a9d471daa2fd5c54a9f8562b1dfc52161213..525d138e90c524d08ef3d9755f1a2486c34adc39 100644 (file)
@@ -1239,6 +1239,11 @@ unmap:
        die("index file corrupt");
 }
 
+int is_index_unborn(struct index_state *istate)
+{
+       return (!istate->cache_nr && !istate->alloc && !istate->timestamp);
+}
+
 int discard_index(struct index_state *istate)
 {
        istate->cache_nr = 0;
@@ -1485,3 +1490,31 @@ int read_index_unmerged(struct index_state *istate)
        }
        return unmerged;
 }
+
+/*
+ * Returns 1 if the path is an "other" path with respect to
+ * the index; that is, the path is not mentioned in the index at all,
+ * either as a file, a directory with some files in the index,
+ * or as an unmerged entry.
+ *
+ * We helpfully remove a trailing "/" from directories so that
+ * the output of read_directory can be used as-is.
+ */
+int index_name_is_other(const struct index_state *istate, const char *name,
+               int namelen)
+{
+       int pos;
+       if (namelen && name[namelen - 1] == '/')
+               namelen--;
+       pos = index_name_pos(istate, name, namelen);
+       if (0 <= pos)
+               return 0;       /* exact match */
+       pos = -pos - 1;
+       if (pos < istate->cache_nr) {
+               struct cache_entry *ce = istate->cache[pos];
+               if (ce_namelen(ce) == namelen &&
+                   !memcmp(ce->name, name, namelen))
+                       return 0; /* Yup, this one exists unmerged */
+       }
+       return 1;
+}