aboutsummaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2010-11-09 22:49:45 +0100
committerJunio C Hamano <gitster@pobox.com>2010-11-17 13:21:30 -0800
commit8ef313e1ec3b9b8ca47dce1fec632597aa34bedc (patch)
tree92be1e3c711e174cc17cf2c21942c2958f5658b1 /builtin/notes.c
parentd4990c4b2f5f7066853fea4df775b3f506c79431 (diff)
downloadgit-8ef313e1ec3b9b8ca47dce1fec632597aa34bedc.tar.gz
git-8ef313e1ec3b9b8ca47dce1fec632597aa34bedc.tar.xz
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>
Diffstat (limited to 'builtin/notes.c')
-rw-r--r--builtin/notes.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index 51a11ba38..f35cf9bd4 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);
}