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

Re: Fastest way to set files date and time to latest commit time of each one

From
EWEric Wong <e@yhbt.net>
Date
Aug 29, 2020, 04:48 UTC
Message-ID
<20200829044842.GA5732@dcvr>
In-Reply-To
<CAEbcw=3mOoYuJo2mQgqB2aJgn-D2i_7ZRmhfPvYNVHD1Kp8wuA@mail.gmail.com>
Ivan Baldo <ibaldo@gmail.com> wrote:
Show 18 quoted lines
>   Hello.
>   I know this is not standard usage of git, but I need a way to have
> more stable dates and times in the files in order to avoid rsync
> checksumming.
>   So I found this
> https://stackoverflow.com/questions/2179722/checking-out-old-file-with-original-create-modified-timestamps/2179876#2179876
> and modified it a bit to run in CentOS 7:
> 
> IFS="
> "
> for FILE in $(git ls-files -z | tr '\0' '\n')
> do
>     TIME=$(git log --pretty=format:%cd -n 1 --date=iso -- "$FILE")
>     touch -c -m -d "$TIME" "$FILE"
> done
> 
>   Unfortunately it takes ages for a 84k files repo.
>   I see the CPU usage is dominated by the git log command.
running git log for each file isn't necessary.

On Debian, rsync actually ships the `git-set-file-times' script in /usr/share/doc/rsync/scripts/ which only runs `git log' once and parses it.

You can also get my (original) version from: https://yhbt.net/git-set-file-times

>   I know a way I could use to split the work for all the CPU threads
> but anyway, I would like to know if you guys and girls know of a
> faster way to do this.

Much of your overhead is going to be from process spawning. My Perl version reduces that significantly.

I haven't tried it with 84K files, but it'll have to keep all those filenames in memory. I'm not sure if parallelizing utime() syscalls is worth it, either; maybe it helps on SSD more than HDD.

Previous: Raymond E. PascoNext: Ivan Baldo
Message 4 of 6 in “Fastest way to set files date and time to latest commit time of each one”
  1. Ivan BaldoAug 29, 2020
  2. Junio C HamanoAug 29, 2020
  3. Raymond E. PascoAug 29, 2020
  4. Eric WongAug 29, 2020
  5. Ivan BaldoSep 2, 2020
  6. Andreas SchwabAug 29, 2020

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.