{"thread":{"id":"28536","subject":"how to produce an index with smudged entries","startedAt":"2011-09-30T15:33:54Z","lastAt":"2011-10-02T13:10:24Z","messageCount":2,"participants":["Christian Halstrick","Robin Rosenberg"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"176575","messageId":"CAENte7h-sbv7VTBdV7A+=TtONTpgOBBfVWz2Nejm1DqJJ9tFiQ@mail.gmail.com","threadId":"28536","inReplyTo":null,"subject":"how to produce an index with smudged entries","fromName":"Christian Halstrick","fromEmail":"christian.halstrick@gmail.com","sentAt":"2011-09-30T15:33:54Z","receivedAt":"2011-09-30T15:33:54Z","isPatch":false,"sender":{"key":"christian.halstrick@gmail.com","avatar":"https://gravatar.com/avatar/3598bf518644c7dc32d4dcd8e0554b6a313e12103011862402c83ae2854203ce?d=mp&s=160"},"body":"I am trying to find out how native git handles the racy git problem. I\nread https://raw.github.com/git/git/master/Documentation/technical/racy-git.txt.\nBut I cannot reproduce the behaviour described in this text.\n\nI want to create an index which contains entries where the length of\nthe file was set to 0 to mark the entry as \"racily clean\". As I\nunderstood the text you have to modify a file and execute 'git\nupdate-index <file>' so fast that in the end the files modification\ntime is the same as the modification time of the file .git/index. That\nshould be sufficient that when persisting the index during the 'git\nupdate-index' call git should detect that the files mod-time is\nyounger than the index mod time  and should mark this entry \"racily\nclean\" with a length of 0.\n\nHere is the script with which I try to produce it but it always fails\nto create an index with a smudged entry. Any ideas? (Btw: I would\nassume that the first entry in the index is smduged when I find 4\nzeros beginning at position 48. That's what I deduced from\nhttps://github.com/gitster/git/blob/master/Documentation/technical/index-format.txt)\n\n#!/bin/bash\n\ngit init\necho \"initial\" > foo\n\n# wait for the next tick on the filesystem clock\ntouch foo\nlastTouch=$(stat -c %Y foo)\nwhile [ $lastTouch = $(stat -c %Y foo) ] ;do\n  touch foo\ndone\n\ngit add foo\n\n# modify 'foo' and update the index\n# (hopefully before the filesystem clock has increased)\n# repeat this step until the filesystem timer increased and\n# print the index everytime\nlastTouch=$(stat -c %Y foo)\nwhile [ $lastTouch = $(stat -c %Y foo) ] ;do\n  echo \"modification #$n\" > foo\n  git update-index foo\n  let \"n += 1\"\n  echo \"after attempt $n:\"\n  # dump 4 bytes of index beginning from pos 48.\n  # That should be the length of the first entry\n  od -j 48 -N 4 -x -A d .git/index\ndone\n"},{"id":"176682","messageId":"4E8862C0.7010906@dewire.com","threadId":"28536","inReplyTo":"CAENte7h-sbv7VTBdV7A+=TtONTpgOBBfVWz2Nejm1DqJJ9tFiQ@mail.gmail.com","subject":"Re: how to produce an index with smudged entries","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2011-10-02T13:10:24Z","receivedAt":"2011-10-02T13:10:24Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Christian Halstrick skrev 2011-09-30 17.33:\n> I am trying to find out how native git handles the racy git problem. I\n> read https://raw.github.com/git/git/master/Documentation/technical/racy-git.txt.\n> But I cannot reproduce the behaviour described in this text.\n\nI guess that code is only likely to work if USE_NSEC is not set or the\nfile system has only whole second resolution. It might be very hard to \nreproduce the situation since the likehood that a file AND the index has \nthe same timestamp at the subsecond level is very small. Nasty thing to \ntest :)\n\nIs your file system one that does not have subsecond timestamp \nresolution? The nanosecond part of the timestamp(s) should be 0 (byte \n24-27 for mtime for the first index entry).\n\nTouch can set the timestamp to an explicit value, so you can use that \ninstead of waiting for luck. Touch cannot set ctime, but you can make \ngit ignore ctime by setting core.trustctime to false.\n\nFor testing the issue with nanosecond resolution you have to roll your \nown touch in C, perl or even Java.\n\n-- robin\n"}]}