Re: suggested feature: someone mails me a blob, git please tell me what it is
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Feb 16, 2007, 17:37 UTC
- Message-ID
- <Pine.LNX.4.64.0702160930130.20368@woody.linux-foundation.org>
- In-Reply-To
- <vpqr6sq58j8.fsf@olympe.imag.fr>
On Fri, 16 Feb 2007, Matthieu Moy wrote:
> > But it should be possible to recompute the git sha1sum by recomputing > the magic formula sha1sum(<ascii type without space> + <space> + > <ascii decimal size> + <byte\0> + <binary object data>).
Yes. Try this:
[torvalds@woody git]$ ls -l Makefile -rw-rw-rw- 1 torvalds torvalds 27586 Feb 14 13:35 Makefile [torvalds@woody git]$ ( echo -en "blob 27586\0" ; cat Makefile ) | sha1sum ebecbbd9c28390654ed9fea2ff4ebf6a5a317c70 -
[torvalds@woody git]$ git ls-tree HEAD Makefile 100644 blob ebecbbd9c28390654ed9fea2ff4ebf6a5a317c70 Makefile
and notice how the SHA1's match (ebecbb..).
Now, finding all of the copies of that particular object in history is pretty expensive. You'll basically have to do something like
git rev-list --all | while read i do files=$(git ls-tree -r $i | grep $SHA1) if [ -n "$files" ] then git cat-file -p $i echo $files echo fi done
which is quite expensive. You can probably start from "git fsck" and ask it to print out where it found something (but then it will print out only the first time it found it - because it avoids walking trees more than once it won't report on it unless if finds it in two trees that are different).
Linus