@matheusbsbs / matheus-bagliano / commits / 8a3d203bd0
Fork 0

log.decorate: usability fixes

The configuration is meant to suppliment --decorate command line option that can be used as a boolean to turn the feature on, so it is natural to expect [log] decorate decorate = yes to work. The original commit would segfault with the first one, and would not understand the second one. Once a user has this configuration in ~/.gitconfig, there needs to be a way to override it from the command line. Add --no-decorate option to log family and also allow --decorate=no to mean the same thing. Since we allow setting log.decorate to 'true', the command line also should accept --decorate=yes and behave accordingly. New tests in t4202 are designed to exercise the interaction between the configuration variable and the command line option that overrides it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 17, 2010 at 10:20 UTC 8a3d203bd02bec48a02557961899d81da172fa23
3 files changed +76 -11
Documentation/git-log.txt
+2 -1
@@ -37,7 +37,8 @@ include::diff-options.txt[]
37 and <until>, see "SPECIFYING REVISIONS" section in
38 linkgit:git-rev-parse[1].
39
40 ---decorate[=short|full]::
40 +--no-decorate::
41 +--decorate[=short|full|no]::
42 Print out the ref names of any commits that are shown. If 'short' is
43 specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
44 'refs/remotes/' will not be printed. If 'full' is specified, the
builtin-log.c
+25 -10
@@ -24,7 +24,7 @@
24 static const char *default_date_mode = NULL;
25
26 static int default_show_root = 1;
27 -static int decoration_style = 0;
27 +static int decoration_style;
28 static const char *fmt_patch_subject_prefix = "PATCH";
29 static const char *fmt_pretty;
30
@@ -32,6 +32,23 @@ static const char * const builtin_log_usage =
32 "git log [<options>] [<since>..<until>] [[--] <path>...]\n"
33 " or: git show [options] <object>...";
34
35 +static int parse_decoration_style(const char *var, const char *value)
36 +{
37 + switch (git_config_maybe_bool(var, value)) {
38 + case 1:
39 + return DECORATE_SHORT_REFS;
40 + case 0:
41 + return 0;
42 + default:
43 + break;
44 + }
45 + if (!strcmp(value, "full"))
46 + return DECORATE_FULL_REFS;
47 + else if (!strcmp(value, "short"))
48 + return DECORATE_SHORT_REFS;
49 + return -1;
50 +}
51 +
52 static void cmd_log_init(int argc, const char **argv, const char *prefix,
53 struct rev_info *rev)
54 {
@@ -74,12 +91,11 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
91 decoration_style = DECORATE_SHORT_REFS;
92 } else if (!prefixcmp(arg, "--decorate=")) {
93 const char *v = skip_prefix(arg, "--decorate=");
77 - if (!strcmp(v, "full"))
78 - decoration_style = DECORATE_FULL_REFS;
79 - else if (!strcmp(v, "short"))
80 - decoration_style = DECORATE_SHORT_REFS;
81 - else
94 + decoration_style = parse_decoration_style(arg, v);
95 + if (decoration_style < 0)
96 die("invalid --decorate option: %s", arg);
97 + } else if (!strcmp(arg, "--no-decorate")) {
98 + decoration_style = 0;
99 } else if (!strcmp(arg, "--source")) {
100 rev->show_source = 1;
101 } else if (!strcmp(arg, "-h")) {
@@ -253,10 +269,9 @@ static int git_log_config(const char *var, const char *value, void *cb)
269 if (!strcmp(var, "log.date"))
270 return git_config_string(&default_date_mode, var, value);
271 if (!strcmp(var, "log.decorate")) {
256 - if (!strcmp(value, "full"))
257 - decoration_style = DECORATE_FULL_REFS;
258 - else if (!strcmp(value, "short"))
259 - decoration_style = DECORATE_SHORT_REFS;
272 + decoration_style = parse_decoration_style(var, value);
273 + if (decoration_style < 0)
274 + decoration_style = 0; /* maybe warn? */
275 return 0;
276 }
277 if (!strcmp(var, "log.showroot")) {
t/t4202-log.sh
+49
@@ -387,5 +387,54 @@ test_expect_success 'log --graph with merge' '
387 test_cmp expect actual
388 '
389
390 +test_expect_success 'log.decorate configuration' '
391 + git config --unset-all log.decorate || :
392 +
393 + git log --oneline >expect.none &&
394 + git log --oneline --decorate >expect.short &&
395 + git log --oneline --decorate=full >expect.full &&
396 +
397 + echo "[log] decorate" >>.git/config &&
398 + git log --oneline >actual &&
399 + test_cmp expect.short actual &&
400 +
401 + git config --unset-all log.decorate &&
402 + git config log.decorate true &&
403 + git log --oneline >actual &&
404 + test_cmp expect.short actual &&
405 + git log --oneline --decorate=full >actual &&
406 + test_cmp expect.full actual &&
407 + git log --oneline --decorate=no >actual &&
408 + test_cmp expect.none actual &&
409 +
410 + git config --unset-all log.decorate &&
411 + git config log.decorate no &&
412 + git log --oneline >actual &&
413 + test_cmp expect.none actual &&
414 + git log --oneline --decorate >actual &&
415 + test_cmp expect.short actual &&
416 + git log --oneline --decorate=full >actual &&
417 + test_cmp expect.full actual &&
418 +
419 + git config --unset-all log.decorate &&
420 + git config log.decorate short &&
421 + git log --oneline >actual &&
422 + test_cmp expect.short actual &&
423 + git log --oneline --no-decorate >actual &&
424 + test_cmp expect.none actual &&
425 + git log --oneline --decorate=full >actual &&
426 + test_cmp expect.full actual &&
427 +
428 + git config --unset-all log.decorate &&
429 + git config log.decorate full &&
430 + git log --oneline >actual &&
431 + test_cmp expect.full actual &&
432 + git log --oneline --no-decorate >actual &&
433 + test_cmp expect.none actual &&
434 + git log --oneline --decorate >actual &&
435 + test_cmp expect.short actual
436 +
437 +'
438 +
439 test_done
440