Skip to content

fix st_ino on Windows so includeIf works on subst drives - #6586

Open
ChrisIdema wants to merge 1 commit into
git-for-windows:mainfrom
ChrisIdema:fix-includeIf-on-subst-drive
Open

ChrisIdema wants to merge 1 commit into
git-for-windows:mainfrom
ChrisIdema:fix-includeIf-on-subst-drive

Conversation

@ChrisIdema

Copy link
Copy Markdown

No description provided.

Signed-off-by: Chris Idema <github_chris_idema@proton.me>
@ChrisIdema
ChrisIdema force-pushed the fix-includeIf-on-subst-drive branch from b6ffab1 to f3dafa9 Compare December 2, 2026 14:25

@dscho dscho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this @ChrisIdema. In general, this is of course a good idea.

Please note that the ramifications from your change are far, far, far away from affecting only includeIf. You're changing the implementation of lstat(), Which is most prominently used to quickly verify that files in a work tree are up to date. Which they now will not be, Not when the Git index was written by a previous version and the user updated to a Git version including your change. Refreshing and rehashing is very expensive. Therefore, I think this must be an intentional upgrade by the user. You can't just force everybody, especially those with monorepos, to involunatrily refresh their potentially huge Git indices.

So I think that this needs, definitely needs, to be an opt-in.

Furthermore, we really need to deal with the fact that Git assumes that inode numbers are unsigned ints, that is, 32-bit. Your patch truncates a 64-bit number. So what was assumed to be unique no longer is.

Besides, if I saw correctly, you only covered the regular mingw_lstat(), but not the fscache_lstat(). That will require an equivalent change.

Finally, note that this is missing documentation. Which in this case is not a formality because there are plenty of file systems that do not provide those pseudo-inode numbers. Granted, NTFS and ReFS support it, but FAT doesn't. Most network file systems also do not, if I recall correctly.

