builtin/notes.c: Split notes ref DWIMmery into a separate function
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Nov 9, 2010 at 22:49 UTC
8ef313e1ec3b9b8ca47dce1fec632597aa34bedc
1 file changed
+11
-6
builtin/notes.c
+11
-6
@@ -83,6 +83,16 @@ struct msg_arg {
83
struct strbuf buf;
84
};
85
86
+static void expand_notes_ref(struct strbuf *sb)
87
+{
88
+ if (!prefixcmp(sb->buf, "refs/notes/"))
89
+ return; /* we're happy */
90
+ else if (!prefixcmp(sb->buf, "notes/"))
91
+ strbuf_insert(sb, 0, "refs/", 5);
92
+ else
93
+ strbuf_insert(sb, 0, "refs/notes/", 11);
94
+}
95
+
96
static int list_each_note(const unsigned char *object_sha1,
97
const unsigned char *note_sha1, char *note_path,
98
void *cb_data)
@@ -839,13 +849,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
849
850
if (override_notes_ref) {
851
struct strbuf sb = STRBUF_INIT;
842
- if (!prefixcmp(override_notes_ref, "refs/notes/"))
843
- /* we're happy */;
844
- else if (!prefixcmp(override_notes_ref, "notes/"))
845
- strbuf_addstr(&sb, "refs/");
846
- else
847
- strbuf_addstr(&sb, "refs/notes/");
852
strbuf_addstr(&sb, override_notes_ref);
853
+ expand_notes_ref(&sb);
854
setenv("GIT_NOTES_REF", sb.buf, 1);
855
strbuf_release(&sb);
856
}