git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 3/4] range-diff: add section header instead of diff header

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 15, 2019, 13:01 UTC
Message-ID
<nycvar.QRO.7.76.6.1904151457310.44@tvgsbejvaqbjf.bet>
In-Reply-To
<CAPig+cTJyYLGAfHM_PrZd9DDaZBcVUetcWFcANGCYPvaMh2qxA@mail.gmail.com>
Hi Eric,
On Sun, 14 Apr 2019, Eric Sunshine wrote:
Show 50 quoted lines
> 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".
>
> > +                               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.
> 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.

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

Previous: Johannes SixtNext: Thomas Gummerer
Message 23 of 29 in “incorrect range-diff output?”
  1. Duy NguyenApr 11, 2019
  2. Thomas GummererApr 11, 2019
  3. Johannes SchindelinApr 12, 2019
  4. Thomas GummererApr 14, 2019
  5. Duy NguyenApr 12, 2019
  6. Junio C HamanoApr 12, 2019
  7. Thomas GummererApr 14, 2019
  8. Junio C HamanoApr 15, 2019
  9. Johannes SchindelinApr 15, 2019
  10. 0/4 output improvements for git range-diffThomas Gummerer, Apr 14, 2019
  11. 1/4 range-diff: fix function parameter indentationThomas Gummerer, Apr 14, 2019
  12. 2/4 range-diff: don't remove funcname from inner diffThomas Gummerer, Apr 14, 2019
  13. Eric SunshineApr 14, 2019
  14. Johannes SchindelinApr 15, 2019
  15. Thomas GummererApr 15, 2019
  16. Johannes SchindelinApr 17, 2019
  17. Thomas GummererApr 24, 2019
  18. Johannes SchindelinApr 15, 2019
  19. Thomas GummererApr 15, 2019
  20. 3/4 range-diff: add section header instead of diff headerThomas Gummerer, Apr 14, 2019
  21. Eric SunshineApr 14, 2019
  22. Johannes SixtApr 15, 2019
  23. Johannes SchindelinApr 15, 2019
  24. Thomas GummererApr 15, 2019
  25. 4/4 range-diff: add section headers to the outer hunk headerThomas Gummerer, Apr 14, 2019
  26. Johannes SchindelinApr 15, 2019
  27. Thomas GummererApr 15, 2019
  28. Johannes SchindelinApr 15, 2019
  29. Thomas GummererApr 15, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.