threads / patch / 12517

patchshortlog: take the first populated line of the description

Subject: [PATCH] shortlog: take the first populated line of the description

## tl;dr

8 messages between Mar 5, 2008 and Mar 5, 2008. Diffs are folded; open one to read it.

replies: 7people: 4as markdown or json

Andy Whitcroft· Mar 5, 2008, 13:47 UTC · lore

Way back the perl version of shortlog would take the first populated line of the commit body. The builtin version mearly takes the first line. This leads to empty shortlog entries when there is some viable text in the commit.

Reinstate this behaviour igoring all lines with nothing but whitespace.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
	This seems to be an improvement, returning to the original
	behaviour.  I cannot think of any good reason not to take the first
	populated line for a shortlog.	The alternative less agressive
	compromise might be to skip only completly empty lines at the
	start, but I am not sure that adds any value.
	I seem to get a lot of these in converted SVN commits.
	Comments?
	-apw
---
 builtin-shortlog.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
Show changes to builtin-shortlog.c +3 −2
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index af31aba..b22b0ed 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -70,11 +70,12 @@ static void insert_one_record(struct shortlog *log,
 	else
 		free(buffer);
 
+	/* Skip any leading whitespace, including any blank lines. */
+	while (*oneline && isspace(*oneline))
+		oneline++;
 	eol = strchr(oneline, '\n');
 	if (!eol)
 		eol = oneline + strlen(oneline);
-	while (*oneline && isspace(*oneline) && *oneline != '\n')
-		oneline++;
 	if (!prefixcmp(oneline, "[PATCH")) {
 		char *eob = strchr(oneline, ']');
 		if (eob && (!eol || eob < eol))
Johannes Schindelin· Mar 5, 2008, 14:48 UTC · re: Andy Whitcroft · lore

Re: [PATCH] shortlog: take the first populated line of the description

Hi,
On Wed, 5 Mar 2008, Andy Whitcroft wrote:
Show 19 quoted lines
> diff --git a/builtin-shortlog.c b/builtin-shortlog.c
> index af31aba..b22b0ed 100644
> --- a/builtin-shortlog.c
> +++ b/builtin-shortlog.c
> @@ -70,11 +70,12 @@ static void insert_one_record(struct shortlog *log,
>  	else
>  		free(buffer);
>  
> +	/* Skip any leading whitespace, including any blank lines. */
> +	while (*oneline && isspace(*oneline))
> +		oneline++;
>  	eol = strchr(oneline, '\n');
>  	if (!eol)
>  		eol = oneline + strlen(oneline);
> -	while (*oneline && isspace(*oneline) && *oneline != '\n')
> -		oneline++;
>  	if (!prefixcmp(oneline, "[PATCH")) {
>  		char *eob = strchr(oneline, ']');
>  		if (eob && (!eol || eob < eol))

Why do you move the code around? Makes it harder to read your patch. Besides, you now strip empty lines at the beginning of the commit messages, right? Who produces such a thing?

Ciao, Dscho

Andy Whitcroft· Mar 5, 2008, 16:43 UTC · re: Johannes Schindelin · lore

Re: [PATCH] shortlog: take the first populated line of the description

On Wed, Mar 05, 2008 at 03:48:00PM +0100, Johannes Schindelin wrote:
Show 27 quoted lines
> Hi,
> 
> On Wed, 5 Mar 2008, Andy Whitcroft wrote:
> 
> > diff --git a/builtin-shortlog.c b/builtin-shortlog.c
> > index af31aba..b22b0ed 100644
> > --- a/builtin-shortlog.c
> > +++ b/builtin-shortlog.c
> > @@ -70,11 +70,12 @@ static void insert_one_record(struct shortlog *log,
> >  	else
> >  		free(buffer);
> >  
> > +	/* Skip any leading whitespace, including any blank lines. */
> > +	while (*oneline && isspace(*oneline))
> > +		oneline++;
> >  	eol = strchr(oneline, '\n');
> >  	if (!eol)
> >  		eol = oneline + strlen(oneline);
> > -	while (*oneline && isspace(*oneline) && *oneline != '\n')
> > -		oneline++;
> >  	if (!prefixcmp(oneline, "[PATCH")) {
> >  		char *eob = strchr(oneline, ']');
> >  		if (eob && (!eol || eob < eol))
> 
> Why do you move the code around?  Makes it harder to read your patch.  
> Besides, you now strip empty lines at the beginning of the commit 
> messages, right?  Who produces such a thing?

I've not moved the code as such. I added a loop to drop the leading whitespace. That made the second loop redundant as its job is already done, so I killed it.

The point of the patch is to strip the empty lines at the start of the commit. I am ending up with them in my repo mostly due to imcompetant users of SVN I suspect. The main driver is that I have those and the original non-C version coped and the builtin does not.

Now if people think that its a stupid idea I might suggest it could be optional?

-apw
Johannes Schindelin· Mar 5, 2008, 16:51 UTC · re: Andy Whitcroft · lore

Re: [PATCH] shortlog: take the first populated line of the description

Hi,
On Wed, 5 Mar 2008, Andy Whitcroft wrote:
Show 29 quoted lines
> On Wed, Mar 05, 2008 at 03:48:00PM +0100, Johannes Schindelin wrote:
> 
> > On Wed, 5 Mar 2008, Andy Whitcroft wrote:
> > 
> > > diff --git a/builtin-shortlog.c b/builtin-shortlog.c
> > > index af31aba..b22b0ed 100644
> > > --- a/builtin-shortlog.c
> > > +++ b/builtin-shortlog.c
> > > @@ -70,11 +70,12 @@ static void insert_one_record(struct shortlog *log,
> > >  	else
> > >  		free(buffer);
> > >  
> > > +	/* Skip any leading whitespace, including any blank lines. */
> > > +	while (*oneline && isspace(*oneline))
> > > +		oneline++;
> > >  	eol = strchr(oneline, '\n');
> > >  	if (!eol)
> > >  		eol = oneline + strlen(oneline);
> > > -	while (*oneline && isspace(*oneline) && *oneline != '\n')
> > > -		oneline++;
> > >  	if (!prefixcmp(oneline, "[PATCH")) {
> > >  		char *eob = strchr(oneline, ']');
> > >  		if (eob && (!eol || eob < eol))
> > 
> > Why do you move the code around?  Makes it harder to read your patch.  
> > Besides, you now strip empty lines at the beginning of the commit 
> > messages, right?  Who produces such a thing?
> 
> I've not moved the code as such.

Well, it sure looks like that. Maybe you want to make it look like that even more?

Show 7 quoted lines
> The point of the patch is to strip the empty lines at the start of the 
> commit.  I am ending up with them in my repo mostly due to imcompetant 
> users of SVN I suspect.  The main driver is that I have those and the 
> original non-C version coped and the builtin does not.
> 
> Now if people think that its a stupid idea I might suggest it could be 
> optional?

No, I think with an explanation like this in the commit message, it is good as-is.

Ciao, Dscho

Nicolas Pitre· Mar 5, 2008, 18:47 UTC · re: Andy Whitcroft · lore

Re: [PATCH] shortlog: take the first populated line of the description

On Wed, 5 Mar 2008, Andy Whitcroft wrote:
Show 20 quoted lines
> 
> Way back the perl version of shortlog would take the first populated line
> of the commit body.  The builtin version mearly takes the first line.
> This leads to empty shortlog entries when there is some viable text in
> the commit.
> 
> Reinstate this behaviour igoring all lines with nothing but whitespace.
> 
> Signed-off-by: Andy Whitcroft <apw@shadowen.org>
> ---
> 
> 	This seems to be an improvement, returning to the original
> 	behaviour.  I cannot think of any good reason not to take the first
> 	populated line for a shortlog.	The alternative less agressive
> 	compromise might be to skip only completly empty lines at the
> 	start, but I am not sure that adds any value.
> 
> 	I seem to get a lot of these in converted SVN commits.
> 
> 	Comments?
Maybe it is the SVN conversion that needs fixing?
Nicolas
Junio C Hamano· Mar 5, 2008, 21:27 UTC · re: Nicolas Pitre · lore

Re: [PATCH] shortlog: take the first populated line of the description

Nicolas Pitre <nico@cam.org> writes:
Show 12 quoted lines
> On Wed, 5 Mar 2008, Andy Whitcroft wrote:
> ...
>> 	...  I cannot think of any good reason not to take the first
>> 	populated line for a shortlog.	The alternative less agressive
>> 	compromise might be to skip only completly empty lines at the
>> 	start, but I am not sure that adds any value.
>> 
>> 	I seem to get a lot of these in converted SVN commits.
>> 
>> 	Comments?
>
> Maybe it is the SVN conversion that needs fixing?
I thought about saying the same, but I am of two minds.

It is likely that you would want to clean-up when importing, especially when you are planning to abandon the other system and switch to git. But you may want to have an import that is as close to the original as possible, excess blank lines in the log messages and all.

I think Andy's fix to make the output side take away unnecessary blank lines is unconditionally good.

I've added these three lines at the end of the log message.
    This is often useful when dealing with commits imported from foreign SCMs
    that do not tidy up the log message of useless blank lines at the
    beginning.
Nicolas Pitre· Mar 5, 2008, 21:47 UTC · re: Junio C Hamano · lore

Re: [PATCH] shortlog: take the first populated line of the description

On Wed, 5 Mar 2008, Junio C Hamano wrote:
Show 22 quoted lines
> Nicolas Pitre <nico@cam.org> writes:
> 
> > On Wed, 5 Mar 2008, Andy Whitcroft wrote:
> > ...
> >> 	...  I cannot think of any good reason not to take the first
> >> 	populated line for a shortlog.	The alternative less agressive
> >> 	compromise might be to skip only completly empty lines at the
> >> 	start, but I am not sure that adds any value.
> >> 
> >> 	I seem to get a lot of these in converted SVN commits.
> >> 
> >> 	Comments?
> >
> > Maybe it is the SVN conversion that needs fixing?
> 
> I thought about saying the same, but I am of two minds.
> 
> It is likely that you would want to clean-up when importing,
> especially when you are planning to abandon the other system and
> switch to git.  But you may want to have an import that is as
> close to the original as possible, excess blank lines in the log
> messages and all.

I don't think excess blank lines at the _beginning_ of the commit log has any value worth preserving though.

> I think Andy's fix to make the output side take away
> unnecessary blank lines is unconditionally good.

It is not "bad" in itself. However that feels like papering over another problem which IMHO has greater merits to be fixed. We have given special semantics to the first line of a commit log in many other places now, so unless all those places are also made aware of substandard commit logs too, I think it would be more productive to make sure those logs are semi sensible upon entering Git in the first place instead.

Nicolas
Junio C Hamano· Mar 5, 2008, 22:14 UTC · re: Nicolas Pitre · lore

Re: [PATCH] shortlog: take the first populated line of the description

Nicolas Pitre <nico@cam.org> writes:
Show 12 quoted lines
> On Wed, 5 Mar 2008, Junio C Hamano wrote:
>
>> I think Andy's fix to make the output side take away
>> unnecessary blank lines is unconditionally good.
>
> It is not "bad" in itself.  However that feels like papering over 
> another problem which IMHO has greater merits to be fixed.  We have 
> given special semantics to the first line of a commit log in many other 
> places now, so unless all those places are also made aware of 
> substandard commit logs too, I think it would be more productive to make 
> sure those logs are semi sensible upon entering Git in the first place 
> instead.

My understanding of the current status when I wrote that message was that everybody at commit.c layer (that is, everybody except shortlog) strips such garbage. Do you have a specific broken one in mind?

I suspect --pretty=format:%s might be broken; I didn't check.

← back to recent threads