All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]  commit: Remove backward goto in read_craft_line()
@ 2010-12-01 19:59 Ralf Thielow
  0 siblings, 0 replies; 8+ messages in thread
From: Ralf Thielow @ 2010-12-01 19:59 UTC (permalink / raw)
  To: git; +Cc: Ralf Thielow

 Bad graft data is noticed in several places in read_graft_line and
 in each case we go back to the first site of detection.  Move the
 error handling to the end of the function for better readability.

Signed-off-by: Ralf Thielow <ralf.thielow@googlemail.com>
---
 commit.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index 0094ec1..642ee34 100644
--- a/commit.c
+++ b/commit.c
@@ -137,12 +137,8 @@ struct commit_graft *read_graft_line(char *buf, int len)
 		buf[--len] = '\0';
 	if (buf[0] == '#' || buf[0] == '\0')
 		return NULL;
-	if ((len + 1) % 41) {
-	bad_graft_data:
-		error("bad graft data: %s", buf);
-		free(graft);
-		return NULL;
-	}
+	if ((len + 1) % 41)
+		goto bad_graft_data;
 	i = (len + 1) / 41 - 1;
 	graft = xmalloc(sizeof(*graft) + 20 * i);
 	graft->nr_parent = i;
@@ -155,6 +151,10 @@ struct commit_graft *read_graft_line(char *buf, int len)
 			goto bad_graft_data;
 	}
 	return graft;
+ bad_graft_data:
+	error("bad graft data: %s", buf);
+	free(graft);
+	return NULL;
 }
 
 static int read_graft_file(const char *graft_file)
-- 
1.7.1

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

* Re: [PATCH] commit: Remove backward goto in read_craft_line()
  2010-12-01 21:19         ` Junio C Hamano
@ 2010-12-01 21:40           ` Ralf Thielow
  0 siblings, 0 replies; 8+ messages in thread
From: Ralf Thielow @ 2010-12-01 21:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jonathan Nieder, git

I remember about a peoble (not on this project) who sad that
also a little change like this should includes in the sources because
it's make the code better without fixing a bug or add a new feature.
But in my experience these patches are not very popular.
But sure, I understand your reasons, Junio.
The statement from above is not even true.

2010/12/1 Junio C Hamano <gitster@pobox.com>:
> Ralf Thielow <ralf.thielow@googlemail.com> writes:
>
>>> If "--show-c-function" output is the problem, perhaps we should know a bit
>>> better about what C function header looks like?
>>
>> In fact the "--show-c-function" output is the problem. But I think that
>> a change can't be rejected because of another issue.
>
> Well, I never said anything about rejection nor acceptance.
>
>> The style of placing "goto"-statements, which leave a function to the
>> end of that is used in many other projects. And I think
>> it's very usefull.
>
> It is a good discipline to follow in general to place an exceptional case
> at the end if you jump out of the general flow.  But because the affected
> function was so small, its readability doesn't benefit very much from the
> discipline (in other words, you knew about a good discipline, but applied
> it to a wrong function).  The patch was small and obviously correct, so it
> will not hurt, but it will not make the world greatly a better place,
> either.
>
> IOW, it was a "Meh" topic for me.
>
> It was more important to discuss Jonathan's "leave SP at the beginning of
> a goto label to please --show-c-function" from the maintainer's point of
> view, as people may remember it as a rule and start sending patches that
> follow it, which I will need to deal with in the future.  I do not think
> that one is a good rule.
>
> Now that we have dealt with that more important business of letting people
> know that protecting goto labels with a leading SP is _not_ the rule ;-),
> I am happy with this discussion.
>
> And often I forget about the original issue when a discussion reaches this
> stage of happiness.  So thanks for reminding me.
>
> As I said, even though I do not think the particular function you touched
> badly needs the discipline applied, it would not hurt, and it obviously is
> the right thing to do (iow, if the function were written from day one in a
> way your patch reorganized it, we would never accept a patch to change it
> into today's shape of jumping backwards).  For one thing, it would remove
> an example from the codebase people can point at to make excuses when
> responding to a review of their patch that adds a backward goto to a much
> larger function.
>
> Will queue after massaging the log message somewhat.  Thanks.
>

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

* Re: [PATCH] commit: Remove backward goto in read_craft_line()
  2010-12-01 20:44       ` Ralf Thielow
@ 2010-12-01 21:19         ` Junio C Hamano
  2010-12-01 21:40           ` Ralf Thielow
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2010-12-01 21:19 UTC (permalink / raw)
  To: Ralf Thielow; +Cc: Jonathan Nieder, git

Ralf Thielow <ralf.thielow@googlemail.com> writes:

>> If "--show-c-function" output is the problem, perhaps we should know a bit
>> better about what C function header looks like?
>
> In fact the "--show-c-function" output is the problem. But I think that
> a change can't be rejected because of another issue.

Well, I never said anything about rejection nor acceptance.

> The style of placing "goto"-statements, which leave a function to the
> end of that is used in many other projects. And I think
> it's very usefull.

It is a good discipline to follow in general to place an exceptional case
at the end if you jump out of the general flow.  But because the affected
function was so small, its readability doesn't benefit very much from the
discipline (in other words, you knew about a good discipline, but applied
it to a wrong function).  The patch was small and obviously correct, so it
will not hurt, but it will not make the world greatly a better place,
either.

IOW, it was a "Meh" topic for me.

It was more important to discuss Jonathan's "leave SP at the beginning of
a goto label to please --show-c-function" from the maintainer's point of
view, as people may remember it as a rule and start sending patches that
follow it, which I will need to deal with in the future.  I do not think
that one is a good rule.

Now that we have dealt with that more important business of letting people
know that protecting goto labels with a leading SP is _not_ the rule ;-),
I am happy with this discussion.

And often I forget about the original issue when a discussion reaches this
stage of happiness.  So thanks for reminding me.

As I said, even though I do not think the particular function you touched
badly needs the discipline applied, it would not hurt, and it obviously is
the right thing to do (iow, if the function were written from day one in a
way your patch reorganized it, we would never accept a patch to change it
into today's shape of jumping backwards).  For one thing, it would remove
an example from the codebase people can point at to make excuses when
responding to a review of their patch that adds a backward goto to a much
larger function.

Will queue after massaging the log message somewhat.  Thanks.

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

* Re: [PATCH] commit: Remove backward goto in read_craft_line()
  2010-12-01 20:31     ` Jonathan Nieder
@ 2010-12-01 20:44       ` Ralf Thielow
  2010-12-01 21:19         ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Ralf Thielow @ 2010-12-01 20:44 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Junio C Hamano, git

> If "--show-c-function" output is the problem, perhaps we should know a bit
> better about what C function header looks like?

In fact the "--show-c-function" output is the problem. But I think that
a change can't be rejected because of another issue.
The style of placing "goto"-statements, which leave a function to the
end of that is used in many other projects. And I think
it's very usefull.

2010/12/1 Jonathan Nieder <jrnieder@gmail.com>:
> Junio C Hamano wrote:
>> Jonathan Nieder <jrnieder@gmail.com> writes:
>
>>> A space before the "bad_graft_data:" label would improve future
>>> diff --show-c-function output.
>>
>> Hmm, I actually do not think we encourage that (nor we should).
>>
>>     $ git grep -e '^ [a-z0-9]*:' -- '*.c' | wc -l
>>     23
>>     $ git grep -e '^[a-z0-9]*:' -- '*.c' | wc -l
>>     42
>>
>> If "--show-c-function" output is the problem, perhaps we should know a bit
>> better about what C function header looks like?
>
> Thanks for checking.  Yes, I think so.
>
>        $ git grep --show-function strbuf_release -- http.c
>        http.c=static int http_request(const char *url, void *result, int target, int options)
>        http.c: strbuf_release(&buf);
>        http.c=cleanup:
>        http.c: strbuf_release(&tmpfile);
>        http.c=int http_fetch_ref(const char *base, struct ref *ref)
>        http.c: strbuf_release(&buffer);
>
> The following gives me some joy.
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
> diff --git a/.gitattributes b/.gitattributes
> index 5e98806..5888a53 100644
> --- a/.gitattributes
> +++ b/.gitattributes
> @@ -1,3 +1,4 @@
>  * whitespace=!indent,trail,space
>  *.[ch] whitespace=indent,trail,space
> +*.[ch] diff=cpp
>  *.sh whitespace=indent,trail,space
>

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

* Re: [PATCH] commit: Remove backward goto in read_craft_line()
  2010-12-01 20:19   ` Junio C Hamano
@ 2010-12-01 20:31     ` Jonathan Nieder
  2010-12-01 20:44       ` Ralf Thielow
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Nieder @ 2010-12-01 20:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ralf Thielow, git

Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:

>> A space before the "bad_graft_data:" label would improve future
>> diff --show-c-function output.
>
> Hmm, I actually do not think we encourage that (nor we should).
> 
>     $ git grep -e '^ [a-z0-9]*:' -- '*.c' | wc -l
>     23
>     $ git grep -e '^[a-z0-9]*:' -- '*.c' | wc -l
>     42
> 
> If "--show-c-function" output is the problem, perhaps we should know a bit
> better about what C function header looks like?

Thanks for checking.  Yes, I think so.

	$ git grep --show-function strbuf_release -- http.c
	http.c=static int http_request(const char *url, void *result, int target, int options)
	http.c: strbuf_release(&buf);
	http.c=cleanup:
	http.c: strbuf_release(&tmpfile);
	http.c=int http_fetch_ref(const char *base, struct ref *ref)
	http.c: strbuf_release(&buffer);

The following gives me some joy.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff --git a/.gitattributes b/.gitattributes
index 5e98806..5888a53 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,3 +1,4 @@
 * whitespace=!indent,trail,space
 *.[ch] whitespace=indent,trail,space
+*.[ch] diff=cpp
 *.sh whitespace=indent,trail,space

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

* Re: [PATCH] commit: Remove backward goto in read_craft_line()
  2010-12-01 19:44 ` Jonathan Nieder
@ 2010-12-01 20:19   ` Junio C Hamano
  2010-12-01 20:31     ` Jonathan Nieder
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2010-12-01 20:19 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Ralf Thielow, git, Junio C Hamano

Jonathan Nieder <jrnieder@gmail.com> writes:

>> @@ -155,6 +151,11 @@ struct commit_graft *read_graft_line(char *buf, int len)
>>  			goto bad_graft_data;
>>  	}
>>  	return graft;
>> +
>> +bad_graft_data:
>> +	error("bad graft data: %s", buf);
>
> A space before the "bad_graft_data:" label would improve future
> diff --show-c-function output.

Hmm, I actually do not think we encourage that (nor we should).

    $ git grep -e '^ [a-z0-9]*:' -- '*.c' | wc -l
    23
    $ git grep -e '^[a-z0-9]*:' -- '*.c' | wc -l
    42

If "--show-c-function" output is the problem, perhaps we should know a bit
better about what C function header looks like?

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

* Re: [PATCH] commit: Remove backward goto in read_craft_line()
  2010-12-01 19:15 Ralf Thielow
@ 2010-12-01 19:44 ` Jonathan Nieder
  2010-12-01 20:19   ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Nieder @ 2010-12-01 19:44 UTC (permalink / raw)
  To: Ralf Thielow; +Cc: git, Junio C Hamano

Ralf Thielow wrote:

> In case of bad graft data which is determine on many
> places we go back to the first place of detection,
> so move it to the end of the function.

I like it.  Three tiny nits.

Perhaps the log message could be clarified like so:

 bad graft data is noticed in several places in read_graft_line and
 in each case we go back to the first site of detection.  Move the
 error handling to the end of the function for better readability.

> --- a/commit.c
> +++ b/commit.c
> @@ -137,12 +137,8 @@ struct commit_graft *read_graft_line(char *buf, int len)
>  		buf[--len] = '\0';
>  	if (buf[0] == '#' || buf[0] == '\0')
>  		return NULL;
> -	if ((len + 1) % 41) {
> -	bad_graft_data:
> -		error("bad graft data: %s", buf);
> -		free(graft);
> -		return NULL;
> -	}
> +	if ((len + 1) % 41) 
> +		goto bad_graft_data;

Trailing whitespace.  (You can avoid this in the future with
"git diff --check".)

[...]
> @@ -155,6 +151,11 @@ struct commit_graft *read_graft_line(char *buf, int len)
>  			goto bad_graft_data;
>  	}
>  	return graft;
> +
> +bad_graft_data:
> +	error("bad graft data: %s", buf);

