Skip to content

Commit

Permalink
notes: add shorthand --ref to override GIT_NOTES_REF
Browse files Browse the repository at this point in the history
Adds a shorthand option that overrides the GIT_NOTES_REF variable, and
hence determines the notes tree that will be manipulated.  It also
DWIMs a refs/notes/ prefix.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Acked-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Mar 13, 2010
1 parent 6360d34 commit dcf783a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Documentation/git-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ OPTIONS
Like '-C', but with '-c' the editor is invoked, so that
the user can further edit the note message.

--ref <ref>::
Manipulate the notes tree in <ref>. This overrides both
GIT_NOTES_REF and the "core.notesRef" configuration. The ref
is taken to be in `refs/notes/` if it is not qualified.

Author
------
Written by Johannes Schindelin <johannes.schindelin@gmx.de> and
Expand Down
16 changes: 16 additions & 0 deletions builtin-notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
int given_object = 0, i = 1, retval = 0;
struct msg_arg msg = { 0, 0, STRBUF_INIT };
const char *rewrite_cmd = NULL;
const char *override_notes_ref = NULL;
struct option options[] = {
OPT_GROUP("Notes options"),
OPT_CALLBACK('m', "message", &msg, "MSG",
Expand All @@ -459,6 +460,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
"reuse specified note object", parse_reuse_arg),
OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
OPT_BOOLEAN(0, "stdin", &from_stdin, "read objects from stdin"),
OPT_STRING(0, "ref", &override_notes_ref, "notes_ref",
"use notes from <notes_ref>"),
OPT_STRING(0, "for-rewrite", &rewrite_cmd, "command",
"load rewriting config for <command> (implies --stdin)"),
OPT_END()
Expand All @@ -468,6 +471,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix)

argc = parse_options(argc, argv, prefix, options, git_notes_usage, 0);

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);
setenv("GIT_NOTES_REF", sb.buf, 1);
strbuf_release(&sb);
}

if (argc && !strcmp(argv[0], "list"))
list = 1;
else if (argc && !strcmp(argv[0], "add"))
Expand Down

0 comments on commit dcf783a

Please sign in to comment.