@matheusbsbs / matheus-bagliano / commits / dcf783a261
Fork 0

notes: add shorthand --ref to override GIT_NOTES_REF

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>

Thomas Rast committed Mar 12, 2010 at 18:04 UTC dcf783a26110ab99f2052e378ee76c3542a4b9e9
2 files changed +21
Documentation/git-notes.txt
+5
@@ -116,6 +116,11 @@ OPTIONS
116 Like '-C', but with '-c' the editor is invoked, so that
117 the user can further edit the note message.
118
119 +--ref <ref>::
120 + Manipulate the notes tree in <ref>. This overrides both
121 + GIT_NOTES_REF and the "core.notesRef" configuration. The ref
122 + is taken to be in `refs/notes/` if it is not qualified.
123 +
124 Author
125 ------
126 Written by Johannes Schindelin <johannes.schindelin@gmx.de> and
builtin-notes.c
+16
@@ -447,6 +447,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
447 int given_object = 0, i = 1, retval = 0;
448 struct msg_arg msg = { 0, 0, STRBUF_INIT };
449 const char *rewrite_cmd = NULL;
450 + const char *override_notes_ref = NULL;
451 struct option options[] = {
452 OPT_GROUP("Notes options"),
453 OPT_CALLBACK('m', "message", &msg, "MSG",
@@ -459,6 +460,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
460 "reuse specified note object", parse_reuse_arg),
461 OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
462 OPT_BOOLEAN(0, "stdin", &from_stdin, "read objects from stdin"),
463 + OPT_STRING(0, "ref", &override_notes_ref, "notes_ref",
464 + "use notes from <notes_ref>"),
465 OPT_STRING(0, "for-rewrite", &rewrite_cmd, "command",
466 "load rewriting config for <command> (implies --stdin)"),
467 OPT_END()
@@ -468,6 +471,19 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
471
472 argc = parse_options(argc, argv, prefix, options, git_notes_usage, 0);
473
474 + if (override_notes_ref) {
475 + struct strbuf sb = STRBUF_INIT;
476 + if (!prefixcmp(override_notes_ref, "refs/notes/"))
477 + /* we're happy */;
478 + else if (!prefixcmp(override_notes_ref, "notes/"))
479 + strbuf_addstr(&sb, "refs/");
480 + else
481 + strbuf_addstr(&sb, "refs/notes/");
482 + strbuf_addstr(&sb, override_notes_ref);
483 + setenv("GIT_NOTES_REF", sb.buf, 1);
484 + strbuf_release(&sb);
485 + }
486 +
487 if (argc && !strcmp(argv[0], "list"))
488 list = 1;
489 else if (argc && !strcmp(argv[0], "add"))