[PATCH 07/18] builtin/notes.c: Split notes ref DWIMmery into a separate function

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johan Herland
Date: Tuesday, September 28, 2010 - 5:23 pm

expand_notes_ref() is a new function that performs the DWIM transformation
of "foo" -> "refs/notes/foo" where notes refs are expected.

This is done in preparation for future patches which will also need this
DWIM functionality.

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/notes.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 35f6eb6..9c91c59 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -83,6 +83,16 @@ struct msg_arg {
 	struct strbuf buf;
 };
 
+static void expand_notes_ref(struct strbuf *sb)
+{
+	if (!prefixcmp(sb->buf, "refs/notes/"))
+		return; /* we're happy */
+	else if (!prefixcmp(sb->buf, "notes/"))
+		strbuf_insert(sb, 0, "refs/", 5);
+	else
+		strbuf_insert(sb, 0, "refs/notes/", 11);
+}
+
 static int list_each_note(const unsigned char *object_sha1,
 		const unsigned char *note_sha1, char *note_path,
 		void *cb_data)
@@ -839,13 +849,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
 
 	if (override_notes_ref) {
 		struct strbuf sb = STRBUF_INIT;
-		if (!prefixcmp(override_notes_ref, "refs/notes/"))
-			/* we're happy */;
-		else if (!prefixcmp(override_notes_ref, "notes/"))
-			strbuf_addstr(&sb, "refs/");
-		else
-			strbuf_addstr(&sb, "refs/notes/");
 		strbuf_addstr(&sb, override_notes_ref);
+		expand_notes_ref(&sb);
 		setenv("GIT_NOTES_REF", sb.buf, 1);
 		strbuf_release(&sb);
 	}
-- 
1.7.3.98.g5ad7d9

--
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 00/18] git notes merge, Johan Herland, (Tue Sep 28, 5:23 pm)
[PATCH 07/18] builtin/notes.c: Split notes ref DWIMmery in ..., Johan Herland, (Tue Sep 28, 5:23 pm)
Re: [PATCH 00/18] git notes merge, Sverre Rabbelier, (Wed Sep 29, 7:56 am)
Re: [PATCH 00/18] git notes merge, Johan Herland, (Wed Sep 29, 8:16 am)
Re: [PATCH 00/18] git notes merge, Sverre Rabbelier, (Wed Sep 29, 8:20 am)
Re: [PATCH 00/18] git notes merge, Johan Herland, (Wed Sep 29, 9:04 am)
Re: [PATCH 14/18] git notes merge: Manual conflict resolut ..., Ævar Arnfjörð Bjarmason, (Wed Sep 29, 9:19 am)
Re: [PATCH 10/18] git notes merge: Handle real, non-confli ..., Ævar Arnfjörð Bjarmason, (Wed Sep 29, 9:20 am)