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

6 messages from 2007-02-16 to 2007-02-17. Participants: Mike Coleman, Nicolas Pitre, Matthieu Moy, Linus Torvalds, Shawn O. Pearce, Andy Parkins.
Thread: https://gitlist.dev/t/6847

## Mike Coleman, 2007-02-16 16:23

Subject: suggested feature: someone mails me a blob, git please tell me what it is
Message-ID: <3c6c07c20702160823j316c52f4pe4cf5ca8a882e194@mail.gmail.com>
URL: https://gitlist.dev/e/3c6c07c20702160823j316c52f4pe4cf5ca8a882e194%40mail.gmail.com

```
Here's a suggestion for a git feature, if git doesn't already have it.
 Since git generally doesn't use RCS-style keyword cookies (like
"$Id$"), it'd be nice to have some other way to identify an installed
file.  Perhaps you'd want to know exactly what rev a user is running,
for example.

It seems like it should be fairly easy, given a blob (the file), for
git to describe what it knows about it.  For example, it could provide
a list of commits that it's a part of, etc.  It'd be *really* nice if
only the output of the sha1sum command on the blob were needed.  (I
can't recall exactly how git's blob SHA1's are computed--maybe this
isn't feasible.)

Mike

```

## Nicolas Pitre, 2007-02-16 16:48

Subject: Re: suggested feature: someone mails me a blob, git please tell me what it is
Message-ID: <alpine.LRH.0.82.0702161136460.18370@xanadu.home>
URL: https://gitlist.dev/e/alpine.LRH.0.82.0702161136460.18370%40xanadu.home
In-Reply-To: <3c6c07c20702160823j316c52f4pe4cf5ca8a882e194@mail.gmail.com>

```
On Fri, 16 Feb 2007, Mike Coleman wrote:

> Here's a suggestion for a git feature, if git doesn't already have it.
> Since git generally doesn't use RCS-style keyword cookies (like
> "$Id$"), it'd be nice to have some other way to identify an installed
> file.  Perhaps you'd want to know exactly what rev a user is running,
> for example.
> 
> It seems like it should be fairly easy, given a blob (the file), for
> git to describe what it knows about it.  For example, it could provide
> a list of commits that it's a part of, etc.  

That is possible, but would be expensive similar to git-fsck-objects.  
All objects for each commit would need to be searched for the matching 
sha1.

> It'd be *really* nice if only the output of the sha1sum command on the 
> blob were needed.  (I can't recall exactly how git's blob SHA1's are 
> computed--maybe this isn't feasible.)

GIT adds a header of its own before object data.  You therefore need to 
use git-hash-object not sha1sum to get the right sha1 value.


Nicolas

```

## Matthieu Moy, 2007-02-16 17:14

Subject: Re: suggested feature: someone mails me a blob, git please tell me what it is
Message-ID: <vpqr6sq58j8.fsf@olympe.imag.fr>
URL: https://gitlist.dev/e/vpqr6sq58j8.fsf%40olympe.imag.fr
In-Reply-To: <3c6c07c20702160823j316c52f4pe4cf5ca8a882e194@mail.gmail.com>

```
"Mike Coleman" <tutufan@gmail.com> writes:

> It seems like it should be fairly easy, given a blob (the file), for
> git to describe what it knows about it.  For example, it could provide
> a list of commits that it's a part of, etc.  It'd be *really* nice if
> only the output of the sha1sum command on the blob were needed. 

"git cat-file -p" does almost this : given the sha1sum for a blob, it
will give the header and the content of the blob ...

> (I can't recall exactly how git's blob SHA1's are computed--maybe
> this isn't feasible.)

... but this is where it doesn't work :
http://www.kernel.org/pub/software/scm/git/docs/v1.5.0/git.html#Discussion
explains that the sha1sum used by git is the one of the blob _plus_
its header, so it's not the one you get with "sha1sum file".

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

-- 
Matthieu

```

## Linus Torvalds, 2007-02-16 17:37

Subject: Re: suggested feature: someone mails me a blob, git please tell me what it is
Message-ID: <Pine.LNX.4.64.0702160930130.20368@woody.linux-foundation.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0702160930130.20368%40woody.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

```

## Shawn O. Pearce, 2007-02-17 06:10

Subject: Re: suggested feature: someone mails me a blob, git please tell me what it is
Message-ID: <20070217061016.GA27813@spearce.org>
URL: https://gitlist.dev/e/20070217061016.GA27813%40spearce.org
In-Reply-To: <3c6c07c20702160823j316c52f4pe4cf5ca8a882e194@mail.gmail.com>

```
Mike Coleman <tutufan@gmail.com> wrote:
> Here's a suggestion for a git feature, if git doesn't already have it.
> Since git generally doesn't use RCS-style keyword cookies (like
> "$Id$"), it'd be nice to have some other way to identify an installed
> file.  Perhaps you'd want to know exactly what rev a user is running,
> for example.
> 
> It seems like it should be fairly easy, given a blob (the file), for
> git to describe what it knows about it.  For example, it could provide
> a list of commits that it's a part of, etc.  It'd be *really* nice if
> only the output of the sha1sum command on the blob were needed.  (I
> can't recall exactly how git's blob SHA1's are computed--maybe this
> isn't feasible.)

Rather than embedding something like "$Id$" on a per-file basis
use the output of git-describe in your build process to insert the
string into your executable file(s), and then provide a way to let
the user extract it, or insert it with a unique enough pattern that
you can grep for it in the output of `strings`.

This is what git does itself.  We replace GIT_VERSION in git.c
with the output of git-describe during compile time (C preprocessor
macro).  The value can be printed by the user with `git version`.
We also embed it into some Perl scripts.

git-gui does the same thing, but is a Tcl/Tk script.

-- 
Shawn.

```

## Andy Parkins, 2007-02-17 21:40

Subject: Re: suggested feature: someone mails me a blob, git please tell me what it is
Message-ID: <200702172140.54203.andyparkins@gmail.com>
URL: https://gitlist.dev/e/200702172140.54203.andyparkins%40gmail.com
In-Reply-To: <20070217061016.GA27813@spearce.org>

```
On Saturday 2007, February 17, Shawn O. Pearce wrote:

> Rather than embedding something like "$Id$" on a per-file basis
> use the output of git-describe in your build process to insert the

Actually this isn't entirely enough.  The /only/ thing I miss from 
subversion is $Id$; but not in source files - that's easily solved with 
a bit of git-describe magic in the Makefile - no, I miss embedding it 
inkscape generated .svg files, so that my title block on diagrams gets 
automatically assigned a version code.

Q: How lazy am I?  A: I can't be bothered to say... 

Andy

-- 
Dr Andrew Parkins, M Eng (Hons), AMIEE
andyparkins@gmail.com

```
