Merge branch 'sd/log-decorate'

* sd/log-decorate:
  log.decorate: only ignore it under "log --pretty=raw"
  script with rev-list instead of log
  log --pretty/--oneline: ignore log.decorate
  log.decorate: usability fixes
  Add `log.decorate' configuration variable.
  git_config_maybe_bool()

Conflicts:
	builtin/log.c
This commit is contained in:
Junio C Hamano 2010-05-08 22:36:14 -07:00
commit 72d9b222a9
8 changed files with 118 additions and 13 deletions

View File

@ -1270,6 +1270,13 @@ log.date::
following alternatives: {relative,local,default,iso,rfc,short}.
See linkgit:git-log[1].
log.decorate::
Print out the ref names of any commits that are shown by the log
command. If 'short' is specified, the ref name prefixes 'refs/heads/',
'refs/tags/' and 'refs/remotes/' will not be printed. If 'full' is
specified, the full ref name (including prefix) will be printed.
This is the same as the log commands '--decorate' option.
log.showroot::
If true, the initial commit will be shown as a big creation event.
This is equivalent to a diff against an empty tree.

View File

@ -37,7 +37,8 @@ include::diff-options.txt[]
and <until>, see "SPECIFYING REVISIONS" section in
linkgit:git-rev-parse[1].
--decorate[=short|full]::
--no-decorate::
--decorate[=short|full|no]::
Print out the ref names of any commits that are shown. If 'short' is
specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
'refs/remotes/' will not be printed. If 'full' is specified, the

View File

@ -24,6 +24,7 @@
static const char *default_date_mode = NULL;
static int default_show_root = 1;
static int decoration_style;
static const char *fmt_patch_subject_prefix = "PATCH";
static const char *fmt_pretty;
@ -31,11 +32,28 @@ static const char * const builtin_log_usage =
"git log [<options>] [<since>..<until>] [[--] <path>...]\n"
" or: git show [options] <object>...";
static int parse_decoration_style(const char *var, const char *value)
{
switch (git_config_maybe_bool(var, value)) {
case 1:
return DECORATE_SHORT_REFS;
case 0:
return 0;
default:
break;
}
if (!strcmp(value, "full"))
return DECORATE_FULL_REFS;
else if (!strcmp(value, "short"))
return DECORATE_SHORT_REFS;
return -1;
}
static void cmd_log_init(int argc, const char **argv, const char *prefix,
struct rev_info *rev, struct setup_revision_opt *opt)
{
int i;
int decoration_style = 0;
int decoration_given = 0;
struct userformat_want w;
rev->abbrev = DEFAULT_ABBREV;
@ -78,14 +96,15 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
const char *arg = argv[i];
if (!strcmp(arg, "--decorate")) {
decoration_style = DECORATE_SHORT_REFS;
decoration_given = 1;
} else if (!prefixcmp(arg, "--decorate=")) {
const char *v = skip_prefix(arg, "--decorate=");
if (!strcmp(v, "full"))
decoration_style = DECORATE_FULL_REFS;
else if (!strcmp(v, "short"))
decoration_style = DECORATE_SHORT_REFS;
else
decoration_style = parse_decoration_style(arg, v);
if (decoration_style < 0)
die("invalid --decorate option: %s", arg);
decoration_given = 1;
} else if (!strcmp(arg, "--no-decorate")) {
decoration_style = 0;
} else if (!strcmp(arg, "--source")) {
rev->show_source = 1;
} else if (!strcmp(arg, "-h")) {
@ -93,6 +112,15 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
} else
die("unrecognized argument: %s", arg);
}
/*
* defeat log.decorate configuration interacting with --pretty=raw
* from the command line.
*/
if (!decoration_given && rev->pretty_given
&& rev->commit_format == CMIT_FMT_RAW)
decoration_style = 0;
if (decoration_style) {
rev->show_decorations = 1;
load_ref_decorations(decoration_style);
@ -258,6 +286,12 @@ static int git_log_config(const char *var, const char *value, void *cb)
return git_config_string(&fmt_patch_subject_prefix, var, value);
if (!strcmp(var, "log.date"))
return git_config_string(&default_date_mode, var, value);
if (!strcmp(var, "log.decorate")) {
decoration_style = parse_decoration_style(var, value);
if (decoration_style < 0)
decoration_style = 0; /* maybe warn? */
return 0;
}
if (!strcmp(var, "log.showroot")) {
default_show_root = git_config_bool(var, value);
return 0;

View File

@ -944,6 +944,7 @@ extern int git_config_int(const char *, const char *);
extern unsigned long git_config_ulong(const char *, const char *);
extern int git_config_bool_or_int(const char *, const char *, int *);
extern int git_config_bool(const char *, const char *);
extern int git_config_maybe_bool(const char *, const char *);
extern int git_config_string(const char **, const char *, const char *);
extern int git_config_pathname(const char **, const char *, const char *);
extern int git_config_set(const char *, const char *);

View File

@ -322,17 +322,30 @@ unsigned long git_config_ulong(const char *name, const char *value)
return ret;
}
int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
int git_config_maybe_bool(const char *name, const char *value)
{
*is_bool = 1;
if (!value)
return 1;
if (!*value)
return 0;
if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
if (!strcasecmp(value, "true")
|| !strcasecmp(value, "yes")
|| !strcasecmp(value, "on"))
return 1;
if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
if (!strcasecmp(value, "false")
|| !strcasecmp(value, "no")
|| !strcasecmp(value, "off"))
return 0;
return -1;
}
int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
{
int v = git_config_maybe_bool(name, value);
if (0 <= v) {
*is_bool = 1;
return v;
}
*is_bool = 0;
return git_config_int(name, value);
}

View File

@ -57,7 +57,7 @@ create_stash () {
# state of the base commit
if b_commit=$(git rev-parse --verify HEAD)
then
head=$(git log --no-color --abbrev-commit --pretty=oneline -n 1 HEAD --)
head=$(git rev-list --oneline -n 1 HEAD --)
else
die "You do not have the initial commit yet"
fi

View File

@ -650,7 +650,7 @@ cmd_summary() {
range=$sha1_dst
fi
GIT_DIR="$name/.git" \
git log --pretty=oneline --first-parent $range | wc -l
git rev-list --first-parent $range -- | wc -l
)
total_commits=" ($(($total_commits + 0)))"
;;

View File

@ -387,5 +387,54 @@ test_expect_success 'log --graph with merge' '
test_cmp expect actual
'
test_expect_success 'log.decorate configuration' '
git config --unset-all log.decorate || :
git log --oneline >expect.none &&
git log --oneline --decorate >expect.short &&
git log --oneline --decorate=full >expect.full &&
echo "[log] decorate" >>.git/config &&
git log --oneline >actual &&
test_cmp expect.short actual &&
git config --unset-all log.decorate &&
git config log.decorate true &&
git log --oneline >actual &&
test_cmp expect.short actual &&
git log --oneline --decorate=full >actual &&
test_cmp expect.full actual &&
git log --oneline --decorate=no >actual &&
test_cmp expect.none actual &&
git config --unset-all log.decorate &&
git config log.decorate no &&
git log --oneline >actual &&
test_cmp expect.none actual &&
git log --oneline --decorate >actual &&
test_cmp expect.short actual &&
git log --oneline --decorate=full >actual &&
test_cmp expect.full actual &&
git config --unset-all log.decorate &&
git config log.decorate short &&
git log --oneline >actual &&
test_cmp expect.short actual &&
git log --oneline --no-decorate >actual &&
test_cmp expect.none actual &&
git log --oneline --decorate=full >actual &&
test_cmp expect.full actual &&
git config --unset-all log.decorate &&
git config log.decorate full &&
git log --oneline >actual &&
test_cmp expect.full actual &&
git log --oneline --no-decorate >actual &&
test_cmp expect.none actual &&
git log --oneline --decorate >actual &&
test_cmp expect.short actual
'
test_done