Re: Is a given file known to git?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christoph Duelli <duelli@xxxxxxxxxxxx> writes:

> Yes, thank you, Johannes and Shawn, this works.
> (A bit slow, though: with this test enabled my script takes 77 secs;
> without it it takes 0.3 secs. The time is spent in 9000 calls to the
> above test (the rev-parse version). (ok, the fact that there is a Perl
> system call around it might take some time, too).)
>
> [For the record:
> Shawn's ls-files variant takes: 148 secs
> Shawn's cat-file variant takes: 251 secs
> Time taken by time; roughly half user, half system.
> ]
>
> As this script won't run often, that not too big a deal.

I suspect that you asked a wrong question.  If the original question were
"I have a git managed project whose tip has about 8000 paths in it, and I
have 9000 paths that may or may not belong to the tip.  How do I find the
paths that are not part of the tip" (or "How do I find the ones that are
part of the tip"), the answer would have been quite different.

	git ls-files | sort >known
        	(or "git ls-tree --name-only -r HEAD | sort >known")
        $list_your_paths_one_per_line | sort | comm known -

would compare the set of paths in the index (or HEAD) and the set of the
paths you are interested in, and give you the list of ones that are only
present in one side, the other, or both.  Say "comm -13" instead of "comm"
if you are only interested in untracked ones, and say "comm -12" if you
are only interested in tracked ones.  Since you are working inside Perl,
probably you would not pipe to sort/comm but do the comm part yourself, I
would imagine.

It is as if you asked "how do I add one to a given number", without saying
that "I have 9000 paths and I want to repeatedly add one for each path I
have", people taught you the answer to your original question, and you
ended up looping "n := n + 1" 9000 times.  If you told them the real
problem you were trying to solve upfront, they would have taught you how
to multiply instead ;-).
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux