Commit c1a2a14e by Jakob Pfender

index: Correctly write entry mode

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.
parent 1869b31e
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment