git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] for-each-ref: fix setup of option-parsing for --sort
  2007-11-10 14:10 gitweb, updating 'last changed' column on the project page Jon Smirl
@ 2007-11-10 16:07 ` Lars Hjemli
  2007-11-10 16:25   ` Johannes Schindelin
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Hjemli @ 2007-11-10 16:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jakub Narebski, Jon Smirl

The option value for --sort is already a pointer to a pointer to struct
ref_sort, so just use it.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
 builtin-for-each-ref.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index da8c794..e909e66 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -847,7 +847,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 		OPT_GROUP(""),
 		OPT_INTEGER( 0 , "count", &maxcount, "show only <n> matched refs"),
 		OPT_STRING(  0 , "format", &format, "format", "format to use for the output"),
-		OPT_CALLBACK(0 , "sort", &sort_tail, "key",
+		OPT_CALLBACK(0 , "sort", sort_tail, "key",
 		            "field name to sort on", &opt_parse_sort),
 		OPT_END(),
 	};
-- 
1.5.3.5.623.g0a1d

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

* Re: [PATCH] for-each-ref: fix setup of option-parsing for --sort
  2007-11-10 16:07 ` [PATCH] for-each-ref: fix setup of option-parsing for --sort Lars Hjemli
@ 2007-11-10 16:25   ` Johannes Schindelin
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Schindelin @ 2007-11-10 16:25 UTC (permalink / raw)
  To: Lars Hjemli; +Cc: Junio C Hamano, git, Jakub Narebski, Jon Smirl

Hi,

On Sat, 10 Nov 2007, Lars Hjemli wrote:

> The option value for --sort is already a pointer to a pointer to struct
> ref_sort, so just use it.

Could you add a test for that too, please?

Thanks,
Dscho

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

* [PATCH] for-each-ref: fix setup of option-parsing for --sort
@ 2007-11-10 16:47 Lars Hjemli
  2007-11-10 18:58 ` Junio C Hamano
  2007-11-11 19:19 ` Johannes Schindelin
  0 siblings, 2 replies; 5+ messages in thread
From: Lars Hjemli @ 2007-11-10 16:47 UTC (permalink / raw)
  To: Johannes Schindelin, Junio C Hamano; +Cc: Jakub Narebski, Jon Smirl, git

The option value for --sort is already a pointer to a pointer to struct
ref_sort, so just use it.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---

On Nov 10, 2007 5:25 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Could you add a test for that too, please?

Is this ok?


 builtin-for-each-ref.c  |    2 +-
 t/t6300-for-each-ref.sh |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index da8c794..e909e66 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -847,7 +847,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 		OPT_GROUP(""),
 		OPT_INTEGER( 0 , "count", &maxcount, "show only <n> matched refs"),
 		OPT_STRING(  0 , "format", &format, "format", "format to use for the output"),
-		OPT_CALLBACK(0 , "sort", &sort_tail, "key",
+		OPT_CALLBACK(0 , "sort", sort_tail, "key",
 		            "field name to sort on", &opt_parse_sort),
 		OPT_END(),
 	};
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index d0809eb..c722635 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -148,4 +148,26 @@ test_expect_success 'Check format "rfc2822" date fields output' '
 	git diff expected actual
 '
 
+cat >expected <<\EOF
+refs/heads/master
+refs/tags/testtag
+EOF
+
+test_expect_success 'Verify ascending sort' '
+	git-for-each-ref --format="%(refname)" --sort=refname >actual &&
+	git diff expected actual
+'
+
+
+cat >expected <<\EOF
+refs/tags/testtag
+refs/heads/master
+EOF
+
+test_expect_success 'Verify descending sort' '
+	git-for-each-ref --format="%(refname)" --sort=-refname >actual &&
+	git diff expected actual
+'
+
+
 test_done
-- 
1.5.3.5.623.g0a1d

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

* Re: [PATCH] for-each-ref: fix setup of option-parsing for --sort
  2007-11-10 16:47 [PATCH] for-each-ref: fix setup of option-parsing for --sort Lars Hjemli
@ 2007-11-10 18:58 ` Junio C Hamano
  2007-11-11 19:19 ` Johannes Schindelin
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2007-11-10 18:58 UTC (permalink / raw)
  To: Lars Hjemli; +Cc: Johannes Schindelin, Jakub Narebski, Jon Smirl, git

