# Re: [PATCH] remove "[PATCH]" prefix from shortlog output

7 messages from 2006-12-10 to 2006-12-11. Participants: Johannes Schindelin, Jakub Narebski, Junio C Hamano, Nicolas Pitre.
Thread: https://gitlist.dev/t/43343

## Nicolas Pitre, 2006-12-10 00:58

Subject: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <Pine.LNX.4.64.0612091954010.2630@xanadu.home>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0612091954010.2630%40xanadu.home

```
This doesn't convey much information in the shortlog context.
And the perl version did strip it as well.

Signed-off-by: Nicolas Pitre <nico@cam.org>

---

diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index 7a2ddfe..6c4606b 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -146,6 +146,11 @@ static void insert_author_oneline(struct path_list *list,
 	while (onelinelen > 0 && isspace(oneline[onelinelen - 1]))
 		onelinelen--;
 
+	if (onelinelen > 8 && !strncasecmp(oneline, "[PATCH] ", 8)) {
+		oneline += 8;
+		onelinelen -= 8;
+	}
+
 	buffer = xmalloc(onelinelen + 1);
 	memcpy(buffer, oneline, onelinelen);

```

## Johannes Schindelin, 2006-12-10 22:40

Subject: Re: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <Pine.LNX.4.63.0612102337090.28348@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612102337090.28348%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <Pine.LNX.4.64.0612091954010.2630@xanadu.home>

```
Hi,

On Sat, 9 Dec 2006, Nicolas Pitre wrote:

> This doesn't convey much information in the shortlog context.
> And the perl version did strip it as well.

From the current builtin-shortlog.c:128ff:

        if (!strncmp(oneline, "[PATCH", 6)) {
                char *eob = strchr(oneline, ']');

                if (eob) {
                        while (isspace(eob[1]) && eob[1] != '\n')
                                eob++;
                        if (eob - oneline < onelinelen) {
                                onelinelen -= eob - oneline;
                                oneline = eob;
                        }
                }
        }

It tries not only to strip "[PATCH]", but also "[PATCH 0/n]" and basically 
every prefix beginning with "[PATCH" and ending in "]". I do not remember 
if I really tested that code, but it should work.

Ciao,
Dscho

```

## Jakub Narebski, 2006-12-10 23:10

Subject: Re: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <eli3vr$j6v$1@sea.gmane.org>
URL: https://gitlist.dev/e/eli3vr%24j6v%241%40sea.gmane.org
In-Reply-To: <Pine.LNX.4.63.0612102337090.28348@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin wrote:

> On Sat, 9 Dec 2006, Nicolas Pitre wrote:
> 
>> This doesn't convey much information in the shortlog context.
>> And the perl version did strip it as well.
> 
> From the current builtin-shortlog.c:128ff:
> 
>         if (!strncmp(oneline, "[PATCH", 6)) {
>                 char *eob = strchr(oneline, ']');
> 
>                 if (eob) {
>                         while (isspace(eob[1]) && eob[1] != '\n')
>                                 eob++;
>                         if (eob - oneline < onelinelen) {
>                                 onelinelen -= eob - oneline;
>                                 oneline = eob;
>                         }
>                 }
>         }
> 
> It tries not only to strip "[PATCH]", but also "[PATCH 0/n]" and basically 
> every prefix beginning with "[PATCH" and ending in "]". I do not remember 
> if I really tested that code, but it should work.

