From: Neal Kreitzinger <nkreitzinger@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: how to determine version of binary
Date: Sat, 05 May 2012 11:18:13 -0500 [thread overview]
Message-ID: <4FA552C5.7090000@gmail.com> (raw)
In-Reply-To: <20120505092443.GB8172@sigill.intra.peff.net>
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 sha1
somehow determine which of the tree sha1's is newest. Not sure how to
do that.
grep commit objects for that tree sha1
now you have the last commit containing that file so now you know the
version of that file.
-neal
next prev parent reply other threads:[~2012-05-05 16:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 7:12 how to determine version of binary Neal Kreitzinger
2012-05-05 9:24 ` Jeff King
2012-05-05 16:18 ` Neal Kreitzinger [this message]
2012-05-06 12:43 ` Jeff King
2012-05-05 11:43 ` Sitaram Chamarty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FA552C5.7090000@gmail.com \
--to=nkreitzinger@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).