All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] t6300: test sort with multiple keys
@ 2012-08-19 21:15 Kacper Kornet
  2012-08-19 21:15 ` [PATCH 2/2] for-each-ref: Fix " Kacper Kornet
  2012-08-20  0:38 ` [PATCH 1/2] t6300: test " Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Kacper Kornet @ 2012-08-19 21:15 UTC (permalink / raw)
  To: Git Mailing List

Documentation of git-for-each-ref says that --sort=<key> option can be
used multiple times, in which case the last key becomes the primary key.
However this functionality was never checked in test suite and is
currently broken. This commit adds appropriate test in preparation for fix.

Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
---
 t/t6300-for-each-ref.sh | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..3d59bfc 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -242,7 +242,32 @@ test_expect_success 'Verify descending sort' '
 	test_cmp expected actual
 '
 
+test_expect_success 'Create branches to test sort with multiple keys' '
+	git checkout -b Branch1 &&
+	echo foo >> one &&
+	git commit -a -m "Branch1 commit" &&
+	git checkout -b Branch2 &&
+	echo foo >> one &&
+	git commit -a -m "Branch2 commit"
+'
+
+test_atom refs/heads/Branch1 objectname 32fca05e9f638021a123a84226acf17756acc18b
+test_atom refs/heads/Branch2 objectname 194a5b89ac661a114566ba4374bc06c2797539f3
+
 cat >expected <<\EOF
+67a36f10722846e891fbada1ba48ed035de75581 commit	refs/heads/master
+194a5b89ac661a114566ba4374bc06c2797539f3 commit	refs/heads/Branch2
+32fca05e9f638021a123a84226acf17756acc18b commit	refs/heads/Branch1
+EOF
+
+test_expect_failure 'Verify sort with multiple keys' '
+	git for-each-ref --sort=objectname --sort=committerdate refs/heads > actual &&
+	test_cmp expected actual
+'
+
+cat >expected <<\EOF
+'refs/heads/Branch1'
+'refs/heads/Branch2'
 'refs/heads/master'
 'refs/remotes/origin/master'
 'refs/tags/testtag'
@@ -264,6 +289,8 @@ test_expect_success 'Quoting style: python' '
 '
 
 cat >expected <<\EOF
+"refs/heads/Branch1"
+"refs/heads/Branch2"
 "refs/heads/master"
 "refs/remotes/origin/master"
 "refs/tags/testtag"
@@ -285,6 +312,8 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
 done
 
 cat >expected <<\EOF
+Branch1
+Branch2
 master
 testtag
 EOF
@@ -296,6 +325,8 @@ test_expect_success 'Check short refname format' '
 '
 
 cat >expected <<EOF
+
+
 origin/master
 EOF
 
@@ -309,7 +340,7 @@ cat >expected <<EOF
 EOF
 
 test_expect_success 'Check short objectname format' '
-	git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
+	git for-each-ref --format="%(objectname:short)" refs/heads/master >actual &&
 	test_cmp expected actual
 '
 
-- 
1.7.12.rc3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] for-each-ref: Fix sort with multiple keys
  2012-08-19 21:15 [PATCH 1/2] t6300: test sort with multiple keys Kacper Kornet
@ 2012-08-19 21:15 ` Kacper Kornet
  2012-08-20  0:41   ` Junio C Hamano
  2012-08-20  0:38 ` [PATCH 1/2] t6300: test " Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Kacper Kornet @ 2012-08-19 21:15 UTC (permalink / raw)
  To: Git Mailing List

The linked list describing sort options was not correctly set up in
opt_parse_sort. In the result, contrary to the documentation. only the
last of multiple --sort options to git-for-each-ref was taken into
account. This commit fixes it.

Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
---
 builtin/for-each-ref.c  | 4 +++-
 t/t6300-for-each-ref.sh | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index b01d76a..0c5294e 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -962,7 +962,9 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
 	if (!arg) /* should --no-sort void the list ? */
 		return -1;
 
-	*sort_tail = s = xcalloc(1, sizeof(*s));
+	s = xcalloc(1, sizeof(*s));
+	s->next = *sort_tail;
+	*sort_tail = s;
 
 	if (*arg == '-') {
 		s->reverse = 1;
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 3d59bfc..4c5d8ba 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -260,7 +260,7 @@ cat >expected <<\EOF
 32fca05e9f638021a123a84226acf17756acc18b commit	refs/heads/Branch1
 EOF
 
-test_expect_failure 'Verify sort with multiple keys' '
+test_expect_success 'Verify sort with multiple keys' '
 	git for-each-ref --sort=objectname --sort=committerdate refs/heads > actual &&
 	test_cmp expected actual
 '
-- 
1.7.12.rc3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] t6300: test sort with multiple keys
  2012-08-19 21:15 [PATCH 1/2] t6300: test sort with multiple keys Kacper Kornet
  2012-08-19 21:15 ` [PATCH 2/2] for-each-ref: Fix " Kacper Kornet
