]> git.proxmox.com Git - libgit2.git/commitdiff
index: Correctly write entry mode
authorJakob Pfender <jpfender@elegosoft.com>
Wed, 25 May 2011 14:16:41 +0000 (16:16 +0200)
committerJakob Pfender <jpfender@elegosoft.com>
Tue, 7 Jun 2011 10:54:37 +0000 (12:54 +0200)
The entry mode flags for an entry created from a path name were not
correctly written if the entry was a symlink. The st_mode of a statted
symlink is 0120777, however git requires the mode to read 0120000,
because it does not care about permissions of symlinks.

Introduce index_create_mode() that correctly writes the mode flags in
the form expected by git.

src/index.c

index e1b52610bbee5e4dc382e260de28c34844a8a31b..afd9cfccd5b1c45ea444588b7a4c7fababb87f41 100644 (file)
@@ -138,6 +138,15 @@ int unmerged_cmp(const void *a, const void *b)
        return strcmp(info_a->path, info_b->path);
 }
 
+unsigned int index_create_mode(unsigned int mode)
+{
+       if (S_ISLNK(mode))
+               return S_IFLNK;
+       if (S_ISDIR(mode) || (mode & S_IFMT) == 0160000)
+               return 0160000;
+       return S_IFREG | ((mode & 0100) ? 0755 : 0644);
+}
+
 static int index_initialize(git_index **index_out, git_repository *owner, const char *index_path)
 {
        git_index *index;
@@ -419,7 +428,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
        /* entry.ctime.nanoseconds = st.st_ctimensec; */
        entry->dev= st.st_rdev;
        entry->ino = st.st_ino;
-       entry->mode = st.st_mode;
+       entry->mode = index_create_mode(st.st_mode);
        entry->uid = st.st_uid;
        entry->gid = st.st_gid;
        entry->file_size = st.st_size;