Merge branch 'jk/notes-ui-updates'
* jk/notes-ui-updates: contrib/completion: --notes, --no-notes log/pretty-options: Document --[no-]notes and deprecate old notes options revision.c: make --no-notes reset --notes list revision.c: support --notes command-line option notes: refactor display notes default handling notes: refactor display notes extra refs field revision.c: refactor notes ref expansion notes: make expand_notes_ref globally accessible
This commit is contained in:
commit
23f536cf62
@ -178,9 +178,9 @@ May be an unabbreviated ref name or a glob and may be specified
|
|||||||
multiple times. A warning will be issued for refs that do not exist,
|
multiple times. A warning will be issued for refs that do not exist,
|
||||||
but a glob that does not match any refs is silently ignored.
|
but a glob that does not match any refs is silently ignored.
|
||||||
+
|
+
|
||||||
This setting can be disabled by the `--no-standard-notes` option,
|
This setting can be disabled by the `--no-notes` option,
|
||||||
overridden by the 'GIT_NOTES_DISPLAY_REF' environment variable,
|
overridden by the 'GIT_NOTES_DISPLAY_REF' environment variable,
|
||||||
and supplemented by the `--show-notes` option.
|
and overridden by the `--notes=<ref>` option.
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
---
|
---
|
||||||
|
@ -30,19 +30,34 @@ people using 80-column terminals.
|
|||||||
preferred by the user. For non plumbing commands this
|
preferred by the user. For non plumbing commands this
|
||||||
defaults to UTF-8.
|
defaults to UTF-8.
|
||||||
|
|
||||||
--no-notes::
|
--notes[=<ref>]::
|
||||||
--show-notes[=<ref>]::
|
|
||||||
Show the notes (see linkgit:git-notes[1]) that annotate the
|
Show the notes (see linkgit:git-notes[1]) that annotate the
|
||||||
commit, when showing the commit log message. This is the default
|
commit, when showing the commit log message. This is the default
|
||||||
for `git log`, `git show` and `git whatchanged` commands when
|
for `git log`, `git show` and `git whatchanged` commands when
|
||||||
there is no `--pretty`, `--format` nor `--oneline` option is
|
there is no `--pretty`, `--format` nor `--oneline` option given
|
||||||
given on the command line.
|
on the command line.
|
||||||
+
|
+
|
||||||
With an optional argument, add this ref to the list of notes. The ref
|
By default, the notes shown are from the notes refs listed in the
|
||||||
is taken to be in `refs/notes/` if it is not qualified.
|
'core.notesRef' and 'notes.displayRef' variables (or corresponding
|
||||||
|
environment overrides). See linkgit:git-config[1] for more details.
|
||||||
|
+
|
||||||
|
With an optional '<ref>' argument, show this notes ref instead of the
|
||||||
|
default notes ref(s). The ref is taken to be in `refs/notes/` if it
|
||||||
|
is not qualified.
|
||||||
|
+
|
||||||
|
Multiple --notes options can be combined to control which notes are
|
||||||
|
being displayed. Examples: "--notes=foo" will show only notes from
|
||||||
|
"refs/notes/foo"; "--notes=foo --notes" will show both notes from
|
||||||
|
"refs/notes/foo" and from the default notes ref(s).
|
||||||
|
|
||||||
|
--no-notes::
|
||||||
|
Do not show notes. This negates the above `--notes` option, by
|
||||||
|
resetting the list of notes refs from which notes are shown.
|
||||||
|
Options are parsed in the order given on the command line, so e.g.
|
||||||
|
"--notes --notes=foo --no-notes --notes=bar" will only show notes
|
||||||
|
from "refs/notes/bar".
|
||||||
|
|
||||||
|
--show-notes[=<ref>]::
|
||||||
--[no-]standard-notes::
|
--[no-]standard-notes::
|
||||||
Enable or disable populating the notes ref list from the
|
These options are deprecated. Use the above --notes/--no-notes
|
||||||
'core.notesRef' and 'notes.displayRef' variables (or
|
options instead.
|
||||||
corresponding environment overrides). Enabled by default.
|
|
||||||
See linkgit:git-config[1].
|
|
||||||
|
@ -100,16 +100,6 @@ 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)
|
||||||
|
@ -1584,7 +1584,7 @@ __git_log_common_options="
|
|||||||
__git_log_gitk_options="
|
__git_log_gitk_options="
|
||||||
--dense --sparse --full-history
|
--dense --sparse --full-history
|
||||||
--simplify-merges --simplify-by-decoration
|
--simplify-merges --simplify-by-decoration
|
||||||
--left-right
|
--left-right --notes --no-notes
|
||||||
"
|
"
|
||||||
# Options that go well for log and shortlog (not gitk)
|
# Options that go well for log and shortlog (not gitk)
|
||||||
__git_log_shortlog_options="
|
__git_log_shortlog_options="
|
||||||
|
17
notes.c
17
notes.c
@ -1053,7 +1053,8 @@ void init_display_notes(struct display_notes_opt *opt)
|
|||||||
|
|
||||||
assert(!display_notes_trees);
|
assert(!display_notes_trees);
|
||||||
|
|
||||||
if (!opt || !opt->suppress_default_notes) {
|
if (!opt || opt->use_default_notes > 0 ||
|
||||||
|
(opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {
|
||||||
string_list_append(&display_notes_refs, default_notes_ref());
|
string_list_append(&display_notes_refs, default_notes_ref());
|
||||||
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
|
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
|
||||||
if (display_ref_env) {
|
if (display_ref_env) {
|
||||||
@ -1066,9 +1067,9 @@ void init_display_notes(struct display_notes_opt *opt)
|
|||||||
|
|
||||||
git_config(notes_display_config, &load_config_refs);
|
git_config(notes_display_config, &load_config_refs);
|
||||||
|
|
||||||
if (opt && opt->extra_notes_refs) {
|
if (opt) {
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
for_each_string_list_item(item, opt->extra_notes_refs)
|
for_each_string_list_item(item, &opt->extra_notes_refs)
|
||||||
string_list_add_refs_by_glob(&display_notes_refs,
|
string_list_add_refs_by_glob(&display_notes_refs,
|
||||||
item->string);
|
item->string);
|
||||||
}
|
}
|
||||||
@ -1285,3 +1286,13 @@ int copy_note(struct notes_tree *t,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
9
notes.h
9
notes.h
@ -1,6 +1,8 @@
|
|||||||
#ifndef NOTES_H
|
#ifndef NOTES_H
|
||||||
#define NOTES_H
|
#define NOTES_H
|
||||||
|
|
||||||
|
#include "string-list.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function type for combining two notes annotating the same object.
|
* Function type for combining two notes annotating the same object.
|
||||||
*
|
*
|
||||||
@ -256,8 +258,8 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,
|
|||||||
struct string_list;
|
struct string_list;
|
||||||
|
|
||||||
struct display_notes_opt {
|
struct display_notes_opt {
|
||||||
unsigned int suppress_default_notes:1;
|
int use_default_notes;
|
||||||
struct string_list *extra_notes_refs;
|
struct string_list extra_notes_refs;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -307,4 +309,7 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob);
|
|||||||
void string_list_add_refs_from_colon_sep(struct string_list *list,
|
void string_list_add_refs_from_colon_sep(struct string_list *list,
|
||||||
const char *globs);
|
const char *globs);
|
||||||
|
|
||||||
|
/* Expand inplace a note ref like "foo" or "notes/foo" into "refs/notes/foo" */
|
||||||
|
void expand_notes_ref(struct strbuf *sb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
35
revision.c
35
revision.c
@ -955,6 +955,8 @@ void init_revisions(struct rev_info *revs, const char *prefix)
|
|||||||
revs->diffopt.prefix = prefix;
|
revs->diffopt.prefix = prefix;
|
||||||
revs->diffopt.prefix_length = strlen(prefix);
|
revs->diffopt.prefix_length = strlen(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
revs->notes_opt.use_default_notes = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_pending_commit_list(struct rev_info *revs,
|
static void add_pending_commit_list(struct rev_info *revs,
|
||||||
@ -1365,32 +1367,39 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
|
|||||||
revs->verbose_header = 1;
|
revs->verbose_header = 1;
|
||||||
revs->pretty_given = 1;
|
revs->pretty_given = 1;
|
||||||
get_commit_format(arg+9, revs);
|
get_commit_format(arg+9, revs);
|
||||||
} else if (!strcmp(arg, "--show-notes")) {
|
} else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) {
|
||||||
revs->show_notes = 1;
|
revs->show_notes = 1;
|
||||||
revs->show_notes_given = 1;
|
revs->show_notes_given = 1;
|
||||||
} else if (!prefixcmp(arg, "--show-notes=")) {
|
revs->notes_opt.use_default_notes = 1;
|
||||||
|
} else if (!prefixcmp(arg, "--show-notes=") ||
|
||||||
|
!prefixcmp(arg, "--notes=")) {
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
revs->show_notes = 1;
|
revs->show_notes = 1;
|
||||||
revs->show_notes_given = 1;
|
revs->show_notes_given = 1;
|
||||||
if (!revs->notes_opt.extra_notes_refs)
|
if (!prefixcmp(arg, "--show-notes")) {
|
||||||
revs->notes_opt.extra_notes_refs = xcalloc(1, sizeof(struct string_list));
|
if (revs->notes_opt.use_default_notes < 0)
|
||||||
if (!prefixcmp(arg+13, "refs/"))
|
revs->notes_opt.use_default_notes = 1;
|
||||||
/* happy */;
|
|
||||||
else if (!prefixcmp(arg+13, "notes/"))
|
|
||||||
strbuf_addstr(&buf, "refs/");
|
|
||||||
else
|
|
||||||
strbuf_addstr(&buf, "refs/notes/");
|
|
||||||
strbuf_addstr(&buf, arg+13);
|
strbuf_addstr(&buf, arg+13);
|
||||||
string_list_append(revs->notes_opt.extra_notes_refs,
|
}
|
||||||
|
else
|
||||||
|
strbuf_addstr(&buf, arg+8);
|
||||||
|
expand_notes_ref(&buf);
|
||||||
|
string_list_append(&revs->notes_opt.extra_notes_refs,
|
||||||
strbuf_detach(&buf, NULL));
|
strbuf_detach(&buf, NULL));
|
||||||
} else if (!strcmp(arg, "--no-notes")) {
|
} else if (!strcmp(arg, "--no-notes")) {
|
||||||
revs->show_notes = 0;
|
revs->show_notes = 0;
|
||||||
revs->show_notes_given = 1;
|
revs->show_notes_given = 1;
|
||||||
|
revs->notes_opt.use_default_notes = -1;
|
||||||
|
/* we have been strdup'ing ourselves, so trick
|
||||||
|
* string_list into free()ing strings */
|
||||||
|
revs->notes_opt.extra_notes_refs.strdup_strings = 1;
|
||||||
|
string_list_clear(&revs->notes_opt.extra_notes_refs, 0);
|
||||||
|
revs->notes_opt.extra_notes_refs.strdup_strings = 0;
|
||||||
} else if (!strcmp(arg, "--standard-notes")) {
|
} else if (!strcmp(arg, "--standard-notes")) {
|
||||||
revs->show_notes_given = 1;
|
revs->show_notes_given = 1;
|
||||||
revs->notes_opt.suppress_default_notes = 0;
|
revs->notes_opt.use_default_notes = 1;
|
||||||
} else if (!strcmp(arg, "--no-standard-notes")) {
|
} else if (!strcmp(arg, "--no-standard-notes")) {
|
||||||
revs->notes_opt.suppress_default_notes = 1;
|
revs->notes_opt.use_default_notes = 0;
|
||||||
} else if (!strcmp(arg, "--oneline")) {
|
} else if (!strcmp(arg, "--oneline")) {
|
||||||
revs->verbose_header = 1;
|
revs->verbose_header = 1;
|
||||||
get_commit_format("oneline", revs);
|
get_commit_format("oneline", revs);
|
||||||
|
@ -272,6 +272,44 @@ do
|
|||||||
'
|
'
|
||||||
done
|
done
|
||||||
|
|
||||||
|
test_expect_success 'setup alternate notes ref' '
|
||||||
|
git notes --ref=alternate add -m alternate
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git log --notes shows default notes' '
|
||||||
|
git log -1 --notes >output &&
|
||||||
|
grep xyzzy output &&
|
||||||
|
! grep alternate output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git log --notes=X shows only X' '
|
||||||
|
git log -1 --notes=alternate >output &&
|
||||||
|
! grep xyzzy output &&
|
||||||
|
grep alternate output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git log --notes --notes=X shows both' '
|
||||||
|
git log -1 --notes --notes=alternate >output &&
|
||||||
|
grep xyzzy output &&
|
||||||
|
grep alternate output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git log --no-notes resets default state' '
|
||||||
|
git log -1 --notes --notes=alternate \
|
||||||
|
--no-notes --notes=alternate \
|
||||||
|
>output &&
|
||||||
|
! grep xyzzy output &&
|
||||||
|
grep alternate output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git log --no-notes resets ref list' '
|
||||||
|
git log -1 --notes --notes=alternate \
|
||||||
|
--no-notes --notes \
|
||||||
|
>output &&
|
||||||
|
grep xyzzy output &&
|
||||||
|
! grep alternate output
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'create -m notes (setup)' '
|
test_expect_success 'create -m notes (setup)' '
|
||||||
: > a5 &&
|
: > a5 &&
|
||||||
git add a5 &&
|
git add a5 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user