All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gummerer <t.gummerer@gmail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, Duy Nguyen <pclouds@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [RFC PATCH 2/4] range-diff: don't remove funcname from inner diff
Date: Mon, 15 Apr 2019 19:57:40 +0100	[thread overview]
Message-ID: <20190415185740.GC1704@hank.intra.tgummerer.com> (raw)
In-Reply-To: <nycvar.QRO.7.76.6.1904151448530.44@tvgsbejvaqbjf.bet>

On 04/15, Johannes Schindelin wrote:
> Hi Thomas,
> 
> 
> On Sun, 14 Apr 2019, Thomas Gummerer wrote:
> > diff --git a/range-diff.c b/range-diff.c
> > index 9242b8975f..f365141ade 100644
> > --- a/range-diff.c
> > +++ b/range-diff.c
> > @@ -102,9 +102,12 @@ static int read_patches(const char *range, struct string_list *list)
> >  				strbuf_addch(&buf, '\n');
> >  			}
> >  			continue;
> > -		} else if (starts_with(line.buf, "@@ "))
> > -			strbuf_addstr(&buf, "@@");
> > -		else if (!line.buf[0] || starts_with(line.buf, "index "))
> > +		} else if (starts_with(line.buf, "@@ ")) {
> > +			char *skip_lineno = strstr(line.buf + 3, "@@");
> 
> Rather than using the magic constant "3", it would probably make sense to
> declare `skip_lineno` outside of the `if` construct, and use
> `skip_prefix(line.buf, "@@ ", &skip_lineno)` instead of
> `starts_with(...)`.

I like this suggestion.

> We *will*, however, want to have a safeguard against `strstr()` not
> finding anything. Maybe re-use the `p` variable that we already have, and
> do this instead:
> 
> 		} else if (skip_prefix(line.buf, "@@ ", &p) &&
> 			   (p = strstr(p, "@@"))) {
> 
> > +			strbuf_remove(&line, 0, skip_lineno - line.buf);
> > +			strbuf_addch(&buf, ' ');
> 
> Shorter:
> 
> 			strbuf_splice(&line, 0, p - line.buf, " ", 1);
> 
> (assuming that you accept my suggestion to use `p` instead of
> `skip_lineno`...)

And this is also much nicer, thanks!

> Thanks,
> Dscho
> 
> > +			strbuf_addbuf(&buf, &line);
> > +		} else if (!line.buf[0] || starts_with(line.buf, "index "))
> >  			/*
> >  			 * A completely blank (not ' \n', which is context)
> >  			 * line is not valid in a diff.  We skip it
> > --
> > 2.21.0.593.g511ec345e1
> >
> >

  reply	other threads:[~2019-04-15 18:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 11:17 incorrect range-diff output? Duy Nguyen
2019-04-11 22:05 ` Thomas Gummerer
2019-04-12  8:41   ` Johannes Schindelin
2019-04-14 21:12     ` Thomas Gummerer
2019-04-12  9:21   ` Duy Nguyen
2019-04-12 15:02   ` Junio C Hamano
2019-04-14 21:20     ` Thomas Gummerer
2019-04-15  2:01       ` Junio C Hamano
2019-04-15 12:40     ` Johannes Schindelin
2019-04-14 21:09   ` [RFC PATCH 0/4] output improvements for git range-diff Thomas Gummerer
2019-04-14 21:09     ` [RFC PATCH 1/4] range-diff: fix function parameter indentation Thomas Gummerer
2019-04-14 21:09     ` [RFC PATCH 2/4] range-diff: don't remove funcname from inner diff Thomas Gummerer
2019-04-14 23:21       ` Eric Sunshine
2019-04-15 12:54         ` Johannes Schindelin
2019-04-15 18:56           ` Thomas Gummerer
2019-04-17 11:52             ` Johannes Schindelin
2019-04-24 18:15               ` Thomas Gummerer
2019-04-15 12:53       ` Johannes Schindelin
2019-04-15 18:57         ` Thomas Gummerer [this message]
2019-04-14 21:09     ` [RFC PATCH 3/4] range-diff: add section header instead of diff header Thomas Gummerer
2019-04-14 23:29       ` Eric Sunshine
2019-04-15  6:28         ` Johannes Sixt
2019-04-15 13:01         ` Johannes Schindelin
2019-04-15 19:09           ` Thomas Gummerer
2019-04-14 21:09     ` [RFC PATCH 4/4] range-diff: add section headers to the outer hunk header Thomas Gummerer
2019-04-15 12:44       ` Johannes Schindelin
2019-04-15 18:48         ` Thomas Gummerer
2019-04-15 12:47     ` [RFC PATCH 0/4] output improvements for git range-diff Johannes Schindelin
2019-04-15 19:25       ` Thomas Gummerer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190415185740.GC1704@hank.intra.tgummerer.com \
    --to=t.gummerer@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.