git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Do not change the file type if the filesystem does not support symlinks.

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Feb 27, 2007, 21:41 UTC
Message-ID
<1172612504272-git-send-email-johannes.sixt@telecom.at>
In-Reply-To
<11726125033437-git-send-email-johannes.sixt@telecom.at>

Upon git add and git update-index, if core.symlinks = false, do not change an entry from symbolic link to regular file even if the filesystem entry is a regular file.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 builtin-update-index.c |    6 +++---
 cache.h                |    6 +++++-
 read-cache.c           |   12 +++++++-----
 3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 772aaba..cf8c069 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -109,11 +109,11 @@ static int add_file_to_cache(const char *path)
 	ce->ce_flags = htons(namelen);
 	fill_stat_cache_info(ce, &st);
 
-	if (trust_executable_bit)
+	if (trust_executable_bit && trust_symlink_fmt)
 		ce->ce_mode = create_ce_mode(st.st_mode);
 	else {
-		/* If there is an existing entry, pick the mode bits
-		 * from it, otherwise assume unexecutable.
+		/* If there is an existing entry, pick the mode bits and format
+		 * from it, otherwise assume unexecutable regular file.
 		 */
 		struct cache_entry *ent;
 		int pos = cache_name_pos(path, namelen);
diff --git a/cache.h b/cache.h
index 6cbb9d8..298cdd2 100644
--- a/cache.h
+++ b/cache.h
@@ -108,7 +108,11 @@ static inline unsigned int create_ce_mode(unsigned int mode)
 }
 static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode)
 {
-	extern int trust_executable_bit;
+	extern int trust_executable_bit, trust_symlink_fmt;
+	/* note: !trust_symlink_fmt trumps !trust_executable_bit */
+	if (!trust_symlink_fmt && S_ISREG(mode) &&
+	    ce && S_ISLNK(ntohl(ce->ce_mode)))
+		return ce->ce_mode;
 	if (!trust_executable_bit && S_ISREG(mode)) {
 		if (ce && S_ISREG(ntohl(ce->ce_mode)))
 			return ce->ce_mode;
diff --git a/read-cache.c b/read-cache.c
index 605b352..f09ee2e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -116,7 +116,8 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
 
 	switch (ntohl(ce->ce_mode) & S_IFMT) {
 	case S_IFREG:
-		changed |= !S_ISREG(st->st_mode) ? TYPE_CHANGED : 0;
+		if (trust_symlink_fmt && !S_ISREG(st->st_mode))
+			changed |= TYPE_CHANGED;
 		/* We consider only the owner x bit to be relevant for
 		 * "mode changes"
 		 */
@@ -125,7 +126,8 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
 			changed |= MODE_CHANGED;
 		break;
 	case S_IFLNK:
-		changed |= !S_ISLNK(st->st_mode) ? TYPE_CHANGED : 0;
+		if (trust_symlink_fmt && !S_ISLNK(st->st_mode))
+			changed |= TYPE_CHANGED;
 		break;
 	default:
 		die("internal error: ce_mode is %o", ntohl(ce->ce_mode));
@@ -344,11 +346,11 @@ int add_file_to_index(const char *path, int verbose)
 	ce->ce_flags = htons(namelen);
 	fill_stat_cache_info(ce, &st);
 
-	if (trust_executable_bit)
+	if (trust_executable_bit && trust_symlink_fmt)
 		ce->ce_mode = create_ce_mode(st.st_mode);
 	else {
-		/* If there is an existing entry, pick the mode bits
-		 * from it, otherwise assume unexecutable.
+		/* If there is an existing entry, pick the mode bits and format
+		 * from it, otherwise assume unexecutable regular file.
 		 */
 		struct cache_entry *ent;
 		int pos = cache_name_pos(path, namelen);
-- 
1.5.0.19.gddff
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 18 in “Implement core.symlinks to support filesystems without symlinks”
  1. Johannes SixtFeb 27, 2007
  2. Add a flag core.symlinks analogous to core.filemode.Johannes Sixt, Feb 27, 2007
  3. Do not change the file type if the filesystem does not support symlinks.Johannes Sixt, Feb 27, 2007
  4. Create a symbolic link as a regular file on filesystems without symlinks.Johannes Sixt, Feb 27, 2007
  5. diff-lib.c: Ignore type differences if the filesystem does not support symlinks.Johannes Sixt, Feb 27, 2007
  6. Describe core.symlinks in the man pages.Johannes Sixt, Feb 27, 2007
  7. Johannes SchindelinFeb 27, 2007
  8. Johannes SixtFeb 28, 2007
  9. Johannes SchindelinFeb 27, 2007
  10. Johannes SixtFeb 28, 2007
  11. Johannes SchindelinFeb 28, 2007
  12. Robin RosenbergFeb 27, 2007
  13. Johannes SchindelinFeb 28, 2007
  14. Robin RosenbergFeb 28, 2007
  15. Johannes SchindelinMar 1, 2007
  16. Robin RosenbergMar 1, 2007
  17. Johannes SchindelinMar 1, 2007
  18. Johannes SixtMar 1, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.