mirror of
https://github.com/git/git
synced 2024-09-13 21:34:42 +00:00
Merge branch 'ns/pretty-format'
* ns/pretty-format: bash completion: add --format= and --oneline options for "git log" Add tests for git log --pretty, --format and --oneline. Add --oneline that is a synonym to "--pretty=oneline --abbrev-commit" Give short-hands to --pretty=tformat:%formatstring Add --format that is a synonym to --pretty
This commit is contained in:
commit
458eaf5bf8
|
@ -152,3 +152,12 @@ $ git log -2 --pretty=tformat:%h 4da45bef \
|
||||||
4da45be
|
4da45be
|
||||||
7134973
|
7134973
|
||||||
---------------------
|
---------------------
|
||||||
|
+
|
||||||
|
In addition, any unrecognized string that has a `%` in it is interpreted
|
||||||
|
as if it has `tformat:` in front of it. For example, these two are
|
||||||
|
equivalent:
|
||||||
|
+
|
||||||
|
---------------------
|
||||||
|
$ git log -2 --pretty=tformat:%h 4da45bef
|
||||||
|
$ git log -2 --pretty=%h 4da45bef
|
||||||
|
---------------------
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
--pretty[='<format>']::
|
--pretty[='<format>']::
|
||||||
|
--format[='<format>']::
|
||||||
|
|
||||||
Pretty-print the contents of the commit logs in a given format,
|
Pretty-print the contents of the commit logs in a given format,
|
||||||
where '<format>' can be one of 'oneline', 'short', 'medium',
|
where '<format>' can be one of 'oneline', 'short', 'medium',
|
||||||
|
@ -17,6 +18,10 @@ configuration (see linkgit:git-config[1]).
|
||||||
This should make "--pretty=oneline" a whole lot more readable for
|
This should make "--pretty=oneline" a whole lot more readable for
|
||||||
people using 80-column terminals.
|
people using 80-column terminals.
|
||||||
|
|
||||||
|
--oneline::
|
||||||
|
This is a shorthand for "--pretty=oneline --abbrev-commit"
|
||||||
|
used together.
|
||||||
|
|
||||||
--encoding[=<encoding>]::
|
--encoding[=<encoding>]::
|
||||||
The commit objects record the encoding used for the log message
|
The commit objects record the encoding used for the log message
|
||||||
in their encoding header; this option can be used to tell the
|
in their encoding header; this option can be used to tell the
|
||||||
|
|
|
@ -1018,6 +1018,11 @@ _git_log ()
|
||||||
" "" "${cur##--pretty=}"
|
" "" "${cur##--pretty=}"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
--format=*)
|
||||||
|
__gitcomp "$__git_log_pretty_formats
|
||||||
|
" "" "${cur##--format=}"
|
||||||
|
return
|
||||||
|
;;
|
||||||
--date=*)
|
--date=*)
|
||||||
__gitcomp "
|
__gitcomp "
|
||||||
relative iso8601 rfc2822 short local default
|
relative iso8601 rfc2822 short local default
|
||||||
|
@ -1033,7 +1038,7 @@ _git_log ()
|
||||||
--follow
|
--follow
|
||||||
--abbrev-commit --abbrev=
|
--abbrev-commit --abbrev=
|
||||||
--relative-date --date=
|
--relative-date --date=
|
||||||
--pretty=
|
--pretty= --format= --oneline
|
||||||
--cherry-pick
|
--cherry-pick
|
||||||
--graph
|
--graph
|
||||||
--decorate
|
--decorate
|
||||||
|
@ -1545,8 +1550,13 @@ _git_show ()
|
||||||
" "" "${cur##--pretty=}"
|
" "" "${cur##--pretty=}"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
--format=*)
|
||||||
|
__gitcomp "$__git_log_pretty_formats
|
||||||
|
" "" "${cur##--format=}"
|
||||||
|
return
|
||||||
|
;;
|
||||||
--*)
|
--*)
|
||||||
__gitcomp "--pretty=
|
__gitcomp "--pretty= --format=
|
||||||
$__git_diff_common_options
|
$__git_diff_common_options
|
||||||
"
|
"
|
||||||
return
|
return
|
||||||
|
|
20
pretty.c
20
pretty.c
|
@ -10,6 +10,15 @@
|
||||||
|
|
||||||
static char *user_format;
|
static char *user_format;
|
||||||
|
|
||||||
|
static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)
|
||||||
|
{
|
||||||
|
free(user_format);
|
||||||
|
user_format = xstrdup(cp);
|
||||||
|
if (is_tformat)
|
||||||
|
rev->use_terminator = 1;
|
||||||
|
rev->commit_format = CMIT_FMT_USERFORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
void get_commit_format(const char *arg, struct rev_info *rev)
|
void get_commit_format(const char *arg, struct rev_info *rev)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -33,12 +42,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
|
if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
|
||||||
const char *cp = strchr(arg, ':') + 1;
|
save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
|
||||||
free(user_format);
|
|
||||||
user_format = xstrdup(cp);
|
|
||||||
if (arg[0] == 't')
|
|
||||||
rev->use_terminator = 1;
|
|
||||||
rev->commit_format = CMIT_FMT_USERFORMAT;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
|
for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
|
||||||
|
@ -50,6 +54,10 @@ void get_commit_format(const char *arg, struct rev_info *rev)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (strchr(arg, '%')) {
|
||||||
|
save_user_format(rev, arg, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
die("invalid --pretty format: %s", arg);
|
die("invalid --pretty format: %s", arg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1144,9 +1144,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
|
||||||
} else if (!strcmp(arg, "--pretty")) {
|
} else if (!strcmp(arg, "--pretty")) {
|
||||||
revs->verbose_header = 1;
|
revs->verbose_header = 1;
|
||||||
get_commit_format(arg+8, revs);
|
get_commit_format(arg+8, revs);
|
||||||
} else if (!prefixcmp(arg, "--pretty=")) {
|
} else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
|
||||||
revs->verbose_header = 1;
|
revs->verbose_header = 1;
|
||||||
get_commit_format(arg+9, revs);
|
get_commit_format(arg+9, revs);
|
||||||
|
} else if (!strcmp(arg, "--oneline")) {
|
||||||
|
revs->verbose_header = 1;
|
||||||
|
get_commit_format("oneline", revs);
|
||||||
|
revs->abbrev_commit = 1;
|
||||||
} else if (!strcmp(arg, "--graph")) {
|
} else if (!strcmp(arg, "--graph")) {
|
||||||
revs->topo_order = 1;
|
revs->topo_order = 1;
|
||||||
revs->rewrite_parents = 1;
|
revs->rewrite_parents = 1;
|
||||||
|
|
|
@ -37,6 +37,46 @@ test_expect_success setup '
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
|
||||||
|
test_expect_success 'pretty' '
|
||||||
|
|
||||||
|
git log --pretty="format:%s" > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
|
||||||
|
test_expect_success 'pretty (tformat)' '
|
||||||
|
|
||||||
|
git log --pretty="tformat:%s" > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'pretty (shortcut)' '
|
||||||
|
|
||||||
|
git log --pretty="%s" > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'format' '
|
||||||
|
|
||||||
|
git log --format="%s" > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
cat > expect << EOF
|
||||||
|
804a787 sixth
|
||||||
|
394ef78 fifth
|
||||||
|
5d31159 fourth
|
||||||
|
2fbe8c0 third
|
||||||
|
f7dab8e second
|
||||||
|
3a2fdcb initial
|
||||||
|
EOF
|
||||||
|
test_expect_success 'oneline' '
|
||||||
|
|
||||||
|
git log --oneline > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'diff-filter=A' '
|
test_expect_success 'diff-filter=A' '
|
||||||
|
|
||||||
actual=$(git log --pretty="format:%s" --diff-filter=A HEAD) &&
|
actual=$(git log --pretty="format:%s" --diff-filter=A HEAD) &&
|
||||||
|
|
Loading…
Reference in a new issue