Skip to content

Commit c068a3b

Browse files
committed
Merge branch 'ds/decorate-filter-tweak'
The namespaces used by "log --decorate" from "refs/" hierarchy by default has been tightened. * ds/decorate-filter-tweak: fetch: use ref_namespaces during prefetch maintenance: stop writing log.excludeDecoration log: create log.initialDecorationSet=all log: add --clear-decorations option log: add default decoration filter log-tree: use ref_namespaces instead of if/else-if refs: use ref_namespaces for replace refs base refs: add array of ref namespaces t4207: test coloring of grafted decorations t4207: modernize test refs: allow "HEAD" as decoration filter
2 parents 07ee72d + 992f25d commit c068a3b

22 files changed

+701
-85
lines changed

Documentation/config/log.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ log.decorate::
1818
names are shown. This is the same as the `--decorate` option
1919
of the `git log`.
2020

21+
log.initialDecorationSet::
22+
By default, `git log` only shows decorations for certain known ref
23+
namespaces. If 'all' is specified, then show all refs as
24+
decorations.
25+
2126
log.excludeDecoration::
2227
Exclude the specified patterns from the log decorations. This is
2328
similar to the `--decorate-refs-exclude` command-line option, but

Documentation/git-log.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@ OPTIONS
4545

4646
--decorate-refs=<pattern>::
4747
--decorate-refs-exclude=<pattern>::
48-
If no `--decorate-refs` is given, pretend as if all refs were
49-
included. For each candidate, do not use it for decoration if it
48+
For each candidate reference, do not use it for decoration if it
5049
matches any patterns given to `--decorate-refs-exclude` or if it
5150
doesn't match any of the patterns given to `--decorate-refs`. The
5251
`log.excludeDecoration` config option allows excluding refs from
5352
the decorations, but an explicit `--decorate-refs` pattern will
5453
override a match in `log.excludeDecoration`.
54+
+
55+
If none of these options or config settings are given, then references are
56+
used as decoration if they match `HEAD`, `refs/heads/`, `refs/remotes/`,
57+
`refs/stash/`, or `refs/tags/`.
58+
59+
--clear-decorations::
60+
When specified, this option clears all previous `--decorate-refs`
61+
or `--decorate-refs-exclude` options and relaxes the default
62+
decoration filter to include all references. This option is
63+
assumed if the config value `log.initialDecorationSet` is set to
64+
`all`.
5565

5666
--source::
5767
Print out the ref name given on the command line by which each

builtin/fetch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ static void filter_prefetch_refspec(struct refspec *rs)
490490
continue;
491491
if (!rs->items[i].dst ||
492492
(rs->items[i].src &&
493-
!strncmp(rs->items[i].src, "refs/tags/", 10))) {
493+
!strncmp(rs->items[i].src,
494+
ref_namespace[NAMESPACE_TAGS].ref,
495+
strlen(ref_namespace[NAMESPACE_TAGS].ref)))) {
494496
int j;
495497

496498
free(rs->items[i].src);
@@ -506,7 +508,7 @@ static void filter_prefetch_refspec(struct refspec *rs)
506508
}
507509

508510
old_dst = rs->items[i].dst;
509-
strbuf_addstr(&new_dst, "refs/prefetch/");
511+
strbuf_addstr(&new_dst, ref_namespace[NAMESPACE_PREFETCH].ref);
510512

