Propagate timestamp and author from git to file system

31 Views Asked by At

Some tools don't know about git, but read owner and modification time from the file system. Such systems could become implicitly "git aware" if the file system's fields for each file's owner and last modification time were updated with author and author date information from git. Is there a way to automate this?

I've searched online and here on Stack Overflow for various terms and synonyms, but found not even tangential mention of anything in this direction.

1

There are 1 best solutions below

0
bk2204 On

There's no specific way to handle this automatically. Git is designed for contexts where the author or committer may be external parties (e.g., open source contributors) who don't have any access to the files on the local system. Even on my work laptop, for example, there is exactly one non-system user (me) and my colleagues are not represented in the users database (since they have their own systems).

Even when all of the authors are represented in the users on the system, that isn't known to Git or the file system, the mapping is not necessarily trivial or obvious, and in general, there are lots of security risks with changing ownership of files, which is why this is restricted to the superuser (or users with certain capabilities).

It is possible to store a nearly arbitrary timestamp in the file system, but Git doesn't specifically update the timestamp. Instead, if it needs to write a file, it does, and that file gets the current timestamp. This makes tools like make which use timestamps to determine what to rebuild work correctly.

Having said that, it is possible to store a manifest to set ownership, permissions, timestamps, and other metadata. One of the most common tools for this, which is found on most of the BSDs, is called mtree, and exists in a variety of slightly incompatible tools. There are versions of it available for other OSes; for example, Debian ships mtree-netbsd.

You can store the manifest along side the rest of the data in the repository, or you could write a script to generate the output based on the Git history, probably using git rev-list and git diff-tree to generate appropriate entries. Many mtree implementations allow a record-per-line format, so you can generate a manifest quite easily using standard shell scripts. However, I'm not aware of any existing tool which provides this functionality, so you would need to write it yourself.

It is also at least in theory possible to expose this as a separate file system, using something like FUSE, 9P, or NFSv4, or by implementing an SFTP server (which can be mounted using FUSE with SSHFS). These would allow you to expose the file system with just a bare repository. I've implemented both 9P and SFTP and it isn't too difficult, but again, I'm not aware of any existing tooling for this. My recommendation is FUSE or SFTP because at least on Linux, 9P is a kernel-based file system driver, so any failure of the file system (due to coding bugs, unavailability of underlying resources, or what have you) tends to hang processes using the file system until system reboot, which tends to be inconvenient.