git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-diff-index -C problem
@ 2007-06-18  5:48 Govind Salinas
  2007-06-18  6:26 ` Shawn O. Pearce
  0 siblings, 1 reply; 2+ messages in thread
From: Govind Salinas @ 2007-06-18  5:48 UTC (permalink / raw)
  To: git

I am writing a porcelain for git and I have been playing with
git-diff-index. I noticed that if i copy a file and git-add the copy
it shows the file added, as i expect...

But then if i then say git-add on the original file, i expect that -C
would check that file to see if it was copied, it does not.  If i
touch the file, then git detects the copy, so git-add is not forcing
git to consider the file modified.

I would be happy if there was a way that I could tell git that a file
was modified for this purpose.  Otherwise I will have to open/close a
file in which the user may be working, which I shouldn't do from my
app (windows problem modifying open docs).  Maybe make "git-add -f" do
that?

Thanks,
Govind.

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

* Re: git-diff-index -C problem
  2007-06-18  5:48 git-diff-index -C problem Govind Salinas
@ 2007-06-18  6:26 ` Shawn O. Pearce
  0 siblings, 0 replies; 2+ messages in thread
From: Shawn O. Pearce @ 2007-06-18  6:26 UTC (permalink / raw)
  To: Govind Salinas; +Cc: git

Govind Salinas <govindsalinas@gmail.com> wrote:
> I am writing a porcelain for git and I have been playing with
> git-diff-index. I noticed that if i copy a file and git-add the copy
> it shows the file added, as i expect...
> 
> But then if i then say git-add on the original file, i expect that -C
> would check that file to see if it was copied, it does not.  If i
> touch the file, then git detects the copy, so git-add is not forcing
> git to consider the file modified.

Oddly enough if you add --find-copies-harder Git does actually
find the copy then, without needing to make the file stat-dirty
in the index.

  $ rm -rf foo;mkdir foo;cd foo;git init
  Initialized empty Git repository in .git/

  $ echo hello >a;git add a; git commit -m a
  Created initial commit 9d2537b: a
   1 files changed, 1 insertions(+), 0 deletions(-)
   create mode 100644 a

  $ cp a b;git add b
  $ git diff-index --abbrev HEAD
  :000000 100644 0000000... ce01362... A  b
  $ git diff-index --abbrev -C HEAD
  :000000 100644 0000000... ce01362... A  b
  $ git diff-index --abbrev -C --find-copies-harder HEAD
  :100644 100644 ce01362... ce01362... C100       a       b

  $ touch a
  $ git diff-index --abbrev -C HEAD
  :100644 100644 ce01362... 0000000... M  a
  :100644 100644 ce01362... ce01362... C100       a       b

I *think* the reason this happens is because -C means to find a copy
among the other modified files.  Because "a" was not modified (unless
it is stat-dirty or otherwise modified) then "b" is not a copy of it.

The --find-copies-harder makes us also look at the unmodified files,
and there we find the copy.

Indeed, the documentation says exactly that:

  --find-copies-harder::
      For performance reasons, by default, `-C` option finds copies only
      if the original file of the copy was modified in the same
      changeset.  This flag makes the command
      inspect unmodified files as candidates for the source of
      copy.  This is a very expensive operation for large
      projects, so use it with caution.  Giving more than one
      `-C` option has the same effect.

So what you are seeing is actually as designed, and documented.

-- 
Shawn.

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

end of thread, other threads:[~2007-06-18  6:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-18  5:48 git-diff-index -C problem Govind Salinas
2007-06-18  6:26 ` Shawn O. Pearce

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).