Skip to content

Commit

Permalink
builtin/notes.c: Split notes ref DWIMmery into a separate function
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johan Herland authored and Junio C Hamano committed Nov 17, 2010
1 parent d4990c4 commit 8ef313e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8ef313e

Please sign in to comment.