What happens if you have "[PATCH" without closing "]"? Does it work (and
doesn't crash)? Does it strip anything?
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


```

## Junio C Hamano, 2006-12-10 23:32

Subject: Re: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <7vac1v2uom.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vac1v2uom.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.63.0612102337090.28348@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> It tries not only to strip "[PATCH]", but also "[PATCH 0/n]" and basically 
> every prefix beginning with "[PATCH" and ending in "]". I do not remember 
> if I really tested that code, but it should work.

The problem is that you forgot that the lines are indented when
acting as a filter.

How about this?  It also contains the extra whitespace removal
from the author name.

diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index 7a2ddfe..3fc43dd 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -188,18 +188,25 @@ static void read_from_stdin(struct path_list *list)
 				bob = buffer + strlen(buffer);
 			else {
 				offset = 8;
-				if (isspace(bob[-1]))
+				while (buffer + offset < bob &&
+				       isspace(bob[-1]))
 					bob--;
 			}
 
 			while (fgets(buffer2, sizeof(buffer2), stdin) &&
 					buffer2[0] != '\n')
 				; /* chomp input */
-			if (fgets(buffer2, sizeof(buffer2), stdin))
+			if (fgets(buffer2, sizeof(buffer2), stdin)) {
+				int l2 = strlen(buffer2);
+				int i;
+				for (i = 0; i < l2; i++)
+					if (!isspace(buffer2[i]))
+						break;
 				insert_author_oneline(list,
 						buffer + offset,
 						bob - buffer - offset,
-						buffer2, strlen(buffer2));
+						buffer2 + i, l2 - i);
+			}
 		}
 	}
 }

```

## Johannes Schindelin, 2006-12-10 23:35

Subject: Re: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <Pine.LNX.4.63.0612110031480.1348@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612110031480.1348%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <eli3vr$j6v$1@sea.gmane.org>

```
Hi,

On Mon, 11 Dec 2006, Jakub Narebski wrote:

> Johannes Schindelin wrote:
> 
> > On Sat, 9 Dec 2006, Nicolas Pitre wrote:
> > 
> >> This doesn't convey much information in the shortlog context.
> >> And the perl version did strip it as well.
> > 
> > From the current builtin-shortlog.c:128ff:
> > 
> >         if (!strncmp(oneline, "[PATCH", 6)) {
> >                 char *eob = strchr(oneline, ']');
> > 
> >                 if (eob) {
> >                         while (isspace(eob[1]) && eob[1] != '\n')
> >                                 eob++;
> >                         if (eob - oneline < onelinelen) {
> >                                 onelinelen -= eob - oneline;
> >                                 oneline = eob;
> >                         }
> >                 }
> >         }
> > 
> > It tries not only to strip "[PATCH]", but also "[PATCH 0/n]" and basically 
> > every prefix beginning with "[PATCH" and ending in "]". I do not remember 
> > if I really tested that code, but it should work.
> 
> What happens if you have "[PATCH" without closing "]"? Does it work (and
> doesn't crash)? Does it strip anything?

Use the source, Luke!

If "[PATCH" is there, but "]" is not, then eob will be NULL, and nothing 
happens.

Well, actually it is not completely true: the code searches for "]" in the 
_complete_ commit message (which _is_ terminated by '\0'). But only if it 
is found, _and_ it is in the first line, the substring is trimmed away.

Hth,
Dscho

```

## Johannes Schindelin, 2006-12-10 23:41

Subject: Re: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <Pine.LNX.4.63.0612110040260.1471@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612110040260.1471%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <7vac1v2uom.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Sun, 10 Dec 2006, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > It tries not only to strip "[PATCH]", but also "[PATCH 0/n]" and basically 
> > every prefix beginning with "[PATCH" and ending in "]". I do not remember 
> > if I really tested that code, but it should work.
> 
> The problem is that you forgot that the lines are indented when
> acting as a filter.

Of course!

And your patch looks correct to me.
Ciao,

```

## Nicolas Pitre, 2006-12-11 03:17

Subject: Re: [PATCH] remove "[PATCH]" prefix from shortlog output
Message-ID: <Pine.LNX.4.64.0612102147460.2630@xanadu.home>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0612102147460.2630%40xanadu.home
In-Reply-To: <Pine.LNX.4.63.0612110040260.1471@wbgn013.biozentrum.uni-wuerzburg.de>

```
On Mon, 11 Dec 2006, Johannes Schindelin wrote:

> Hi,
> 
> On Sun, 10 Dec 2006, Junio C Hamano wrote:
> 
> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> > 
> > > It tries not only to strip "[PATCH]", but also "[PATCH 0/n]" and basically 
> > > every prefix beginning with "[PATCH" and ending in "]". I do not remember 
> > > if I really tested that code, but it should work.

Hmmm well, right.  And of course I failed to notice that code was there.

I think I was corrupted by the dark side and failed to properly "use the 
source" twice on that tool this week.

> > The problem is that you forgot that the lines are indented when
> > acting as a filter.

Which was indeed my use case.

> Of course!
> 
> And your patch looks correct to me.

Confirmed.



```
