git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Alexey Borzenkov <snaury@gmail.com>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Marius Storm-Olsen <mstormo@gmail.com>,
	git@vger.kernel.org, Johannes.Schindelin@gmx.de,
	msysgit@googlegroups.com, gitster@pobox.com, j6t@kdbg.org,
	lznuaa@gmail.com, raa.lkml@gmail.com,
	Marius Storm-Olsen <marius.storm-olsen@nokia.com>
Subject: Re: [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and  MSVC
Date: Thu, 17 Sep 2009 17:02:25 +0400	[thread overview]
Message-ID: <e2480c70909170602l6afc9842v7be2b91fde9ad498@mail.gmail.com> (raw)
In-Reply-To: <4AB1FB79.5070903@viscovery.net>

This is slightly more than a repost, forgot to reply to all, then
found more info.

On Thu, Sep 17, 2009 at 1:03 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> First thing to do is to understand what is going on: There are other
> architectures that do not have nsec and that do *not* have the problem;
> why do we have a problem on Windows? If you cannot answer this question,
> an nsec solution would still just be "it happens to work", and not "it
> works by design".

Ah, yes, I didn't realize that nsec checking isn't even enabled by
default. So implementing it wouldn't help. As for st_ino it doesn't
matter in this case, as it wouldn't change anyway.

It's interesting that putting git diff or git status before calling
git stash shows that the changes are actually there (and then they can
be picked up). It seems that something manages to spend enough time so
that cache_entry's mtime and index.timestamp start to differ. For
example, here I modified check-racy to show more info for this
particular case:

diff --git a/Makefile b/Makefile
index e0f9a63..00f425c 100644
--- a/Makefile
+++ b/Makefile
@@ -364,6 +364,7 @@ PROGRAMS += git-unpack-file$X
 PROGRAMS += git-update-server-info$X
 PROGRAMS += git-upload-pack$X
 PROGRAMS += git-var$X
+PROGRAMS += git-check-racy$X

 # List built-in command $C whose implementation cmd_$C() is not in
 # builtin-$C.o but is linked in as part of some other command.
diff --git a/check-racy.c b/check-racy.c
index 00d92a1..72b2878 100644
--- a/check-racy.c
+++ b/check-racy.c
@@ -16,6 +16,12 @@ int main(int ac, char **av)
                       continue;
               }

+               if (!strcmp(ce->name, "file")) {
+                       printf("for file: index.timestamp.sec: %d\n",
the_index.timestamp.sec);
+                       printf("for file:    ce->ce_mtime.sec: %d\n",
ce->ce_mtime.sec);
+                       printf("for file:         st.st_mtime: %d\n",
(int)st.st_mtime);
+               }
+
               if (ce_match_stat(ce, &st, 0))
                       dirty++;
               else if (ce_match_stat(ce, &st, CE_MATCH_RACY_IS_DIRTY))
diff --git a/git-stash.sh b/git-stash.sh
index 03e589f..6eb73fe 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -74,8 +74,14 @@ create_stash () {
               cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" &&
               GIT_INDEX_FILE="$TMP-index" &&
               export GIT_INDEX_FILE &&
+               echo ">>> before git read-tree:" >&2 &&
+               git check-racy >&2 &&
               git read-tree -m $i_tree &&
+               echo ">>> before git add:" >&2 &&
+               git check-racy >&2 &&
               git add -u &&
+               echo ">>> before git write-tree" >&2 &&
+               git check-racy >&2 &&
               git write-tree &&
               rm -f "$TMP-index"
       ) ) ||

Now where I run it and it doesn't fail:

