Re: [RFC PATCH 3/4] range-diff: add section header instead of diff header
- From
Thomas Gummerer <t.gummerer@gmail.com>
- Date
- Apr 15, 2019, 19:09 UTC
- Message-ID
- <20190415190939.GD1704@hank.intra.tgummerer.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.1904151457310.44@tvgsbejvaqbjf.bet>
On 04/15, Johannes Schindelin wrote:
Show 31 quoted lines
> Hi Eric,
>
> On Sun, 14 Apr 2019, Eric Sunshine wrote:
>
> > On Sun, Apr 14, 2019 at 5:10 PM Thomas Gummerer <t.gummerer@gmail.com> wrote:
> > > [...]
> > > Introduce a new range diff hunk header, that's enclosed by "##",
> > > similar to how line numbers in diff hunks are enclosed by "@@", and
> > > give human readable information of what exactly happened to the file,
> > > including the file name.
> > > [...]
> > > Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
> > > ---
> > > diff --git a/range-diff.c b/range-diff.c
> > > @@ -90,8 +91,37 @@ static int read_patches(const char *range, struct string_list *list)
> > > + } else if (starts_with(line.buf, "--- ")) {
> > > + if (!strcmp(line.buf, "--- /dev/null"))
> > > + strbuf_remove(&line, 0, 4);
> > > + else
> > > + strbuf_remove(&line, 0, 6);
> > > + strbuf_rtrim(&line);
> > > + strbuf_reset(&filename_a);
> > > + strbuf_addbuf(&filename_a, &line);
> > > + } else if (starts_with(line.buf, "+++ ")) {
> >
> > At this point, we know that line.buf starts with "+++"...
> >
> > > + strbuf_addstr(&buf, " ## ");
> > > + if (!strcmp(line.buf, "--- /dev/null"))
> >
> > so, it seems unlikely that it's ever going to match "--- /dev/null".Ouch yup, this is some bad copy pasta, thanks for catching!
Show 24 quoted lines
> > > + strbuf_remove(&line, 0, 4);
> > > + if (!strcmp(filename_a.buf, "/dev/null")) {
> > > + strbuf_addstr(&buf, "new file ");
> > > + strbuf_addbuf(&buf, &line);
> > > + } else if (!strcmp(line.buf, "/dev/null")) {
> > > + strbuf_addstr(&buf, "removed file ");
> > > + strbuf_addbuf(&buf, &line);
> > > + } else if (strbuf_cmp(&filename_a, &line)) {
> > > + strbuf_addstr(&buf, "renamed file ");
> > > + strbuf_addbuf(&buf, &filename_a);
> > > + strbuf_addstr(&buf, " -> ");
> > > + strbuf_addbuf(&buf, &line);
> > > + } else {
> > > + strbuf_addstr(&buf, "modified file ");
> > > + strbuf_addbuf(&buf, &line);
> > > + }
> >
> > All of these disposition strings end with "file", which seems
> > redundant. Short and sweet "new", "removed", "renamed", "modified"
> > provide just as much useful information.
> >
> > Also, should these strings be localizable?
>
> I'd rather not.Dunno, why do you think they should not be localizable? I'm tend to agree with Eric that they could be made localizable, after all this output is not supposed to be machine readable either way. I don't have a strong opinion here though.
Show 22 quoted lines
> > Alternately, rather than using prose to describe the disposition, > > perhaps do so symbolically (thus universally), say with "+", "-", "->", > > "*" (or ""), respectively? > > Or maybe streamline the common case (modified) by *not* saying anything, > then? I.e. > > @@ Documentation/Makefile > > for a modified file, > > @@ builtin/psuh.c (new) > > for a new file, > > @@ git-add--interactive.perl (deleted) > > for a removed one, and > > @@ builtin/serve.c -> t/helper/test-serve-v2.c > > for a renamed one.
This looks like a good suggestion to me, thanks!
Show 5 quoted lines
> That should also give us a bit of wiggle room to append the function name > part of the inner hunk header, if any. > > Ciao, > Dscho