On 5/5/2012 4:24 AM, Jeff King wrote:
On Sat, May 05, 2012 at 02:12:44AM -0500, Neal Kreitzinger wrote:Scenario: I detect a binary file that is 'dirty'. I don't know how it got there. However, I know it came from a git repo. So I calculate the sha1 of the binary. What is the git command to determine which commit that binary version first appeared in? And the last commit that binary appeared in?There is no pre-made git commit. I would look at the output of "git log --raw --no-abbrev" in a pager and search for the sha1 in question. That will show you the commits that made it come and go. Note that there may be multiple instances in which the sha1 comes and goes (e.g., two parallel lines of development which both introduce or modify a sha1, or even linear development with reverting). You can script it like this: git log --format=%H --no-abbrev --raw | perl -lne ' BEGIN { $sha1 = shift } if (/^[0-9a-f]{40}$/) { $commit = $_; } elsif (/^:\d+ \d+ ([0-9a-f]{40}) ([0-9a-f]{40}) \S+\t(.*)/) { if ($2 eq $sha1) { # sha1 on "after" side; content probably came into existence if ($1 eq $sha1) { # unless it was that way before, in which case it was a mode change # or rename. Ignore. } else { print "$commit: $sha1 appears (as $3)"; } } elsif ($1 eq $sha1) { # sha1 on "before" side; content went away print "$commit: $sha1 went away (from $3)"; } } ' $sha1_of_interest though I wouldn't bother to do so unless I was going to do some analysis over many files.Why: we have people ftp'ing binaries around. I want to see the commit message and source change of that commit to see what the binary version is.This won't necessarily show you the version they have; it will only show you the version that introduced that particular version of a file. A more general question is "given a set of files, which revision did they come from?". For that, you would want to find the set of commits that contain sha1 A, then intersect them with the set of commits that contain sha1 B, and so forth. You can do that by scripting around "rev-list" and "ls-tree", but it's a little more complicated.
What about this recipe: calculate sha1 of dirty deliverable (binary, html, etc) grep git tree objects for that sha1somehow determine which of the tree sha1's is newest. Not sure how to do that.
grep commit objects for that tree sha1now you have the last commit containing that file so now you know the version of that file.
-neal -- 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
[Newbies FAQ] [Linux Kernel Development] [Free Online Dating] [Gcc Help] [IETF Annouce] [DCCP] [Netdev] [Networking] [Security] [V4L] [Bugtraq] [Free Online Dating] [Photo] [Yosemite] [MIPS Linux] [ARM Linux] [Linux Security] [Linux RAID] [Linux SCSI] [Fedora Users] [Linux Resources]