[PATCH 6/6] Add fsck_verify_ref_to_tag_object() to verify that refname matches name stored in tag object

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

On Monday 28 May 2007, Junio C Hamano wrote:

This patch adds the check described by Junio.

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin-fsck.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/builtin-fsck.c b/builtin-fsck.c
index a8914ae..379317e 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -515,6 +515,25 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in
 	return 0;
 }
 
+static void fsck_verify_ref_to_tag_object(const char *refname, struct object *obj)
+{
+	/* Verify that refname matches the name stored in obj's "tag" header */
+	struct tag *tagobj = (struct tag *) parse_object(obj->sha1);
+	size_t tagname_len = strlen(tagobj->tag);
+	size_t refname_len = strlen(refname);
+
+	if (!tagname_len) return; /* No tag name stored in tagobj. Nothing to do. */
+
+	if (tagname_len < refname_len &&
+	    !memcmp(tagobj->tag, refname + (refname_len - tagname_len), tagname_len) &&
+	    refname[(refname_len - tagname_len) - 1] == '/') {
+		/* OK: tag name is "$name", and refname ends with "/$name" */
+		return;
+	}
+	else
+		error("%s: Mismatch between tag ref and tag object's name %s", refname, tagobj->tag);
+}
+
 static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
 {
 	struct object *obj;
@@ -529,6 +548,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
 		/* We'll continue with the rest despite the error.. */
 		return 0;
 	}
+	if (obj->type == OBJ_TAG) /* ref to tag object */
+		fsck_verify_ref_to_tag_object(refname, obj);
 	default_refs++;
 	obj->used = 1;
 	mark_reachable(obj, REACHABLE);
-- 
1.5.2

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/6] Refactor the tag object, Johan Herland, (Sun Jun 3, 5:51 pm)
[PATCH 6/6] Add fsck_verify_ref_to_tag_object() to verify ..., Johan Herland, (Sun Jun 3, 5:54 pm)
Re: [PATCH 3/6] git-fsck: Do thorough verification of tag ..., Matthias Lederhofer, (Sun Jun 3, 10:56 pm)
Re: [PATCH 0/6] Refactor the tag object, Junio C Hamano, (Mon Jun 4, 1:32 pm)
[PATCH 0/7] Introduce soft references (softrefs), Johan Herland, (Sat Jun 9, 11:19 am)
[PATCH 2/7] Softrefs: Add implementation of softrefs API, Johan Herland, (Sat Jun 9, 11:22 am)
Comment on weak refs, Junio C Hamano, (Sat Jun 9, 4:55 pm)
Re: Comment on weak refs, Johan Herland, (Sat Jun 9, 6:25 pm)
Re: Comment on weak refs, Johannes Schindelin, (Sat Jun 9, 11:33 pm)
Re: [PATCH 1/7] Softrefs: Add softrefs header file with AP ..., Johannes Schindelin, (Sat Jun 9, 11:58 pm)
Re: [PATCH 1/7] Softrefs: Add softrefs header file with AP ..., Johannes Schindelin, (Sun Jun 10, 12:54 am)
Re: [PATCH] Change softrefs file format from text (82 byte ..., Johannes Schindelin, (Sun Jun 10, 1:02 am)
Re: Comment on weak refs, Pierre Habouzit, (Sun Jun 10, 2:03 am)
Re: [PATCH] Change softrefs file format from text (82 byte ..., Johannes Schindelin, (Sun Jun 10, 2:46 am)
Re: Comment on weak refs, Johan Herland, (Sun Jun 10, 6:41 am)
Re: Comment on weak refs, Pierre Habouzit, (Sun Jun 10, 7:09 am)
Re: Comment on weak refs, Pierre Habouzit, (Sun Jun 10, 7:25 am)