511513
/*
512514
* If old_dst starts with "refs/", then place

builtin/gc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,6 @@ static int fetch_remote(struct remote *remote, void *cbdata)
910910

911911
static int maintenance_task_prefetch(struct maintenance_run_opts *opts)
912912
{
913-
git_config_set_multivar_gently("log.excludedecoration",
914-
"refs/prefetch/",
915-
"refs/prefetch/",
916-
CONFIG_FLAGS_FIXED_VALUE |
917-
CONFIG_FLAGS_MULTI_REPLACE);
918-
919913
if (for_each_remote(fetch_remote, opts)) {
920914
error(_("failed to prefetch remotes"));
921915
return 1;

builtin/log.c

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ static int parse_decoration_style(const char *value)
101101
return -1;
102102
}
103103

104+
static int use_default_decoration_filter = 1;
105+
static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
106+
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
107+
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
108+
109+
static int clear_decorations_callback(const struct option *opt,
110+
const char *arg, int unset)
111+
{
112+
string_list_clear(&decorate_refs_include, 0);
113+
string_list_clear(&decorate_refs_exclude, 0);
114+
use_default_decoration_filter = 0;
115+
return 0;
116+
}
117+
104118
static int decorate_callback(const struct option *opt, const char *arg, int unset)
105119
{
106120
if (unset)
@@ -162,25 +176,72 @@ static void cmd_log_init_defaults(struct rev_info *rev)
162176
parse_date_format(default_date_mode, &rev->date_mode);
163177
}
164178

179+
static void set_default_decoration_filter(struct decoration_filter *decoration_filter)
180+
{
181+
int i;
182+
char *value = NULL;
183+
struct string_list *include = decoration_filter->include_ref_pattern;
184+
const struct string_list *config_exclude =
185+
git_config_get_value_multi("log.excludeDecoration");
186+
187+
if (config_exclude) {
188+
struct string_list_item *item;
189+
for_each_string_list_item(item, config_exclude)
190+
string_list_append(decoration_filter->exclude_ref_config_pattern,
191+
item->string);
192+
}
193+
194+
/*
195+
* By default, decorate_all is disabled. Enable it if
196+
* log.initialDecorationSet=all. Don't ever disable it by config,
197+
* since the command-line takes precedent.
198+
*/
199+
if (use_default_decoration_filter &&
200+
!git_config_get_string("log.initialdecorationset", &value) &&
201+
!strcmp("all", value))
202+
use_default_decoration_filter = 0;
203+
free(value);
204+
205+
if (!use_default_decoration_filter ||
206+
decoration_filter->exclude_ref_pattern->nr ||
207+
decoration_filter->include_ref_pattern->nr ||
208+
decoration_filter->exclude_ref_config_pattern->nr)
209+
return;
210+
211+
/*
212+
* No command-line or config options were given, so
213+
* populate with sensible defaults.
214+
*/
215+
for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
216+
if (!ref_namespace[i].decoration)
217+
continue;
218+
219+
string_list_append(include, ref_namespace[i].ref);
220+
}
221+
}
222+
165223
static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
166224
struct rev_info *rev, struct setup_revision_opt *opt)
167225
{
168226
struct userformat_want w;
169227
int quiet = 0, source = 0, mailmap;
170228
static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP};
171-
static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
172-
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
173-
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
174-
struct decoration_filter decoration_filter = {&decorate_refs_include,
175-
&decorate_refs_exclude,
176-
&decorate_refs_exclude_config};
229+
struct decoration_filter decoration_filter = {
230+
.exclude_ref_pattern = &decorate_refs_exclude,
231+
.include_ref_pattern = &decorate_refs_include,
232+
.exclude_ref_config_pattern = &decorate_refs_exclude_config,
233+
};
177234
static struct revision_sources revision_sources;
178235