A space before the "bad_graft_data:" label would improve future
diff --show-c-function output.

Except as noted above,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.
---
diff --git a/commit.c b/commit.c
index d86159a..d5144f6 100644
--- a/commit.c
+++ b/commit.c
@@ -137,7 +137,7 @@ struct commit_graft *read_graft_line(char *buf, int len)
 		buf[--len] = '\0';
 	if (buf[0] == '#' || buf[0] == '\0')
 		return NULL;
-	if ((len + 1) % 41) 
+	if ((len + 1) % 41)
 		goto bad_graft_data;
 	i = (len + 1) / 41 - 1;
 	graft = xmalloc(sizeof(*graft) + 20 * i);
@@ -152,7 +152,7 @@ struct commit_graft *read_graft_line(char *buf, int len)
 	}
 	return graft;
 
-bad_graft_data:
+ bad_graft_data:
 	error("bad graft data: %s", buf);
 	free(graft);
 	return NULL;

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

* [PATCH] commit: Remove backward goto in read_craft_line()
@ 2010-12-01 19:15 Ralf Thielow
  2010-12-01 19:44 ` Jonathan Nieder
  0 siblings, 1 reply; 8+ messages in thread
From: Ralf Thielow @ 2010-12-01 19:15 UTC (permalink / raw)
  To: git; +Cc: Ralf Thielow

In case of bad graft data which is determine on many
places we go back to the first place of detection,
so move it to the end of the function.

Signed-off-by: Ralf Thielow <ralf.thielow@googlemail.com>
---
 commit.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index 0094ec1..d86159a 100644
--- a/commit.c
+++ b/commit.c
@@ -137,12 +137,8 @@ struct commit_graft *read_graft_line(char *buf, int len)
 		buf[--len] = '\0';
 	if (buf[0] == '#' || buf[0] == '\0')
 		return NULL;
-	if ((len + 1) % 41) {
-	bad_graft_data:
-		error("bad graft data: %s", buf);
-		free(graft);
-		return NULL;
-	}
+	if ((len + 1) % 41) 
+		goto bad_graft_data;
 	i = (len + 1) / 41 - 1;
 	graft = xmalloc(sizeof(*graft) + 20 * i);
 	graft->nr_parent = i;
@@ -155,6 +151,11 @@ struct commit_graft *read_graft_line(char *buf, int len)
 			goto bad_graft_data;
 	}
 	return graft;
+
+bad_graft_data:
+	error("bad graft data: %s", buf);
+	free(graft);
+	return NULL;
 }
 
 static int read_graft_file(const char *graft_file)
-- 
1.7.1

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

end of thread, other threads:[~2010-12-01 21:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-01 19:59 [PATCH] commit: Remove backward goto in read_craft_line() Ralf Thielow
  -- strict thread matches above, loose matches on Subject: below --
2010-12-01 19:15 Ralf Thielow
2010-12-01 19:44 ` Jonathan Nieder
2010-12-01 20:19   ` Junio C Hamano
2010-12-01 20:31     ` Jonathan Nieder
2010-12-01 20:44       ` Ralf Thielow
2010-12-01 21:19         ` Junio C Hamano
2010-12-01 21:40           ` Ralf Thielow

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.