{"thread":{"id":"29714","subject":"[PATCH] mingw: work around stat-limitation","startedAt":"2012-02-23T20:25:44Z","lastAt":"2012-02-23T22:37:39Z","messageCount":4,"participants":["Erik Faye-Lund","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"185298","messageId":"1330028744-5280-1-git-send-email-kusmabite@gmail.com","threadId":"29714","inReplyTo":null,"subject":"[PATCH] mingw: work around stat-limitation","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-02-23T20:25:44Z","receivedAt":"2012-02-23T20:25:44Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Our stat implementation for Windows always sets st_ino to 0. This\nmeans that checking if isatty(0) and comparing the reported inodes\nof stdout and stdin is not sufficient to detect that both are\npointing to the same TTY.\n\nLuckily, there's only one console on Windows, so adding a check for\nisatty(1) should do the trick. For platforms where inodes are\nreported correctly, this should still be correct.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n\nHere's a proper patch for this glitch.\n\n builtin/merge.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex ed0f959..bef01e3 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1130,6 +1130,7 @@ static int default_edit_option(void)\n \treturn (!fstat(0, &st_stdin) &&\n \t\t!fstat(1, &st_stdout) &&\n \t\tisatty(0) &&\n+\t\tisatty(1) &&\n \t\tst_stdin.st_dev == st_stdout.st_dev &&\n \t\tst_stdin.st_ino == st_stdout.st_ino &&\n \t\tst_stdin.st_mode == st_stdout.st_mode);\n-- \n1.7.9\n"},{"id":"185303","messageId":"alpine.DEB.1.00.1202231525320.3340@s15462909.onlinehome-server.info","threadId":"29714","inReplyTo":"1330028744-5280-1-git-send-email-kusmabite@gmail.com","subject":"Re: [msysGit] [PATCH] mingw: work around stat-limitation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2012-02-23T21:26:14Z","receivedAt":"2012-02-23T21:26:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 23 Feb 2012, Erik Faye-Lund wrote:\n\n> Our stat implementation for Windows always sets st_ino to 0. This\n> means that checking if isatty(0) and comparing the reported inodes\n> of stdout and stdin is not sufficient to detect that both are\n> pointing to the same TTY.\n> \n> Luckily, there's only one console on Windows, so adding a check for\n> isatty(1) should do the trick. For platforms where inodes are\n> reported correctly, this should still be correct.\n\nSorry to ask so stupidly, but why does isatty(1) work and isatty(0) does\nnot? Should they not access the very same console object?\n\nThanks,\nDscho\n"},{"id":"185304","messageId":"CABPQNSZ+=no5PKkaa8_44FbOzh_W4A5knoxKgDQ2wTvOaeKdew@mail.gmail.com","threadId":"29714","inReplyTo":"alpine.DEB.1.00.1202231525320.3340@s15462909.onlinehome-server.info","subject":"Re: [msysGit] [PATCH] mingw: work around stat-limitation","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-02-23T21:36:40Z","receivedAt":"2012-02-23T21:36:40Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Thu, Feb 23, 2012 at 10:26 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Thu, 23 Feb 2012, Erik Faye-Lund wrote:\n>\n>> Our stat implementation for Windows always sets st_ino to 0. This\n>> means that checking if isatty(0) and comparing the reported inodes\n>> of stdout and stdin is not sufficient to detect that both are\n>> pointing to the same TTY.\n>>\n>> Luckily, there's only one console on Windows, so adding a check for\n>> isatty(1) should do the trick. For platforms where inodes are\n>> reported correctly, this should still be correct.\n>\n> Sorry to ask so stupidly, but why does isatty(1) work and isatty(0) does\n> not? Should they not access the very same console object?\n>\n\nThe point is that they might not. The old test would draw the wrong\nconclusion if isatty(0) was true, but isatty(1) was not because it\nused st_ino to verify that stdin and stdout pointed to the same\nterminal. The reason it did that was to catch cases where stdin and\nstdout pointed to different terminals, AFAICT. Not checking isatty(1)\nwas simply an optimization, which works when st_ino is filled out\ncorrectly.\n\nOn Windows there is only one terminal, so it's sufficient to check if\nboth are connected.\n"},{"id":"185305","messageId":"alpine.DEB.1.00.1202231636310.3340@s15462909.onlinehome-server.info","threadId":"29714","inReplyTo":"CABPQNSZ+=no5PKkaa8_44FbOzh_W4A5knoxKgDQ2wTvOaeKdew@mail.gmail.com","subject":"Re: [msysGit] [PATCH] mingw: work around stat-limitation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2012-02-23T22:37:39Z","receivedAt":"2012-02-23T22:37:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi kusma,\n\nOn Thu, 23 Feb 2012, Erik Faye-Lund wrote:\n\n> On Thu, Feb 23, 2012 at 10:26 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > On Thu, 23 Feb 2012, Erik Faye-Lund wrote:\n> >\n> >> Our stat implementation for Windows always sets st_ino to 0. This\n> >> means that checking if isatty(0) and comparing the reported inodes\n> >> of stdout and stdin is not sufficient to detect that both are\n> >> pointing to the same TTY.\n> >>\n> >> Luckily, there's only one console on Windows, so adding a check for\n> >> isatty(1) should do the trick. For platforms where inodes are\n> >> reported correctly, this should still be correct.\n> >\n> > Sorry to ask so stupidly, but why does isatty(1) work and isatty(0) does\n> > not? Should they not access the very same console object?\n> >\n> \n> The point is that they might not. The old test would draw the wrong\n> conclusion if isatty(0) was true, but isatty(1) was not because it\n> used st_ino to verify that stdin and stdout pointed to the same\n> terminal. The reason it did that was to catch cases where stdin and\n> stdout pointed to different terminals, AFAICT. Not checking isatty(1)\n> was simply an optimization, which works when st_ino is filled out\n> correctly.\n> \n> On Windows there is only one terminal, so it's sufficient to check if\n> both are connected.\n\nAh, okay. Thanks for answering so patiently!\n\nACK.\n\nCiao,\nDscho\n"}]}