Re: suggested feature: someone mails me a blob, git please tell me what it is

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

 




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
-
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]