From 3a4c1a5e212357c3df030b6713c75466694c2e77 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Tue, 24 Feb 2009 18:59:14 +0900 Subject: Add --format that is a synonym to --pretty Some people prefer to call the pretty-print styles "format", and get annoyed to see "git log --format=short" fail. Introduce it as a synonym to --pretty so that both can be used. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 5f21efe..6596019 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -1,4 +1,5 @@ --pretty[='']:: +--format[='']:: Pretty-print the contents of the commit logs in a given format, where '' can be one of 'oneline', 'short', 'medium', diff --git a/revision.c b/revision.c index 286e416..556c319 100644 --- a/revision.c +++ b/revision.c @@ -1144,7 +1144,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--pretty")) { revs->verbose_header = 1; get_commit_format(arg+8, revs); - } else if (!prefixcmp(arg, "--pretty=")) { + } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) { revs->verbose_header = 1; get_commit_format(arg+9, revs); } else if (!strcmp(arg, "--graph")) { -- cgit v0.10.2-6-g49f6 From 36407548a2825462a91b456755412a65fd611fc0 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Tue, 24 Feb 2009 18:59:15 +0900 Subject: Give short-hands to --pretty=tformat:%formatstring Allow --pretty="%h %s" (and --format="%h %s") as shorthand for an often used option --pretty=tformat:"%h %s". Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 159390c..5c6e678 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -152,3 +152,12 @@ $ git log -2 --pretty=tformat:%h 4da45bef \ 4da45be 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 +--------------------- diff --git a/pretty.c b/pretty.c index 6cd9149..d739f6d 100644 --- a/pretty.c +++ b/pretty.c @@ -10,6 +10,15 @@ 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) { int i; @@ -33,12 +42,7 @@ void get_commit_format(const char *arg, struct rev_info *rev) return; } if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) { - const char *cp = strchr(arg, ':') + 1; - free(user_format); - user_format = xstrdup(cp); - if (arg[0] == 't') - rev->use_terminator = 1; - rev->commit_format = CMIT_FMT_USERFORMAT; + save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't'); return; } 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; } } + if (strchr(arg, '%')) { + save_user_format(rev, arg, 1); + return; + } die("invalid --pretty format: %s", arg); } -- cgit v0.10.2-6-g49f6 From de84accc59baef73f7827d59f0d479521ecad937 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Tue, 24 Feb 2009 18:59:16 +0900 Subject: Add --oneline that is a synonym to "--pretty=oneline --abbrev-commit" These two are often used together but are too long to type. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 6596019..bff9499 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -18,6 +18,10 @@ configuration (see linkgit:git-config[1]). This should make "--pretty=oneline" a whole lot more readable for people using 80-column terminals. +--oneline:: + This is a shorthand for "--pretty=oneline --abbrev-commit" + used together. + --encoding[=]:: The commit objects record the encoding used for the log message in their encoding header; this option can be used to tell the diff --git a/revision.c b/revision.c index 556c319..c4efe5b 100644 --- a/revision.c +++ b/revision.c @@ -1147,6 +1147,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) { revs->verbose_header = 1; 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")) { revs->topo_order = 1; revs->rewrite_parents = 1; -- cgit v0.10.2-6-g49f6 From bb93afd5153948e58d6b09c86e7c106a65dbfb65 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 24 Feb 2009 23:06:37 +0200 Subject: Add tests for git log --pretty, --format and --oneline. More specifically; --pretty=format, tformat and new %foo shortcut. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 7b976ee..6d43459 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -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' ' actual=$(git log --pretty="format:%s" --diff-filter=A HEAD) && -- cgit v0.10.2-6-g49f6 From 72de29c24f50dccc5f045a7756bb0b47e34a7a8e Mon Sep 17 00:00:00 2001 From: Teemu Likonen Date: Tue, 24 Feb 2009 15:33:29 +0200 Subject: bash completion: add --format= and --oneline options for "git log" We also add --format= completion for "git show". Signed-off-by: Teemu Likonen Acked-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a3092f..31608cb 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1014,6 +1014,11 @@ _git_log () " "" "${cur##--pretty=}" return ;; + --format=*) + __gitcomp "$__git_log_pretty_formats + " "" "${cur##--format=}" + return + ;; --date=*) __gitcomp " relative iso8601 rfc2822 short local default @@ -1029,7 +1034,7 @@ _git_log () --follow --abbrev-commit --abbrev= --relative-date --date= - --pretty= + --pretty= --format= --oneline --cherry-pick --graph --decorate @@ -1541,8 +1546,13 @@ _git_show () " "" "${cur##--pretty=}" return ;; + --format=*) + __gitcomp "$__git_log_pretty_formats + " "" "${cur##--format=}" + return + ;; --*) - __gitcomp "--pretty= + __gitcomp "--pretty= --format= $__git_diff_common_options " return -- cgit v0.10.2-6-g49f6