179236
const struct option builtin_log_options[] = {
180237
OPT__QUIET(&quiet, N_("suppress diff output")),
181238
OPT_BOOL(0, "source", &source, N_("show source")),
182239
OPT_BOOL(0, "use-mailmap", &mailmap, N_("use mail map file")),
183240
OPT_ALIAS(0, "mailmap", "use-mailmap"),
241+
OPT_CALLBACK_F(0, "clear-decorations", NULL, NULL,
242+
N_("clear all previously-defined decoration filters"),
243+
PARSE_OPT_NOARG | PARSE_OPT_NONEG,
244+
clear_decorations_callback),
184245
OPT_STRING_LIST(0, "decorate-refs", &decorate_refs_include,
185246
N_("pattern"), N_("only decorate refs that match <pattern>")),
186247
OPT_STRING_LIST(0, "decorate-refs-exclude", &decorate_refs_exclude,
@@ -265,16 +326,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
265326
}
266327

267328
if (decoration_style || rev->simplify_by_decoration) {
268-
const struct string_list *config_exclude =
269-
repo_config_get_value_multi(the_repository,
270-
"log.excludeDecoration");
271-
272-
if (config_exclude) {
273-
struct string_list_item *item;
274-
for_each_string_list_item(item, config_exclude)
275-
string_list_append(&decorate_refs_exclude_config,
276-
item->string);
277-
}
329+
set_default_decoration_filter(&decoration_filter);
278330

279331
if (decoration_style)
280332
rev->show_decorations = 1;

builtin/replace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
106106
size_t base_len;
107107
int had_error = 0;
108108
struct object_id oid;
109+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
109110

110111
strbuf_addstr(&ref, git_replace_ref_base);
111112
base_len = ref.len;
@@ -147,6 +148,8 @@ static int check_ref_valid(struct object_id *object,
147148
struct strbuf *ref,
148149
int force)
149150
{
151+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
152+
150153
strbuf_reset(ref);
151154
strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object));
152155
if (check_refname_format(ref->buf, 0))

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ void reset_shared_repository(void);
10161016
* commands that do not want replace references to be active.
10171017
*/
10181018
extern int read_replace_refs;
1019-
extern char *git_replace_ref_base;
10201019

10211020
/*
10221021
* These values are used to help identify parts of a repository to fsync.

environment.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const char *askpass_program;
5656
const char *excludes_file;
5757
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
5858
int read_replace_refs = 1;
59-
char *git_replace_ref_base;
6059
enum eol core_eol = EOL_UNSET;
6160
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
6261
char *check_roundtrip_encoding = "SHIFT-JIS";
@@ -162,6 +161,7 @@ const char *getenv_safe(struct strvec *argv, const char *name)
162161

163162
void setup_git_env(const char *git_dir)
164163
{
164+
char *git_replace_ref_base;
165165
const char *shallow_file;
166166
const char *replace_ref_base;
167167
struct set_gitdir_args args = { NULL };
@@ -182,9 +182,10 @@ void setup_git_env(const char *git_dir)
182182
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
183183
read_replace_refs = 0;
184184
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
185-
free(git_replace_ref_base);
186185
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
187186
: "refs/replace/");
187+
update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base);
188+
188189
free(git_namespace);
189190
git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
190191
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);

log-tree.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ static int ref_filter_match(const char *refname,
137137
static int add_ref_decoration(const char *refname, const struct object_id *oid,
138138
int flags, void *cb_data)
139139
{
140+
int i;
140141
struct object *obj;
141142
enum object_type objtype;
142143
enum decoration_type deco_type = DECORATION_NONE;
143144
struct decoration_filter *filter = (struct decoration_filter *)cb_data;
145+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
144146

145147
if (filter && !ref_filter_match(refname, filter))
146148
return 0;
@@ -165,16 +167,21 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
165167
return 0;
166168
obj = lookup_object_by_type(the_repository, oid, objtype);
167169

168-
if (starts_with(refname, "refs/heads/"))
169-
deco_type = DECORATION_REF_LOCAL;
170-
else if (starts_with(refname, "refs/remotes/"))
171-
deco_type = DECORATION_REF_REMOTE;
172-
else if (starts_with(refname, "refs/tags/"))
173-
deco_type = DECORATION_REF_TAG;
174-
else if (!strcmp(refname, "refs/stash"))
175-
deco_type = DECORATION_REF_STASH;
176-
else if (!strcmp(refname, "HEAD"))
177-
deco_type = DECORATION_REF_HEAD;
170+
for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
171+
struct ref_namespace_info *info = &ref_namespace[i];
172+
173+
if (!info->decoration)
174+
continue;
175+
if (info->exact) {
176+
if (!strcmp(refname, info->ref)) {
177+
deco_type = info->decoration;
178+
break;
179+
}
180+
} else if (starts_with(refname, info->ref)) {
181+
deco_type = info->decoration;
182+
break;
183+
}
184+
}
178185

179186
add_name_decoration(deco_type, refname, obj);
180187
while (obj->type == OBJ_TAG) {

notes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
10051005

10061006
if (!notes_ref)
10071007
notes_ref = default_notes_ref();
1008+
update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
10081009

10091010
if (!combine_notes)
10101011
combine_notes = combine_notes_concatenate;

0 commit comments

Comments
 (0)