HEAD is now at dfc6a3a other-file
>>> before git read-tree:
for file: index.timestamp.sec: 1253191568
for file:    ce->ce_mtime.sec: 1253191568
for file:         st.st_mtime: 1253191568
dirty 1, clean 1, racy 0
>>> before git add:
for file: index.timestamp.sec: 1253191570
for file:    ce->ce_mtime.sec: 1253191568
for file:         st.st_mtime: 1253191568
dirty 1, clean 1, racy 0
>>> before git write-tree
for file: index.timestamp.sec: 1253191571
for file:    ce->ce_mtime.sec: 1253191568
for file:         st.st_mtime: 1253191568
dirty 0, clean 2, racy 0
Saved working directory and index state WIP on master: dfc6a3a other-file
HEAD is now at dfc6a3a other-file
(To restore them type "git stash apply")
>>> before git read-tree:
for file: index.timestamp.sec: 1253191572
for file:    ce->ce_mtime.sec: 1253191571
for file:         st.st_mtime: 1253191572
dirty 1, clean 1, racy 0
>>> before git add:
for file: index.timestamp.sec: 1253191574
for file:    ce->ce_mtime.sec: 1253191571
for file:         st.st_mtime: 1253191572
dirty 1, clean 1, racy 0
>>> before git write-tree
for file: index.timestamp.sec: 1253191574
for file:    ce->ce_mtime.sec: 1253191572
for file:         st.st_mtime: 1253191572
dirty 0, clean 2, racy 0
Saved working directory and index state WIP on master: dfc6a3a other-file

But, when this test fails, the results are:

HEAD is now at dfc6a3a other-file
>>> before git read-tree:
for file: index.timestamp.sec: 1253191677
for file:    ce->ce_mtime.sec: 1253191676
for file:         st.st_mtime: 1253191676
dirty 0, clean 2, racy 0
>>> before git add:
for file: index.timestamp.sec: 1253191679
for file:    ce->ce_mtime.sec: 1253191676
for file:         st.st_mtime: 1253191676
dirty 0, clean 2, racy 0
>>> before git write-tree
for file: index.timestamp.sec: 1253191679
for file:    ce->ce_mtime.sec: 1253191676
for file:         st.st_mtime: 1253191676
dirty 0, clean 2, racy 0
Saved working directory and index state WIP on master: dfc6a3a other-file
HEAD is now at dfc6a3a other-file
(To restore them type "git stash apply")
>>> before git read-tree:
for file: index.timestamp.sec: 1253191681
for file:    ce->ce_mtime.sec: 1253191680
for file:         st.st_mtime: 1253191680
dirty 0, clean 2, racy 0
>>> before git add:
for file: index.timestamp.sec: 1253191683
for file:    ce->ce_mtime.sec: 1253191680
for file:         st.st_mtime: 1253191680
dirty 0, clean 2, racy 0
>>> before git write-tree
for file: index.timestamp.sec: 1253191683
for file:    ce->ce_mtime.sec: 1253191680
for file:         st.st_mtime: 1253191680
dirty 0, clean 2, racy 0
Saved working directory and index state WIP on master: dfc6a3a other-file

As you can see, even for "8" (first git stash in that test) it failed:
it seemed as if working tree is clean, index was not updated, changes
were not stashed. But it just so happens that it didn't matter.

Also, as you can see, in both cases index timestamp is slightly bigger
than cache_entry's timestamp. That's why git doesn't see file as racy.
Now I'm wondering WHAT manages to modify index timestamp. :-/

Update:

Ah, I just added more git check-racy calls and found one extremely
interesting case:

HEAD is now at dfc6a3a other-file
>>> start of create_stash:
for file: index.timestamp.sec: 1253192315
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 1, clean 1, racy 0
>>> after update-index -q --refresh:
for file: index.timestamp.sec: 1253192315
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 1, clean 1, racy 0
>>> after checking for changes:
for file: index.timestamp.sec: 1253192315
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 1, clean 1, racy 0
>>> after finding i_tree and i_commit:
for file: index.timestamp.sec: 1253192315
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 1, clean 1, racy 0
>>> before git read-tree:
for file: index.timestamp.sec: 1253192316
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 0, clean 2, racy 0
>>> before git add:
for file: index.timestamp.sec: 1253192318
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 0, clean 2, racy 0
>>> before git write-tree
for file: index.timestamp.sec: 1253192318
for file:    ce->ce_mtime.sec: 1253192315
for file:         st.st_mtime: 1253192315
dirty 0, clean 2, racy 0
Saved working directory and index state WIP on master: dfc6a3a other-file

