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>
This commit is contained in:
parent
d4990c4b2f
commit
8ef313e1ec
@ -83,6 +83,16 @@ struct msg_arg {
|
|||||||
struct strbuf buf;
|
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,
|
static int list_each_note(const unsigned char *object_sha1,
|
||||||
const unsigned char *note_sha1, char *note_path,
|
const unsigned char *note_sha1, char *note_path,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
@ -839,13 +849,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
if (override_notes_ref) {
|
if (override_notes_ref) {
|
||||||
struct strbuf sb = STRBUF_INIT;
|
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);
|
strbuf_addstr(&sb, override_notes_ref);
|
||||||
|
expand_notes_ref(&sb);
|
||||||
setenv("GIT_NOTES_REF", sb.buf, 1);
|
setenv("GIT_NOTES_REF", sb.buf, 1);
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user