* [PATCH] Add some basic tests of rev-list --pretty=format @ 2007-03-28 0:08 Jeff King 2007-03-28 19:21 ` Alex Riesen 2007-03-28 20:11 ` [PATCH] Improve output of %p and %P format in git-rev-list --pretty=format: Alex Riesen 0 siblings, 2 replies; 5+ messages in thread From: Jeff King @ 2007-03-28 0:08 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Johannes.Schindelin These could stand to be a little more complex, but it should at least catch obvious problems (like the recently fixed %ct bug). Signed-off-by: Jeff King <peff@peff.net> --- Junio: warning, there is (intentional) trailing whitespace in one of the test results. t/t6006-rev-list-format.sh | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 108 insertions(+), 0 deletions(-) create mode 100644 t/t6006-rev-list-format.sh diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh new file mode 100644 index 0000000..cf096c3 --- /dev/null +++ b/t/t6006-rev-list-format.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +test_description='git-rev-list --pretty=format test' + +. ./test-lib.sh + +test_tick +test_expect_success 'setup' ' +touch foo && git-add foo && git-commit -m "added foo" && + echo changed >foo && git-commit -a -m "changed foo" +' + +# usage: test_format name format_string <expected_output +test_format() { + cat >expect.$1 + test_expect_success "format $1" " +git-rev-list --pretty=format:$2 master >output.$1 && +git-diff expect.$1 output.$1 +" +} + +test_format hash %H%n%h <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +131a310eb913d107dd3c09a65d1651175898735d +131a310 +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +86c75cf +EOF + +test_format tree %T%n%t <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +fe722612f26da5064c32ca3843aa154bdb0b08a0 +fe72261 +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +4d5fcadc293a348e88f777dc0920f11e7d71441c +4d5fcad +EOF + +test_format parents %P%n%p <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +86c75cf +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +86c75cf +86c75cf +EOF + +# we don't test relative here +test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +A U Thor +author@example.com +Thu Apr 7 15:13:13 2005 -0700 +Thu, 7 Apr 2005 15:13:13 -0700 +1112911993 +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +A U Thor +author@example.com +Thu Apr 7 15:13:13 2005 -0700 +Thu, 7 Apr 2005 15:13:13 -0700 +1112911993 +EOF + +test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +C O Mitter +committer@example.com +Thu Apr 7 15:13:13 2005 -0700 +Thu, 7 Apr 2005 15:13:13 -0700 +1112911993 +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +C O Mitter +committer@example.com +Thu Apr 7 15:13:13 2005 -0700 +Thu, 7 Apr 2005 15:13:13 -0700 +1112911993 +EOF + +test_format encoding %e <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +<unknown> +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +<unknown> +EOF + +test_format subject %s <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +changed foo +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +added foo +EOF + +test_format body %b <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +<unknown> +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +<unknown> +EOF + +test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF' +commit 131a310eb913d107dd3c09a65d1651175898735d +^[[31mfoo^[[32mbar^[[34mbaz^[[mxyzzy +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +^[[31mfoo^[[32mbar^[[34mbaz^[[mxyzzy +EOF + +test_done -- 1.5.1.rc2.619.g9dd2d ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Add some basic tests of rev-list --pretty=format 2007-03-28 0:08 [PATCH] Add some basic tests of rev-list --pretty=format Jeff King @ 2007-03-28 19:21 ` Alex Riesen 2007-03-28 20:37 ` [PATCH] Fix "--pretty=format:" for parent related items Junio C Hamano 2007-03-28 20:11 ` [PATCH] Improve output of %p and %P format in git-rev-list --pretty=format: Alex Riesen 1 sibling, 1 reply; 5+ messages in thread From: Alex Riesen @ 2007-03-28 19:21 UTC (permalink / raw) To: Jeff King; +Cc: Junio C Hamano, git, Johannes.Schindelin Jeff King, Wed, Mar 28, 2007 02:08:28 +0200: > +test_format parents %P%n%p <<'EOF' > +commit 131a310eb913d107dd3c09a65d1651175898735d > +86c75cfd708a0e5868dc876ed5b8bb66c80b4873 > +86c75cf > +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 > +86c75cf > +86c75cf > +EOF Isn't this a bit wrong for initial commit? ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Fix "--pretty=format:" for parent related items. 2007-03-28 19:21 ` Alex Riesen @ 2007-03-28 20:37 ` Junio C Hamano 0 siblings, 0 replies; 5+ messages in thread From: Junio C Hamano @ 2007-03-28 20:37 UTC (permalink / raw) To: Alex Riesen; +Cc: Jeff King, git, Johannes.Schindelin There are two breakages in the %P/%p interpolation. It appended an excess SP at the end of the list, and it gave uninitialized contents of a buffer on the stack for root commits. This fixes it, while updating the t6006 test which expected the wrong output. Signed-off-by: Junio C Hamano <junkio@cox.net> --- commit.c | 12 ++++++++---- t/t6006-rev-list-format.sh | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) mode change 100644 => 100755 t/t6006-rev-list-format.sh diff --git a/commit.c b/commit.c index a92958c..33b63c4 100644 --- a/commit.c +++ b/commit.c @@ -849,19 +849,23 @@ static long format_commit_message(const struct commit *commit, interp_set_entry(table, ITREE_ABBREV, find_unique_abbrev(commit->tree->object.sha1, DEFAULT_ABBREV)); + + parents[1] = 0; for (i = 0, p = commit->parents; p && i < sizeof(parents) - 1; p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ", + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s", sha1_to_hex(p->item->object.sha1)); - interp_set_entry(table, IPARENTS, parents); + interp_set_entry(table, IPARENTS, parents + 1); + + parents[1] = 0; for (i = 0, p = commit->parents; p && i < sizeof(parents) - 1; p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ", + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s", find_unique_abbrev(p->item->object.sha1, DEFAULT_ABBREV)); - interp_set_entry(table, IPARENTS_ABBREV, parents); + interp_set_entry(table, IPARENTS_ABBREV, parents + 1); for (i = 0, state = HEADER; msg[i] && state < BODY; i++) { int eol; diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh old mode 100644 new mode 100755 index cf096c3..ce9c7dc --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -39,11 +39,11 @@ EOF test_format parents %P%n%p <<'EOF' commit 131a310eb913d107dd3c09a65d1651175898735d -86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cf +86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +86c75cf commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cf -86c75cf + + EOF # we don't test relative here -- 1.5.1.rc2.632.g054ea8 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] Improve output of %p and %P format in git-rev-list --pretty=format: 2007-03-28 0:08 [PATCH] Add some basic tests of rev-list --pretty=format Jeff King 2007-03-28 19:21 ` Alex Riesen @ 2007-03-28 20:11 ` Alex Riesen 2007-03-28 20:24 ` Jeff King 1 sibling, 1 reply; 5+ messages in thread From: Alex Riesen @ 2007-03-28 20:11 UTC (permalink / raw) To: Jeff King; +Cc: Junio C Hamano, git, Johannes.Schindelin Remove the terminating space from the space-separated list of parents. Also fix the test t6006: it wrongly assumed that the initial commit has a parent and was not executable. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> --- The test even hardcoded parents of the initial commit to the initial commit itself, which does not make any sense at all. commit.c | 5 +++-- t/t6006-rev-list-format.sh | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/commit.c b/commit.c index a92958c..94b3713 100644 --- a/commit.c +++ b/commit.c @@ -852,13 +852,14 @@ static long format_commit_message(const struct commit *commit, for (i = 0, p = commit->parents; p && i < sizeof(parents) - 1; p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ", + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s" + !i, sha1_to_hex(p->item->object.sha1)); interp_set_entry(table, IPARENTS, parents); + *parents = '\0'; for (i = 0, p = commit->parents; p && i < sizeof(parents) - 1; p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ", + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s" + !i, find_unique_abbrev(p->item->object.sha1, DEFAULT_ABBREV)); interp_set_entry(table, IPARENTS_ABBREV, parents); diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index cf096c3..ce9c7dc 100644 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -39,11 +39,11 @@ EOF test_format parents %P%n%p <<'EOF' commit 131a310eb913d107dd3c09a65d1651175898735d -86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cf +86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +86c75cf commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cf -86c75cf + + EOF # we don't test relative here -- 1.5.1.rc2.18.g157b4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Improve output of %p and %P format in git-rev-list --pretty=format: 2007-03-28 20:11 ` [PATCH] Improve output of %p and %P format in git-rev-list --pretty=format: Alex Riesen @ 2007-03-28 20:24 ` Jeff King 0 siblings, 0 replies; 5+ messages in thread From: Jeff King @ 2007-03-28 20:24 UTC (permalink / raw) To: Alex Riesen; +Cc: Junio C Hamano, git, Johannes.Schindelin On Wed, Mar 28, 2007 at 10:11:23PM +0200, Alex Riesen wrote: > Remove the terminating space from the space-separated list of parents. > Also fix the test t6006: it wrongly assumed that the initial commit > has a parent and was not executable. Argh, yes. As is probably obvious, I moved the actual output to be 'expected' after giving it a cursory check, but I was more focused on the author/committer information, since that's where I was fixing bugs. Good catch. This is obviously fairly untested code. I will follow up with a few more tests for encoding/body to help make it more complete. -Peff ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-03-28 20:37 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-03-28 0:08 [PATCH] Add some basic tests of rev-list --pretty=format Jeff King 2007-03-28 19:21 ` Alex Riesen 2007-03-28 20:37 ` [PATCH] Fix "--pretty=format:" for parent related items Junio C Hamano 2007-03-28 20:11 ` [PATCH] Improve output of %p and %P format in git-rev-list --pretty=format: Alex Riesen 2007-03-28 20:24 ` Jeff King
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).