summaryrefslogtreecommitdiff
path: root/tag.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-10-25 21:20:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-28 05:04:49 (GMT)
commit228c78fbd42b58ebf43477290432c149358b04b1 (patch)
treecee5a6dfc36a973d15f1b30d872866a186e33bfd /tag.c
parent78d50148b955283e027ff46f310a4d3930ad42c0 (diff)
downloadgit-228c78fbd42b58ebf43477290432c149358b04b1.zip
git-228c78fbd42b58ebf43477290432c149358b04b1.tar.gz
git-228c78fbd42b58ebf43477290432c149358b04b1.tar.bz2
commit, tag: don't set parsed bit for parse failures
If we can't parse a commit, then parse_commit() will return an error code. But it _also_ sets the "parsed" flag, which tells us not to bother trying to re-parse the object. That means that subsequent parses have no idea that the information in the struct may be bogus. I.e., doing this: parse_commit(commit); ... if (parse_commit(commit) < 0) die("commit is broken"); will never trigger the die(). The second parse_commit() will see the "parsed" flag and quietly return success. There are two obvious ways to fix this: 1. Stop setting "parsed" until we've successfully parsed. 2. Keep a second "corrupt" flag to indicate that we saw an error (and when the parsed flag is set, return 0/-1 depending on the corrupt flag). This patch does option 1. The obvious downside versus option 2 is that we might continually re-parse a broken object. But in practice, corruption like this is rare, and we typically die() or return an error in the caller. So it's OK not to worry about optimizing for corruption. And it's much simpler: we don't need to use an extra bit in the object struct, and callers which check the "parsed" flag don't need to learn about the corrupt bit, too. There's no new test here, because this case is already covered in t5318. Note that we do need to update the expected message there, because we now detect the problem in the return from "parse_commit()", and not with a separate check for a NULL tree. In fact, we can now ditch that explicit tree check entirely, as we're covered robustly by this change (and the previous recent change to treat a NULL tree as a parse error). We'll also give tags the same treatment. I don't know offhand of any cases where the problem can be triggered (it implies somebody ignoring a parse error earlier in the process), but consistently returning an error should cause the least surprise. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tag.c')
-rw-r--r--tag.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/tag.c b/tag.c
index 6a51efd..71b5444 100644
--- a/tag.c
+++ b/tag.c
@@ -141,7 +141,16 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
if (item->object.parsed)
return 0;
- item->object.parsed = 1;
+
+ if (item->tag) {
+ /*
+ * Presumably left over from a previous failed parse;
+ * clear it out in preparation for re-parsing (we'll probably
+ * hit the same error, which lets us tell our current caller
+ * about the problem).
+ */
+ FREE_AND_NULL(item->tag);
+ }
if (size < the_hash_algo->hexsz + 24)
return -1;
@@ -192,6 +201,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
else
item->date = 0;
+ item->object.parsed = 1;
return 0;
}