Lars Hjemli <hjemli@gmail.com> writes:

> The option value for --sort is already a pointer to a pointer to struct
> ref_sort, so just use it.
>
> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
> ---
>
> On Nov 10, 2007 5:25 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>> Could you add a test for that too, please?
>
> Is this ok?
>

Testing "for that" would be kind of hard and semi pointless,
isn't it?

If it's mismatch of the expected number of times a pointer is
dereferenced between the caller and the callee, I'd imagine that
it will read from and write to random place in memory and would
lead to unpredictable behaviour.  If you are lucky you would not
get expected results but if you are unlucky who knows what would
happen.

But the new test makes sure --sort takes intended effect, which
is a good thing.

Thanks.

>  builtin-for-each-ref.c  |    2 +-
>  t/t6300-for-each-ref.sh |   22 ++++++++++++++++++++++
>  2 files changed, 23 insertions(+), 1 deletions(-)
>
> diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
> index da8c794..e909e66 100644
> --- a/builtin-for-each-ref.c
> +++ b/builtin-for-each-ref.c
> @@ -847,7 +847,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
>  		OPT_GROUP(""),
>  		OPT_INTEGER( 0 , "count", &maxcount, "show only <n> matched refs"),
>  		OPT_STRING(  0 , "format", &format, "format", "format to use for the output"),
> -		OPT_CALLBACK(0 , "sort", &sort_tail, "key",
> +		OPT_CALLBACK(0 , "sort", sort_tail, "key",
>  		            "field name to sort on", &opt_parse_sort),
>  		OPT_END(),
>  	};
> diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
> index d0809eb..c722635 100755
> --- a/t/t6300-for-each-ref.sh
> +++ b/t/t6300-for-each-ref.sh
> @@ -148,4 +148,26 @@ test_expect_success 'Check format "rfc2822" date fields output' '
>  	git diff expected actual
>  '
>  
> +cat >expected <<\EOF
> +refs/heads/master
> +refs/tags/testtag
> +EOF
> +
> +test_expect_success 'Verify ascending sort' '
> +	git-for-each-ref --format="%(refname)" --sort=refname >actual &&
> +	git diff expected actual
> +'
> +
> +
> +cat >expected <<\EOF
> +refs/tags/testtag
> +refs/heads/master
> +EOF
> +
> +test_expect_success 'Verify descending sort' '
> +	git-for-each-ref --format="%(refname)" --sort=-refname >actual &&
> +	git diff expected actual
> +'
> +
> +
>  test_done
> -- 
> 1.5.3.5.623.g0a1d

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

* Re: [PATCH] for-each-ref: fix setup of option-parsing for --sort
  2007-11-10 16:47 [PATCH] for-each-ref: fix setup of option-parsing for --sort Lars Hjemli
  2007-11-10 18:58 ` Junio C Hamano
@ 2007-11-11 19:19 ` Johannes Schindelin
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Schindelin @ 2007-11-11 19:19 UTC (permalink / raw)
  To: Lars Hjemli; +Cc: Junio C Hamano, Jakub Narebski, Jon Smirl, git

Hi,

On Sat, 10 Nov 2007, Lars Hjemli wrote:

> The option value for --sort is already a pointer to a pointer to struct
> ref_sort, so just use it.
> 
> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
> ---
> 
> On Nov 10, 2007 5:25 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > Could you add a test for that too, please?
> 
> Is this ok?

That's exactly what I had in mind.

Thank you,
Dscho

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

end of thread, other threads:[~2007-11-11 19:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-10 16:47 [PATCH] for-each-ref: fix setup of option-parsing for --sort Lars Hjemli
2007-11-10 18:58 ` Junio C Hamano
2007-11-11 19:19 ` Johannes Schindelin
  -- strict thread matches above, loose matches on Subject: below --
2007-11-10 14:10 gitweb, updating 'last changed' column on the project page Jon Smirl
2007-11-10 16:07 ` [PATCH] for-each-ref: fix setup of option-parsing for --sort Lars Hjemli
2007-11-10 16:25   ` Johannes Schindelin

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).