@ 2012-08-20  0:38 ` Junio C Hamano
  2012-08-20  5:24   ` Kacper Kornet
  2012-08-21  7:46   ` [PATCHv2 " Kacper Kornet
  1 sibling, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2012-08-20  0:38 UTC (permalink / raw)
  To: Kacper Kornet; +Cc: Git Mailing List

Kacper Kornet <draenog@pld-linux.org> writes:

> Documentation of git-for-each-ref says that --sort=<key> option can be
> used multiple times, in which case the last key becomes the primary key.
> However this functionality was never checked in test suite and is
> currently broken. This commit adds appropriate test in preparation for fix.
>
> Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
> ---

Thanks.

> +test_expect_success 'Create branches to test sort with multiple keys' '
> +	git checkout -b Branch1 &&
> +	echo foo >> one &&
> +	git commit -a -m "Branch1 commit" &&
> +	git checkout -b Branch2 &&
> +	echo foo >> one &&
> +	git commit -a -m "Branch2 commit"
> +'
> +
> +test_atom refs/heads/Branch1 objectname 32fca05e9f638021a123a84226acf17756acc18b
> +test_atom refs/heads/Branch2 objectname 194a5b89ac661a114566ba4374bc06c2797539f3

Do these need to be "Branch[12]", not "branch[12]" for the code to
exhibit the bug?  If not, please don't be creative in names like
these.  On case corrupting filesystems you may write Branch1 and
they may come back as branch1, but that is not what we are testing
here.

Also, style: redirection sticks to the target file, e.g.

	echo foo >>one &&

> +
>  cat >expected <<\EOF
> +67a36f10722846e891fbada1ba48ed035de75581 commit	refs/heads/master
> +194a5b89ac661a114566ba4374bc06c2797539f3 commit	refs/heads/Branch2
> +32fca05e9f638021a123a84226acf17756acc18b commit	refs/heads/Branch1
> +EOF
> +
> +test_expect_failure 'Verify sort with multiple keys' '
> +	git for-each-ref --sort=objectname --sort=committerdate refs/heads > actual &&
> +	test_cmp expected actual
> +'
> +
> +cat >expected <<\EOF
> +'refs/heads/Branch1'
> +'refs/heads/Branch2'
>  'refs/heads/master'
>  'refs/remotes/origin/master'
>  'refs/tags/testtag'
> @@ -264,6 +289,8 @@ test_expect_success 'Quoting style: python' '
>  '
>  
>  cat >expected <<\EOF
> +"refs/heads/Branch1"
> +"refs/heads/Branch2"
>  "refs/heads/master"
>  "refs/remotes/origin/master"
>  "refs/tags/testtag"
> @@ -285,6 +312,8 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
>  done
>  
>  cat >expected <<\EOF
> +Branch1
> +Branch2
>  master
>  testtag
>  EOF
> @@ -296,6 +325,8 @@ test_expect_success 'Check short refname format' '
>  '
>  
>  cat >expected <<EOF
> +
> +
>  origin/master

What are these blank line outputs?

>  EOF
>  
> @@ -309,7 +340,7 @@ cat >expected <<EOF
>  EOF
>  
>  test_expect_success 'Check short objectname format' '
> -	git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
> +	git for-each-ref --format="%(objectname:short)" refs/heads/master >actual &&
>  	test_cmp expected actual
>  '

All in all, I have to wonder if you can limit the updates to other
unrelated tests if you added a new test near the end.  Also doesn't
the existing test already create enough refs to let you sort with
multiple keys and demonstrate the breakage already, without adding
new refs and objects?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] for-each-ref: Fix sort with multiple keys
  2012-08-19 21:15 ` [PATCH 2/2] for-each-ref: Fix " Kacper Kornet
@ 2012-08-20  0:41   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2012-08-20  0:41 UTC (permalink / raw)
  To: Kacper Kornet; +Cc: Git Mailing List

Kacper Kornet <draenog@pld-linux.org> writes:

