From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [IGNORETHIS/PATCH] Choosing the sha1 prefix of your commits
Date: Wed, 19 Oct 2011 15:01:14 -0400 [thread overview]
Message-ID: <20111019190114.GA4670@sigill.intra.peff.net> (raw)
In-Reply-To: <CACBZZX5PqYa0uWiGgs952rk2cy+QRCU95kF63qzSi3fKK-YrCQ@mail.gmail.com>
On Wed, Oct 19, 2011 at 08:03:24PM +0200, Ævar Arnfjörð Bjarmason wrote:
> This is quick hack I wrote just before leaving work to show that I
> could indeed push patches to our main repository starting with
> 31337. Names hidden to protect the innocent.
Clever and amusing.
> Which in just over a minute will generate, in my case:
>
> $ git show --pretty=raw 313375d995e6f8b7773c6ed1ee165e5a9e15690b | head -n 7
> commit 313375d995e6f8b7773c6ed1ee165e5a9e15690b
> tree c9bebc99c05dfe61cccf02ebdf442945c8ff8b3c
> parent 0dce2d45a79d26a593f0e12301cdfeb7eb23c17a
> author Ævar Arnfjörð Bjarmason <avar@example.com> <censored> <censored>
> committer Ævar Arnfjörð Bjarmason <avar@example.com> <censored> <censored>
> lulz 697889
Nice header name.
> I also think it's interesting that we seemingly don't have (in my
> brief search, maybe I missed it) an API for writing a complete commit
> object into a strbuf, so I had to write a lot of commit objects to
> disk, and keep unlinking the unacceptable candidates so the repository
> wouldn't balloon in size.
Calculating an object sha1 is pretty straightforward. I think you could
just tack the "commit <size>" header in front of the commit strbuf, and
sha1 that, and then just send the "winner" to actually be written.
Too bad it won't work in an append only way. The internal state of sha1
after a certain set of bytes is deterministic, so you could do something
like:
void leetify_object(struct strbuf *data)
{
SHA_CTX base, guess;
int len = data->len;
int i = 0;
/* come up with a base internal state representing
* the commit */
SHA1_Init(&base);
SHA1_Update(&base, data->buf, data->len);
while (1) {
char append[64];
int n = snprintf(append, sizeof(append),
"x-lulz-by: %d\n", i);
unsigned char sha1[20];
/* and then from that state, see what the sha1 would
* be if we add our few new bytes */
memcpy(&guess, &base, sizeof(guess));
SHA1_Update(&guess, append, n);
SHA1_Final(sha1, &guess);
/* did we pick a winner? */
if (sha1[0] == 0x31 &&
sha1[1] == 0x33 &&
&sha1[2] & 0xf0) == 0x70) {
strbuf_addstr(data, append);
return;
}
i++;
}
}
There are two problems with this:
1. The x-lulz-by header is visible in the commit message. I think you
can actually get around this by appending a NUL character, and "git
log" and friends will stop processing the commit message there.
2. The object header will actually have the length of the object at
the beginning. So as your lulz number grows, the length of the
object will change, and invalidate your earlier sha1. You could get
around this by using a fixed-size guess (e.g., start with 20 bytes
of zeroes, and then just keep incrementing).
-Peff
next prev parent reply other threads:[~2011-10-19 19:01 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-19 18:03 [IGNORETHIS/PATCH] Choosing the sha1 prefix of your commits Ævar Arnfjörð Bjarmason
2011-10-19 19:01 ` Jeff King [this message]
2011-10-19 19:38 ` Jeff King
2011-10-20 2:51 ` Jeff King
2011-10-20 4:15 ` Kyle Moffett
2011-10-20 4:25 ` Jeff King
2011-10-20 4:27 ` Junio C Hamano
2011-10-20 4:32 ` Kyle Moffett
2011-10-24 20:47 ` Jeff King
2011-10-20 4:31 ` Junio C Hamano
2011-10-20 4:34 ` Jeff King
2011-10-20 6:57 ` Junio C Hamano
2011-10-20 7:13 ` Jeff King
2011-10-20 13:14 ` Ted Ts'o
2011-10-20 15:56 ` Jeff King
2011-10-25 22:35 ` Drew Northup
2011-10-20 18:36 ` Re* " Junio C Hamano
2011-10-20 19:00 ` Jeff King
2011-10-20 7:27 ` Nguyen Thai Ngoc Duy
2011-10-20 9:14 ` Nguyen Thai Ngoc Duy
2011-10-20 15:44 ` Jeff King
2011-10-20 9:38 ` Mikael Magnusson
2011-10-20 13:44 ` Elijah Newren
2011-10-19 22:09 ` Jonathan Nieder
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=20111019190114.GA4670@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
/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).