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

[RFC/PATCH] hash-object doc: "git hash-object -w" can write invalid objects

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 22, 2013, 23:01 UTC
Message-ID
<20130222230132.GB4514@google.com>
In-Reply-To
<kg8ri2$vjb$1@ger.gmane.org>

When using "hash-object -w" to create non-blob objects, it is generally a good policy to run "git fsck" afterward to make sure the resulting object is valid. Add a warning to the manpage.

While it at, gently nudge the user of "hash-object -w" toward higher-level interfaces for creating or modifying trees, commits, and tags.

Reported-by: Mantas Mikulėnas <grawity@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Hi Mantas,
Mantas Mikulėnas wrote:
> When messing around with various repositories, I noticed that git 1.8
> (currently using 1.8.2.rc0.22.gb3600c3) has problems parsing tag objects
> that have invalid timestamps.
[...]
> Git doesn't handle the resulting tag objects nicely at all. For example,
> running `git cat-file -p` on the new object outputs a really odd
> timestamp "Thu Jun Thu Jan 1 00:16:09 1970 +0016" (I'm guessing it
> parses the year as Unix time),

The usual rule is that with invalid objects (e.g. as detected by "git fsck"), any non-crash result is acceptable. Garbage in, garbage out.

>                                and `git show` outright crashes
> (backtrace included below.)
Probably worth fixing.

I notice that git-hash-object(1) doesn't contain any reference to git-fsck(1). How about something like this, to start?

Perhaps by default hash-object should automatically fsck the objects it is asked to create.

Thanks, Jonathan

 Documentation/git-hash-object.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt
index 02c1f12..8ed8c6e 100644
--- a/Documentation/git-hash-object.txt
+++ b/Documentation/git-hash-object.txt
@@ -30,6 +30,8 @@ OPTIONS
 
 -w::
 	Actually write the object into the object database.
+	This does not check that the resulting object is valid;
+	for that, see linkgit:git-fsck[1].
 
 --stdin::
 	Read the object from standard input instead of from a file.
@@ -53,6 +55,14 @@ OPTIONS
 	conversion. If the file is read from standard input then this
 	is always implied, unless the --path option is given.
 
+SEE ALSO
+--------
+linkgit:git-mktree[1],
+linkgit:git-commit-tree[1],
+linkgit:git-tag[1],
+linkgit:git-filter-branch[1],
+sha1sum(1)
+
 GIT
 ---
 Part of the linkgit:git[1] suite
-- 
1.8.1.4
Previous: Mantas MikulėnasNext: Junio C Hamano
Message 14 of 16 in “Crashes while trying to show tag objects with bad timestamps”
  1. Mantas MikulėnasFeb 22, 2013
  2. Jeff KingFeb 22, 2013
  3. Junio C HamanoFeb 22, 2013
  4. Jeff KingFeb 22, 2013
  5. Mantas MikulėnasFeb 22, 2013
  6. Jeff KingFeb 25, 2013
  7. Junio C HamanoFeb 22, 2013
  8. Jeff KingFeb 25, 2013
  9. 1/4 handle malformed dates in ident linesJeff King, Feb 25, 2013
  10. 2/4 skip_prefix: return a non-const pointerJeff King, Feb 25, 2013
  11. 3/4 fsck: check "tagger" linesJeff King, Feb 25, 2013
  12. 4/4 cat-file: print tags raw for "cat-file -p"Jeff King, Feb 25, 2013
  13. Mantas MikulėnasFeb 25, 2013
  14. hash-object doc: "git hash-object -w" can write invalid objectsJonathan Nieder, Feb 22, 2013
  15. Junio C HamanoFeb 22, 2013
  16. Jeff KingFeb 22, 2013

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.