> The linked list describing sort options was not correctly set up in
> opt_parse_sort. In the result, contrary to the documentation. only the
> last of multiple --sort options to git-for-each-ref was taken into
> account. This commit fixes it.
>
> Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
> ---
>  builtin/for-each-ref.c  | 4 +++-
>  t/t6300-for-each-ref.sh | 2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
> index b01d76a..0c5294e 100644
> --- a/builtin/for-each-ref.c
> +++ b/builtin/for-each-ref.c
> @@ -962,7 +962,9 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
>  	if (!arg) /* should --no-sort void the list ? */
>  		return -1;
>  
> -	*sort_tail = s = xcalloc(1, sizeof(*s));
> +	s = xcalloc(1, sizeof(*s));
> +	s->next = *sort_tail;
> +	*sort_tail = s;

This fix looks correct.  

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] t6300: test sort with multiple keys
  2012-08-20  0:38 ` [PATCH 1/2] t6300: test " Junio C Hamano
@ 2012-08-20  5:24   ` Kacper Kornet
  2012-08-21  7:46   ` [PATCHv2 " Kacper Kornet
  1 sibling, 0 replies; 8+ messages in thread
From: Kacper Kornet @ 2012-08-20  5:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Sun, Aug 19, 2012 at 05:38:29PM -0700, Junio C Hamano wrote:
> Kacper Kornet <draenog@pld-linux.org> writes:

> > Documentation of git-for-each-ref says that --sort=<key> option can be
> > used multiple times, in which case the last key becomes the primary key.
> > However this functionality was never checked in test suite and is
> > currently broken. This commit adds appropriate test in preparation for fix.

> > Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
> > ---

> Thanks.

> > +test_expect_success 'Create branches to test sort with multiple keys' '
> > +	git checkout -b Branch1 &&
> > +	echo foo >> one &&
> > +	git commit -a -m "Branch1 commit" &&
> > +	git checkout -b Branch2 &&
> > +	echo foo >> one &&
> > +	git commit -a -m "Branch2 commit"
> > +'
> > +
> > +test_atom refs/heads/Branch1 objectname 32fca05e9f638021a123a84226acf17756acc18b
> > +test_atom refs/heads/Branch2 objectname 194a5b89ac661a114566ba4374bc06c2797539f3

> Do these need to be "Branch[12]", not "branch[12]" for the code to
> exhibit the bug?  If not, please don't be creative in names like
> these.  On case corrupting filesystems you may write Branch1 and
> they may come back as branch1, but that is not what we are testing
> here.

Branches names can be lowercased. Only the commit messages should be
preserved as they produce the test depends on the lexicographical order
of created SHA1s.

> > @@ -296,6 +325,8 @@ test_expect_success 'Check short refname format' '
> >  '

> >  cat >expected <<EOF
> > +
> > +
> >  origin/master

> What are these blank line outputs?

The upstreams of Branch1 and Branch2.

> >  EOF

> > @@ -309,7 +340,7 @@ cat >expected <<EOF
> >  EOF

> >  test_expect_success 'Check short objectname format' '
> > -	git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
> > +	git for-each-ref --format="%(objectname:short)" refs/heads/master >actual &&
> >  	test_cmp expected actual
> >  '

> All in all, I have to wonder if you can limit the updates to other
> unrelated tests if you added a new test near the end.  Also doesn't
> the existing test already create enough refs to let you sort with
> multiple keys and demonstrate the breakage already, without adding new
> refs and objects?

My intention was to group all tests to sort in one place. But if the
preferred place for a new one is at the end, then it is possible to find
the adequate refs among existing ones.

-- 
  Kacper Kornet

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCHv2 1/2] t6300: test sort with multiple keys
  2012-08-20  0:38 ` [PATCH 1/2] t6300: test " Junio C Hamano
  2012-08-20  5:24   ` Kacper Kornet
@ 2012-08-21  7:46   ` Kacper Kornet
  2012-08-21  7:47     ` [PATCHv2 2/2] for-each-ref: Fix " Kacper Kornet
  2012-08-21 21:33     ` [PATCHv2 1/2] t6300: test " Junio C Hamano
  1 sibling, 2 replies; 8+ messages in thread
From: Kacper Kornet @ 2012-08-21  7:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Documentation of git-for-each-ref says that --sort=<key> option can be
used multiple times, in which case the last key becomes the primary key.
However this functionality was never checked in test suite and is
currently broken. This commit adds appropriate test in preparation for fix.

Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
---
 t/t6300-for-each-ref.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..a0d82d4 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -456,4 +456,14 @@ test_atom refs/tags/signed-long contents "subject line
 body contents
 $sig"
 