"after finding i_tree and i_commit" is immediately before calculating
w_tree. As you can see, "before git read-tree" is off by a second. I
think it's just a bug in msys, cp -p doesn't preserve mtime exactly.
:-/

  parent reply	other threads:[~2009-09-17 13:02 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16  8:20 [PATCH v4 00/15] Build Git with MSVC Marius Storm-Olsen
2009-09-16  8:20 ` [PATCH 01/15] Avoid declaration after statement Marius Storm-Olsen
2009-09-16  8:20   ` [PATCH 02/15] Add define guards to compat/win32.h Marius Storm-Olsen
2009-09-16  8:20     ` [PATCH 03/15] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
2009-09-16  8:20       ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Marius Storm-Olsen
2009-09-16  8:20         ` [PATCH 05/15] Fix __stdcall placement and function prototype Marius Storm-Olsen
2009-09-16  8:20           ` [PATCH 06/15] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
2009-09-16  8:20             ` [PATCH 07/15] Add empty header files for MSVC port Marius Storm-Olsen
2009-09-16  8:20               ` [PATCH 08/15] Add MinGW header files to build git with MSVC Marius Storm-Olsen
2009-09-16  8:20                 ` [PATCH 09/15] Add platform files for MSVC porting Marius Storm-Olsen
2009-09-16  8:20                   ` [PATCH 10/15] Make usage of windows.h lean and mean Marius Storm-Olsen
2009-09-16  8:20                     ` [PATCH 11/15] Define strncasecmp and ftruncate for MSVC Marius Storm-Olsen
2009-09-16  8:20                       ` [PATCH 12/15] Add MSVC to Makefile Marius Storm-Olsen
2009-09-16  8:20                         ` [PATCH 13/15] Add README for MSVC build Marius Storm-Olsen
2009-09-16  8:20                           ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
2009-09-16  8:20                             ` [RFC 15/15] Tag GIT_VERSION when Git is built with MSVC Marius Storm-Olsen
2009-09-17 20:18                               ` Johannes Sixt
2009-09-18  6:44                                 ` Marius Storm-Olsen
2009-09-17 20:28                             ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Johannes Sixt
2009-09-18  6:59                               ` Marius Storm-Olsen
2009-09-18  8:21                                 ` Johannes Sixt
2009-09-23 15:04                             ` Sebastian Schuberth
2009-09-23 20:37                               ` Johannes Schindelin
2009-09-24  6:05                                 ` Marius Storm-Olsen
2009-09-23 10:03                 ` Add MinGW header files to build git with MSVC Sebastian Schuberth
2009-09-23 11:29                   ` Marius Storm-Olsen
2009-09-25  0:18                     ` [msysGit] " Frank Li
2009-09-16 16:14         ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Johannes Sixt
2009-09-16 20:00           ` Alexey Borzenkov
2009-09-17  7:11             ` Johannes Sixt
2009-09-17  7:25               ` Junio C Hamano
2009-09-17  7:27               ` Marius Storm-Olsen
2009-09-17  7:36                 ` Johannes Sixt
2009-09-17  7:53                   ` Marius Storm-Olsen
2009-09-17  8:10                     ` Johannes Sixt
2009-09-17  8:14                       ` Marius Storm-Olsen
2009-09-17  8:39                       ` Alexey Borzenkov
2009-09-17  8:45                         ` Marius Storm-Olsen
2009-09-17  8:57                           ` Alexey Borzenkov
2009-09-17  9:03                         ` Johannes Sixt
2009-09-17  9:28                           ` Marius Storm-Olsen
2009-09-17 13:02                           ` Alexey Borzenkov [this message]
2009-09-17 13:30                             ` Johannes Sixt
2009-09-17  8:02         ` Marius Storm-Olsen
2009-09-17 10:44           ` Johannes Sixt
     [not found]             ` <4AB212FA.9080102@viscovery.netm>
2009-09-17 11:04               ` Marius Storm-Olsen
2009-09-16  9:42     ` [msysGit] [PATCH 02/15] Add define guards to compat/win32.h Erik Faye-Lund
2009-09-16 10:10       ` Marius Storm-Olsen
2009-09-23  9:44   ` Avoid declaration after statement Sebastian Schuberth
2009-09-25 13:34     ` Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2480c70909170602l6afc9842v7be2b91fde9ad498@mail.gmail.com \
    --to=snaury@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=j6t@kdbg.org \
    --cc=lznuaa@gmail.com \
    --cc=marius.storm-olsen@nokia.com \
    --cc=mstormo@gmail.com \
    --cc=msysgit@googlegroups.com \
    --cc=raa.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).