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

Re: [PATCH] compat: convert modes to use portable file type values

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 1, 2014, 03:11 UTC
Message-ID
<xmqq8uisrrmc.fsf@gitster.dls.corp.google.com>
In-Reply-To
<87vblxl8ah.fsf@gmail.com>
David Michael <fedora.dm0@gmail.com> writes:
Show 10 quoted lines
> This is my most recent attempt at solving the problem of z/OS using
> different file type values than every other OS.  I believe it should be
> safe as long as the file type bits don't ever need to be converted back
> to their native values (and I didn't see any instances of that).
>
> I've been testing it by making commits to the same repositories on
> different operating systems and pushing those changes around, and so far
> there have been no issues.
>
> Can anyone foresee any problems with this method?

I cannot offhand comment on the last question above, but the reliance on exact S_IFxxx bit assignment was identified as a potential problem from very early days of Git that we have known about but didn't have need to address on any system that mattered.

This is a long overdue issue and I am happy to see it getting tackled. The patch seems to be a sensible implementation of your design decision to use the one-way conversion.

Show 28 quoted lines
> diff --git a/compat/stat.c b/compat/stat.c
> new file mode 100644
> index 0000000..0ff1f2f
> --- /dev/null
> +++ b/compat/stat.c
> @@ -0,0 +1,49 @@
> +#define _POSIX_SOURCE
> +#include <stddef.h>    /* NULL         */
> +#include <sys/stat.h>  /* *stat, S_IS* */
> +#include <sys/types.h> /* mode_t       */
> +
> +static inline mode_t mode_native_to_git(mode_t native_mode)
> +{
> +	if (S_ISREG(native_mode))
> +		return 0100000 | (native_mode & 07777);
> +	else if (S_ISDIR(native_mode))
> +		return 0040000 | (native_mode & 07777);
> +	else if (S_ISLNK(native_mode))
> +		return 0120000 | (native_mode & 07777);
> +	else if (S_ISBLK(native_mode))
> +		return 0060000 | (native_mode & 07777);
> +	else if (S_ISCHR(native_mode))
> +		return 0020000 | (native_mode & 07777);
> +	else if (S_ISFIFO(native_mode))
> +		return 0010000 | (native_mode & 07777);
> +	else /* Non-standard type bits were given. */
> +		return native_mode & 07777;
> +}
Previous: David MichaelNext: Duy Nguyen
Message 7 of 12 in “compat: convert modes to use portable file type values”
  1. compat: convert modes to use portable file type valuesDavid Michael, Nov 30, 2014
  2. Torsten BögershausenNov 30, 2014
  3. David MichaelDec 1, 2014
  4. Torsten BögershausenDec 1, 2014
  5. David MichaelDec 1, 2014
  6. David MichaelDec 1, 2014
  7. Junio C HamanoDec 1, 2014
  8. Duy NguyenDec 1, 2014
  9. David MichaelDec 1, 2014
  10. Junio C HamanoDec 1, 2014
  11. David MichaelDec 1, 2014
  12. Junio C HamanoDec 1, 2014

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.