From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Junio C Hamano <junkio@cox.net>
Subject: [PATCH 07/15] git-note: (Almost plumbing) Add support for git notes to git-pack-refs and git-fsck
Date: Sun, 27 May 2007 16:13:36 +0200 [thread overview]
Message-ID: <200705271613.36648.johan@herland.net> (raw)
In-Reply-To: <200705271608.02122.johan@herland.net>
Teach git-pack-refs to pack note refs in the same way that regular
tag refs are packed. Also, make sure to clean up empty subdirs in
refs/notes after packing note refs.
Teach git-fsck some extra checking of note refs.
Signed-off-by: Johan Herland <johan@herland.net>
---
builtin-fsck.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
builtin-pack-refs.c | 5 +++-
2 files changed, 65 insertions(+), 1 deletions(-)
diff --git a/builtin-fsck.c b/builtin-fsck.c
index cbbcaf0..edbb976 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -522,9 +522,70 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
return 0;
}
+static int fsck_handle_note_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+{
+ /*
+ * - Verify that refname has format $object/$note
+ * - Verify that contents of $object/$note == $note
+ * - Verify that $object/$note references a tag object
+ * - Verify that the tag object points to $object
+ * - Verify that $object exists. (already done by fsck_tag())
+ */
+ /* Even on error, we still return 0 to keep for_each_ref() going. */
+
+ const char *object_name = refname;
+ const char *note_name = strchr(object_name, '/');
+ size_t object_name_len, note_name_len;
+ unsigned char object_sha1[20], note_sha1[20];
+ struct object *note_obj;
+ struct tag *note;
+
+ if (!note_name) {
+ error("%s: invalid note refname; missing note part", refname);
+ return 0;
+ }
+ object_name_len = note_name - object_name;
+ note_name_len = strlen(++note_name);
+ if (object_name_len != 40 || get_sha1_hex(object_name, object_sha1)) {
+ error("%s: invalid note refname; object part not valid SHA1 sum", refname);
+ return 0;
+ }
+ if (note_name_len != 40 || get_sha1_hex(note_name, note_sha1)) {
+ error("%s: invalid note refname; note part not valid SHA1 sum", refname);
+ return 0;
+ }
+ if (hashcmp(note_sha1, sha1)) {
+ error("%s: invalid note ref; note part not identical to note's SHA1 sum (%s)",
+ refname, sha1_to_hex(sha1));
+ return 0;
+ }
+ note_obj = lookup_object(sha1);
+ if (!note_obj) { /* Couldn't find note object... */
+ if (!has_sha1_file(sha1)) /* ...and it's not hidden in a pack */
+ error("%s: invalid note ref; must point at a valid object",
+ refname);
+ return 0; /* Return even if in a pack. */
+ }
+ if (note_obj->type != OBJ_TAG) {
+ error("%s: invalid note ref; must point at tag object (type == %s)",
+ refname, typename(note_obj->type));
+ return 0;
+ }
+ note = (struct tag *) parse_object(sha1);
+ if (hashcmp(note->tagged->sha1, object_sha1)) {
+ error("%s: invalid note ref; "
+ "object part not identical to tagged object (%s)",
+ refname, sha1_to_hex(note->tagged->sha1));
+ return 0;
+ }
+
+ return 0;
+}
+
static void get_default_heads(void)
{
for_each_ref(fsck_handle_ref, NULL);
+ for_each_note_ref(fsck_handle_note_ref, NULL);
if (include_reflogs)
for_each_reflog(fsck_handle_reflog, NULL);
diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c
index 1952950..57b9fee 100644
--- a/builtin-pack-refs.c
+++ b/builtin-pack-refs.c
@@ -39,6 +39,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
if ((flags & REF_ISSYMREF))
return 0;
is_tag_ref = !prefixcmp(path, "refs/tags/");
+ is_tag_ref |= !prefixcmp(path, "refs/notes/");
/* ALWAYS pack refs that were already packed or are tags */
if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref && !(flags & REF_ISPACKED))
@@ -109,8 +110,10 @@ static int pack_refs(unsigned int flags)
die("failed to write ref-pack file (%s)", strerror(errno));
if (commit_lock_file(&packed) < 0)
die("unable to overwrite old ref-pack file (%s)", strerror(errno));
- if (cbdata.flags & PACK_REFS_PRUNE)
+ if (cbdata.flags & PACK_REFS_PRUNE) {
prune_refs(cbdata.ref_to_prune);
+ cleanup_notes_subdirs();
+ }
return 0;
}
--
1.5.2.101.gee49f
next prev parent reply other threads:[~2007-05-27 14:13 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-09 19:20 [RFC] Second parent for reverts Daniel Barkalow
2007-05-09 20:07 ` Johannes Schindelin
2007-05-09 20:22 ` Shawn O. Pearce
2007-05-09 22:26 ` Johan Herland
2007-05-09 21:54 ` Junio C Hamano
2007-05-09 22:16 ` Linus Torvalds
2007-05-10 16:35 ` Linus Torvalds
2007-05-10 18:06 ` Johan Herland
2007-05-10 18:22 ` Linus Torvalds
2007-05-27 14:08 ` [PATCH 00/15] git-note: A mechanisim for providing free-form after-the-fact annotations on commits Johan Herland
2007-05-27 14:09 ` [PATCH 01/15] git-note: Add git-note command for adding/listing/deleting git notes Johan Herland
2007-05-27 14:10 ` [PATCH 02/15] git-note: (Documentation) Add git-note manual page Johan Herland
2007-05-27 14:11 ` [PATCH 03/15] git-note: (Administrivia) Add git-note to Makefile, .gitignore, etc Johan Herland
2007-05-27 14:11 ` [PATCH 04/15] git-note: (Plumbing) Add plumbing-level support for git notes Johan Herland
2007-05-27 14:12 ` [PATCH 05/15] git-note: (Plumbing) Add support for git notes to git-rev-parse and git-show-ref Johan Herland
2007-05-27 14:13 ` [PATCH 06/15] git-note: (Documentation) Explain the new '--notes' option " Johan Herland
2007-05-27 14:13 ` Johan Herland [this message]
2007-05-27 14:14 ` [PATCH 08/15] git-note: (Decorations) Add note decorations to "git-{log,show,whatchanged} --decorate" Johan Herland
2007-05-27 14:14 ` [PATCH 09/15] git-note: (Documentation) Explain new behaviour of --decorate in git-{log,show,whatchanged} Johan Herland
2007-05-27 14:15 ` [PATCH 10/15] git-note: (Transfer) Teach git-clone how to clone notes Johan Herland
2007-05-27 14:15 ` [PATCH 11/15] git-note: (Transfer) Teach git-fetch to auto-follow notes Johan Herland
2007-05-27 14:15 ` [PATCH 12/15] git-note: (Transfer) Teach git-push to push notes when --all or --notes is given Johan Herland
2007-05-27 14:16 ` [PATCH 13/15] git-note: (Documentation) Explain the new --notes option to git-push Johan Herland
2007-05-27 14:16 ` [PATCH 14/15] git-note: (Tests) Add tests for git-note and associated functionality Johan Herland
2007-05-27 14:17 ` [PATCH 15/15] git-note: Add display of notes to gitk Johan Herland
2007-05-27 20:09 ` [PATCH 00/15] git-note: A mechanisim for providing free-form after-the-fact annotations on commits Junio C Hamano
2007-05-28 0:29 ` Johan Herland
2007-05-28 0:59 ` Jakub Narebski
2007-05-28 4:37 ` Linus Torvalds
2007-05-28 10:54 ` Johan Herland
2007-05-28 16:28 ` Linus Torvalds
2007-05-28 16:40 ` Johan Herland
2007-05-28 16:58 ` Linus Torvalds
2007-05-28 17:48 ` Johan Herland
2007-05-28 20:45 ` Junio C Hamano
2007-05-28 21:35 ` Shawn O. Pearce
2007-05-28 23:37 ` Johannes Schindelin
2007-05-29 3:12 ` Linus Torvalds
2007-05-29 3:22 ` Shawn O. Pearce
2007-05-29 7:04 ` Jakub Narebski
2007-05-29 11:04 ` Andy Parkins
2007-05-29 11:12 ` Johannes Schindelin
2007-05-29 7:06 ` Johan Herland
2007-05-29 8:22 ` Jeff King
2007-05-29 9:23 ` Johan Herland
2007-05-28 20:45 ` Junio C Hamano
2007-05-28 21:19 ` Shawn O. Pearce
2007-05-28 23:46 ` [PATCH] Add fsck_verify_ref_to_tag_object() to verify that refname matches name stored in tag object Johan Herland
2007-05-28 17:29 ` [PATCH 00/15] git-note: A mechanisim for providing free-form after-the-fact annotations on commits Michael S. Tsirkin
2007-05-28 17:42 ` Michael S. Tsirkin
2007-05-28 17:58 ` Johan Herland
2007-05-10 22:33 ` [RFC] Second parent for reverts Martin Langhoff
2007-05-10 1:43 ` Junio C Hamano
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=200705271613.36648.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
--cc=torvalds@linux-foundation.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).