git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* diff-files inconsistency with touched files
@ 2009-09-02 17:27 James Spencer
  2009-09-02 19:28 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: James Spencer @ 2009-09-02 17:27 UTC (permalink / raw)
  To: git

Hi,

I am puzzled by the following behaviour:

$ git --version
git version 1.6.4.2
$ git diff-files
$ touch test
$ git diff-files
:100644 100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 
0000000000000000000000000000000000000000 M  test
$ git diff
$ git diff-files
$

I don't understand why git diff-files reports a file is changed when 
that file is touched nor why running git diff changes this to (what I 
think is) the correct behaviour.

Thanks in advance,

    --James

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: diff-files inconsistency with touched files
  2009-09-02 17:27 diff-files inconsistency with touched files James Spencer
@ 2009-09-02 19:28 ` Jeff King
  2009-09-03 16:18   ` James Spencer
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2009-09-02 19:28 UTC (permalink / raw)
  To: James Spencer; +Cc: git

On Wed, Sep 02, 2009 at 06:27:15PM +0100, James Spencer wrote:

> $ git diff-files
> $ touch test
> $ git diff-files
> :100644 100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4
> 0000000000000000000000000000000000000000 M  test
> $ git diff
> $ git diff-files
> $
> 
> I don't understand why git diff-files reports a file is changed when
> that file is touched nor why running git diff changes this to (what I
> think is) the correct behaviour.

Git uses the stat information of a file to know whether what we have
cached in the index is up-to-date or not. So in the first diff-files, we
don't even have to look at the contents of "test"; we see that it hasn't
changed since the last time we looked at the contents, and that its
sha-1 matches what's in the index, so there is no diff.

By running "touch", you have changed the stat information, so we believe
there may be a difference. But we don't actually know what's _in_ the
new side, so we just print the null sha1 instead of the actual sha1
contents.

Diff-files _could_ refresh the cache each time it runs, but we
intentionally do not do that. Doing so is a little bit expensive, and
because diff-files is intended as a low-level tool for scripts, we give
the script the flexibility (and responsibility) of refreshing the cache
when it wants to. So you could do:

  $ git update-index --refresh
  $ git diff-files

and get clean output.

You see different behavior from "git diff" because it is meant for user
consumption and therefore refreshes the cache automatically at the
beginning of every run.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: diff-files inconsistency with touched files
  2009-09-02 19:28 ` Jeff King
@ 2009-09-03 16:18   ` James Spencer
  0 siblings, 0 replies; 3+ messages in thread
From: James Spencer @ 2009-09-03 16:18 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King wrote:
> On Wed, Sep 02, 2009 at 06:27:15PM +0100, James Spencer wrote:
> 
>> $ git diff-files
>> $ touch test
>> $ git diff-files
>> :100644 100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4
>> 0000000000000000000000000000000000000000 M  test
>> $ git diff
>> $ git diff-files
>> $
>>
>> I don't understand why git diff-files reports a file is changed when
>> that file is touched nor why running git diff changes this to (what I
>> think is) the correct behaviour.
> 
> Git uses the stat information of a file to know whether what we have
> cached in the index is up-to-date or not. So in the first diff-files, we
> don't even have to look at the contents of "test"; we see that it hasn't
> changed since the last time we looked at the contents, and that its
> sha-1 matches what's in the index, so there is no diff.
> 
> By running "touch", you have changed the stat information, so we believe
> there may be a difference. But we don't actually know what's _in_ the
> new side, so we just print the null sha1 instead of the actual sha1
> contents.
> 
> Diff-files _could_ refresh the cache each time it runs, but we
> intentionally do not do that. Doing so is a little bit expensive, and
> because diff-files is intended as a low-level tool for scripts, we give
> the script the flexibility (and responsibility) of refreshing the cache
> when it wants to. So you could do:
> 
>   $ git update-index --refresh
>   $ git diff-files
> 
> and get clean output.
> 
> You see different behavior from "git diff" because it is meant for user
> consumption and therefore refreshes the cache automatically at the
> beginning of every run.
> 
> -Peff

Thanks for your help!

    --James

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-03 16:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-02 17:27 diff-files inconsistency with touched files James Spencer
2009-09-02 19:28 ` Jeff King
2009-09-03 16:18   ` James Spencer

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 NNTP newsgroup(s).