2

With the git-restoremtime script it is possible to amend the modification time of files checked out from a git repository based on the dates in commit messages.

However, how would you make the mtime of the directories appear intuitive, deterministic and consistent?

I would think that it would make the most sense for each directory to have its mtime set to the time of the latest commit touching any kind of files within such directory or any of its subdirectories. Does such recursive mtime propagation sound reasonable? Is it something that's easy to do with git?

Community
  • 1
  • 1
cnst
  • 21,785
  • 2
  • 73
  • 108

2 Answers2

3

So, it turns out, the script is very easy to modify to support having a deterministic mtime for directories.

https://github.com/cnst/git-tools/commit/89d09da9f362651ce9a0ca66362913c09e6b57cb https://github.com/cnst/git-tools/commit/b20207dc8fd9b791b8371dab94e98aca0a8412f6

The shortest snippet, to be integrated with https://stackoverflow.com/a/13284558/1122270, is as follows:

dirlist = dict()
...

        dir = file
        while dir:
            dir = os.path.dirname(dir)
            if dir in dirlist:
                if dirlist[dir] < mtime:
                    dirlist[dir] = mtime
            else:
                if os.path.isdir(dir):
                    dirlist[dir] = mtime
...

for file, mtime in dirlist.iteritems():
    try:
        os.utime(os.path.join(workdir, file), (mtime, mtime))
        touches += 1
    except Exception as e:
        logger.error("ERROR: %s\n", e)
        errors += 1
Community
  • 1
  • 1
cnst
  • 21,785
  • 2
  • 73
  • 108
1

Is it something that's easy to do with git

This has nothing to do with Git (or other distributed VCS), which simply doesn't record any kind of timestamp

So while your policy makes sense in your context, it would only be the result of a script, applied in your local repo, with no guarantee to be replicated in any of its clones.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Yes, obviously, it wouldn't work like that by default, but what I had in mind is creating a web-site where the source code could be browsed, or doing a checkout from git to package and distribute the source through other means. Of course, my whole notion of what constitutes an mtime change on a directory is vastly different from the regular notion of a filesystem, where the mtime changes in a subdir never propagate upwards. – cnst Jan 30 '13 at 17:44