+cat >expected <<\EOF
+408fe76d02a785a006c2e9c669b7be5589ede96d <committer@example.com> refs/tags/master
+90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo
+EOF
+
+test_expect_failure 'Verify sort with multiple keys' '
+	git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
+		refs/tags/bogo refs/tags/master > actual &&
+	test_cmp expected actual
+'
 test_done
-- 
1.7.12.rc3


-- 
  Kacper Kornet

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCHv2 2/2] for-each-ref: Fix sort with multiple keys
  2012-08-21  7:46   ` [PATCHv2 " Kacper Kornet
@ 2012-08-21  7:47     ` Kacper Kornet
  2012-08-21 21:33     ` [PATCHv2 1/2] t6300: test " Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Kacper Kornet @ 2012-08-21  7:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

The linked list describing sort options was not correctly set up in
opt_parse_sort. In the result, contrary to the documentation, only the
last of multiple --sort options to git-for-each-ref was taken into
account. This commit fixes it.

Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
---
 builtin/for-each-ref.c  | 4 +++-
 t/t6300-for-each-ref.sh | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index b01d76a..0c5294e 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -962,7 +962,9 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
 	if (!arg) /* should --no-sort void the list ? */
 		return -1;
 
-	*sort_tail = s = xcalloc(1, sizeof(*s));
+	s = xcalloc(1, sizeof(*s));
+	s->next = *sort_tail;
+	*sort_tail = s;
 
 	if (*arg == '-') {
 		s->reverse = 1;
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index a0d82d4..752f5cb 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -461,7 +461,7 @@ cat >expected <<\EOF
 90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo
 EOF
 
-test_expect_failure 'Verify sort with multiple keys' '
+test_expect_success 'Verify sort with multiple keys' '
 	git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
 		refs/tags/bogo refs/tags/master > actual &&
 	test_cmp expected actual
-- 
1.7.12.rc3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCHv2 1/2] t6300: test sort with multiple keys
  2012-08-21  7:46   ` [PATCHv2 " Kacper Kornet
  2012-08-21  7:47     ` [PATCHv2 2/2] for-each-ref: Fix " Kacper Kornet
@ 2012-08-21 21:33     ` Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2012-08-21 21:33 UTC (permalink / raw)
  To: Kacper Kornet; +Cc: git

Kacper Kornet <draenog@pld-linux.org> writes:

> Documentation of git-for-each-ref says that --sort=<key> option can be
> used multiple times, in which case the last key becomes the primary key.
> However this functionality was never checked in test suite and is
> currently broken. This commit adds appropriate test in preparation for fix.
>
> Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
> ---
>  t/t6300-for-each-ref.sh | 10 ++++++++++
>  1 file changed, 10 insertions(+)

Much nicer and concise.  It would have been even better if it didn't
have to depend on exact object names, but the existing tests already
depend on them, so it is not making things worse.

Thanks.  Will queue.

> diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
> index 1721784..a0d82d4 100755
> --- a/t/t6300-for-each-ref.sh
> +++ b/t/t6300-for-each-ref.sh
> @@ -456,4 +456,14 @@ test_atom refs/tags/signed-long contents "subject line
>  body contents
>  $sig"
>  
> +cat >expected <<\EOF
> +408fe76d02a785a006c2e9c669b7be5589ede96d <committer@example.com> refs/tags/master
> +90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo
> +EOF
> +
> +test_expect_failure 'Verify sort with multiple keys' '
> +	git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
> +		refs/tags/bogo refs/tags/master > actual &&
> +	test_cmp expected actual
> +'
>  test_done
> -- 
> 1.7.12.rc3

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-21 21:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-19 21:15 [PATCH 1/2] t6300: test sort with multiple keys Kacper Kornet
2012-08-19 21:15 ` [PATCH 2/2] for-each-ref: Fix " Kacper Kornet
2012-08-20  0:41   ` Junio C Hamano
2012-08-20  0:38 ` [PATCH 1/2] t6300: test " Junio C Hamano
2012-08-20  5:24   ` Kacper Kornet
2012-08-21  7:46   ` [PATCHv2 " Kacper Kornet
2012-08-21  7:47     ` [PATCHv2 2/2] for-each-ref: Fix " Kacper Kornet
2012-08-21 21:33     ` [PATCHv2 1/2] t6300: test " Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.