Comment thread compat/mingw-posix.h
struct mingw_stat {
_dev_t st_dev;
_ino_t st_ino;
uint64_t st_ino;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unfortunately incompatible with the unsigned int sd_ino declaration, to which the st_ino values are assigned.

Comment thread compat/mingw.c
Comment on lines -1672 to +1673
buf->st_ino = 0;
buf->st_ino = ((uint64_t)fdata.nFileIndexHigh << 32) |
((uint64_t)fdata.nFileIndexLow << 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Git index stores that statinfo to indicate whether an index entry is up to date, rolling out this change to everybody without making it opt-in will actually render every single Git index out of date in every Git worktree on Windows on this entire planet.

Even worse, should multiple Git implementations be used on the same work tree, they would now flip-flop. For example, if you use regular Git for Windows with this change and a libgit2 based one or an older menu Git, for example via Visual Studio, you will now constantly rehash and refresh the index. That's quite costly.

So in the least, I would suggest to make this a config option. Defaulting to off, of course, to avoid everybody and their parents to waste electricity and time.

@ChrisIdema

ChrisIdema commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

Thanks for the quick reply. In the topic on the issue there has been radio silence for 3 weeks so I thought I take the initiative to create a pull request.

That is unfortunately incompatible with the unsigned int sd_ino declaration, to which the st_ino values are assigned.

On windows _ino_t is defined in C:\git-sdk-64\ucrt64\include\sys\types.h.

#ifndef _INO_T_DEFINED
#define _INO_T_DEFINED
typedef unsigned short _ino_t;
#ifndef	NO_OLDNAMES
typedef unsigned short ino_t;
#endif
#endif

So by defining _INO_T_DEFINED we can overrule it. Unfortunately https://github.com/git/git/blob/566b6997dd4710b625c0882cf10a7443bf52d183/statinfo.h#L20 doesn't use the type _ino_t but uses unsigned int.
So those hardcoded types would have to be replaced by _ino_t too.
Another solution I considered was hashing the 64-bit file index with a 16-bit hash so it can fit in 16-bit. Or changing it to 32-bit and hashing it to 32-bit. There's a non-zero chance of collision, so I don't like that. Though currently st_ino is not valid at all on Windows as it's always 0.

Furthermore, we really need to deal with the fact that Git assumes that inode numbers are unsigned ints, that is, 32-bit. Your patch truncates a 64-bit number. So what was assumed to be unique no longer is.

Currently nothing is assumed unique as st_ino is always 0...

Since the Git index stores that statinfo to indicate whether an index entry is up to date, rolling out this change to everybody without making it opt-in will actually render every single Git index out of date in every Git worktree on Windows on this entire planet.

If the st_ino values are indeed used for that purpose, then that would not be acceptable.

I think the only solution is to modify or override strbuf_add_absolute_path. I don't like the fact it has low level and platform depended stuff in it.

@dscho

dscho commented Dec 2, 2026

Copy link
Copy Markdown
Member

Another solution I considered was hashing the 64-bit file index with a 16-bit hash so it can fit in 16-bit.

You mean 32-bit, right? sd_ino is declared as unsigned int, not as unsigned short.

I do think though that there are hash algorithms that are acceptable here (probably even already in libgit.a). And as you point out, collisions are kind of expected, if the inode number is allowed to be zero for all files.

Since the Git index stores that statinfo to indicate whether an index entry is up to date, rolling out this change to everybody without making it opt-in will actually render every single Git index out of date in every Git worktree on Windows on this entire planet.

If the st_ino values are indeed used for that purpose, then that would not be acceptable.

They are. The statinfo thing is used for that purpose.

So... opt-in?

@rimrul rimrul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably want tests for this and a less terse commit message.

Comment thread compat/mingw.c
buf->st_size = fdata.nFileSizeLow |
(((off_t)fdata.nFileSizeHigh)<<32);
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
buf->st_dev = buf->st_rdev = fdata.dwVolumeSerialNumber;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

st_rdev probably should stay 0 and keep the comment that it's not used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's literally used by git. The comment is wrong.

@ChrisIdema

ChrisIdema commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

Another solution I considered was hashing the 64-bit file index with a 16-bit hash so it can fit in 16-bit.

You mean 32-bit, right? sd_ino is declared as unsigned int, not as unsigned short.

It meant st_ino. I printed sizeof and it printed 2. It's defined as unsigned short in types.h.
The value of 16-bit st_ino is assigned to 32-bit sd_ino.

If the st_ino values are indeed used for that purpose, then that would not be acceptable.

They are. The statinfo thing is used for that purpose.

So... opt-in?

I think you made a good case to not touch st_ino. So I will look for a solution that resolves around fixing strbuf_add_absolute_path and not touch _ino_t.

I can think of several ways to do it. But it's hard for me to find the git way to do it.
My idea is to overrule strbuf_add_absolute_path in mingw.c since working around it to make it work on all platforms without changing it is just too hacky in my opinion. Perhaps add a function "compare_paths" or something that properly compares paths.

@dscho

dscho commented Dec 3, 2026

Copy link
Copy Markdown
Member

I think you made a good case to not touch st_ino.

Hehe, that was actually not the case I wanted to make. To the contrary, I think that if you want to fix this problem, you have to touch st_ino and fix the declaration to either make it 64-bit (and then introduce #if sizeof(st_ino) > sizeof(sd_ino) ... hash to 32-bit ... #endif (paraphrased)) or make it 32-bit (and then hash in compat/mingw.c and compat/win32/fscache.c).

And of course introduce a config option to zero that sd_ino/sd_rdev on Windows by default to retain backwards-compatibility as well as compatibility with libgit2, JGit, older MinGit, etc.

@ChrisIdema

Copy link
Copy Markdown
Author

And of course introduce a config option to zero that sd_ino/sd_rdev on Windows by default to retain backwards-compatibility as well as compatibility with libgit2, JGit, older MinGit, etc.

What do you mean exactly by "by default". Do you mean as a build flag so that users have to enable to use it? Is this so that people can test it? I'm asking, because if there is an acceptable solution wouldn't you want it enabled for everyone eventually? I'd like to know what the "git way" is of approaching this.

@dscho

dscho commented Dec 3, 2026

Copy link
Copy Markdown
Member

And of course introduce a config option to zero that sd_ino/sd_rdev on Windows by default to retain backwards-compatibility as well as compatibility with libgit2, JGit, older MinGit, etc.

What do you mean exactly by "by default". Do you mean as a build flag so that users have to enable to use it? Is this so that people can test it? I'm asking, because if there is an acceptable solution wouldn't you want it enabled for everyone eventually? I'd like to know what the "git way" is of approaching this.

No, by "config option" I was referring to a setting that can be enabled/disabled via git config.

Also, I don't think I impressed enough how much of a cost upgrading from inode numbers being forced to zero to non-zero inode numbers would be. Do note, as I have pointed out above, that those inode numbers are persisted in the Git index. When you run git status, first thing Git does is to enumerate all of the files that are tracked in the git index and compare their stat data.

Imagine that you are a user of a big monorepo that has millions and millions of files. Your Git index has stat data for all of them, and all of them have an rdev and an inode set to zero. Now some wonderful contributor implements a very neat change so that inode numbers are now properly set. The next thing you do is run git status after updating to that new version. The git status command now sees that all of those files are out of date. All of their inodes differ. So naturally, Git needs to rehash every single of them in order to update the Git index.

Phew, that costs some time, right?

But now you look at the same thing with Visual Studio because that's what you usually work in. Or with GitHub Desktop, or any other third party program that uses their own Git implementation. Naturally, they ship with an older version of MinGit (or are based on libgit2 or JGit or gitoxide or whatever, else, really) that does not support the feature where proper, correct inode numbers are calculated. So when those programs try to see which files are up to date... They see that all of them are modified. All of them have differing inode numbers because that Git expected the inode numbers to be zero, but they're recorded as non-zero in the Git index. So now the older Git needs to rehash every single file in order to update the index.

Phew, that costs some time again, right?

Let's check with the new Git for Windows' git status command. Oh wait, the Git index again records the wrong inode number.

Phew, that again costs a lot of time, right? By now you're actually no longer that certain that this was such a wonderful contribution. You wished that somebody had told you that you can opt into it or you can opt out of it and at least told you what to expect. But nobody did.

Except that I want this to be an opt in so that by default, those costs are not paid by Git for Windows users, especially those with large repositories. And I want that config option to be prominently featured in the release notes. And eventually, when enough time has passed so that other Git implementations and applications shipping with MinGit had a chance to catch up, then we flip the default.

Makes sense now?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants