git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: tag format and tests

From
Jeff King <peff@peff.net>
Date
May 30, 2011, 16:02 UTC
Message-ID
<20110530160203.GB24431@sigill.intra.peff.net>
In-Reply-To
<db6ec478a7cb9b963d90651f5315ffec@ensimag.fr>
On Mon, May 30, 2011 at 04:12:30PM +0200, David Glesser wrote:
Show 35 quoted lines
> This error comes from libgit2 and how it writes the timestamp, see below:
> 
> $ cat tag && echo
> object 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
> type blob
> tag hellotag
> tagger SpongeBob <spongebob.square@crusty-crabs.com> 0000000000 +0000
> 
> cheeseburger
> $ git mktag < tag
> 7eade44ddd1b9ee24a44e0b2dde2561efea7f7d6
> $ echo 7eade44ddd1b9ee24a44e0b2dde2561efea7f7d6 | git cat-file --batch
> 7eade44ddd1b9ee24a44e0b2dde2561efea7f7d6 tag 154
> object 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
> type blob
> tag hellotag
> tagger SpongeBob <spongebob.square@crusty-crabs.com> 0000000000 +0000
> 
> cheeseburger
> 
> 
> And now using libgit2 :
> 
> $ git2 mktag < tag
> 49bc784cd2071c97a14841b3eab1181dd1c8fbcd
> $ echo 49bc784cd2071c97a14841b3eab1181dd1c8fbcd | git cat-file --batch
> 49bc784cd2071c97a14841b3eab1181dd1c8fbcd tag 145
> object 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
> type blob
> tag hellotag
> tagger SpongeBob <spongebob.square@crusty-crabs.com> 0 +0000
> 
> cheeseburger
> 
> Both formats are accepted by git.

Yes, both are valid timestamps. And git itself, when creating a tag via "git tag", will not write silly leading zeroes. But in this test, we are using mktag, which is creating a tag object from already-formatted input. So the question is not whether the date-formatting is a problem, but rather whether mktag should do be doing _any_ modification or canonicalization of its input at all.

And I think the answer is "no", because we may be handing gpg-signed contents to mktag, and any change could invalidate that signature. So libgit2 is wrong to munge the data.

I imagine your code parses the buffer into a tag object, checks that it parsed properly, then writes out that object. I think instead you need to parse the buffer into a tag object, check that it parsed, and then write the _original_ buffer into a tag object.

-Peff
Previous: David GlesserNext: David Glesser
Message 2 of 3 in “tag format and tests”
  1. David GlesserMay 30, 2011
  2. Jeff KingMay 30, 2011
  3. David GlesserMay 30, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.