From c1a2a14e022caae68112497f5e6862f9b59f1260 Mon Sep 17 00:00:00 2001 From: Jakob Pfender Date: Wed, 25 May 2011 16:16:41 +0200 Subject: [PATCH] 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. --- src/index.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.c b/src/index.c index e1b52610b..afd9cfccd 100644 --- a/src/index.c +++ b/src/index.c @@ -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;