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

Re: [PATCH] revision: remove stray whitespace when name empty

From
Emily Shaffer <emilyshaffer@google.com>
Date
Jun 12, 2019, 19:23 UTC
Message-ID
<20190612192302.GA233791@google.com>
In-Reply-To
<CAPig+cS7ocDU3fGRPnQZqN+rT1Ujd2b=v5b1p5V6G++XmNPmsQ@mail.gmail.com>
On Fri, Jun 07, 2019 at 08:42:45PM -0400, Eric Sunshine wrote:
Show 46 quoted lines
> On Fri, Jun 7, 2019 at 6:59 PM Emily Shaffer <emilyshaffer@google.com> wrote:
> > Teach show_object_with_name() to avoid writing a space before a name
> > which is empty. Also teach tests for rev-list --objects --filter to not
> > require a space between the object ID and name.
> > [...]
> > Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> > ---
> > Not sure if making the whitespace optional is the right solution for the
> > test, although I couldn't come up with a cleaner approach. Maybe
> > something like this would be better, even though handling it in the
> > regex is shorter?
> >
> >   if [[ -z "$name" ]] then
> 
> In Git, we avoid Bash-isms. Just use 'test'. And, style is to place
> 'then' on its own line.
> 
>     if test -z "$name"
>     then
> 
> > diff --git a/revision.c b/revision.c
> > @@ -40,7 +40,8 @@ void show_object_with_name(FILE *out, struct object *obj, const char *name)
> >  {
> > -       fprintf(out, "%s ", oid_to_hex(&obj->oid));
> > +       fprintf(out, "%s%s", oid_to_hex(&obj->oid),
> > +               strcmp(name, "") == 0 ? "" : " ");
> >         for (p = name; *p && *p != '\n'; p++)
> >                 fputc(*p, out);
> >         fputc('\n', out);
> 
> It's subjective, but this starts to be a bit too noisy and unreadable.
> An alternative:
> 
>     fputs(oid_to_hex(...), out);
>     if (*name)
>         putc(' ', out);
> 
> > diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh
> > @@ -288,7 +288,7 @@ expect_has () {
> >         hash=$(git -C r3 rev-parse $commit:$name) &&
> > -       grep "^$hash $name$" actual
> > +       grep "^$hash \?$name$" actual
> 
> This would be the first use of \? with 'grep' in the test suite. I
> would worry about portability. Your suggestion earlier to tailor
> 'grep' invocation based upon whether $name is empty would be safer.

Thanks for the review, Eric. I'm going to try again from scratch with Peff and Junio's suggestion about adding an option to remove object names, and I'll try to keep your general style concerns in mind when I do so.

 - Emily
Previous: Eric SunshineNext: Jeff King
Message 3 of 22 in “revision: remove stray whitespace when name empty”
  1. revision: remove stray whitespace when name emptyEmily Shaffer, Jun 7, 2019
  2. Eric SunshineJun 8, 2019
  3. Emily ShafferJun 12, 2019
  4. Jeff KingJun 9, 2019
  5. Junio C HamanoJun 10, 2019
  6. Emily ShafferJun 12, 2019
  7. Jeff KingJun 13, 2019
  8. rev-list: teach --oid-only to enable pipingEmily Shaffer, Jun 13, 2019
  9. Jeff KingJun 14, 2019
  10. Junio C HamanoJun 14, 2019
  11. Emily ShafferJun 14, 2019
  12. Emily ShafferJun 14, 2019
  13. Jeff KingJun 19, 2019
  14. rev-list: teach --no-object-names to enable pipingEmily Shaffer, Jun 14, 2019
  15. Junio C HamanoJun 17, 2019
  16. Emily ShafferJun 18, 2019
  17. rev-list: teach --no-object-names to enable pipingEmily Shaffer, Jun 18, 2019
  18. Junio C HamanoJun 19, 2019
  19. Emily ShafferJun 19, 2019
  20. Jeff KingJun 19, 2019
  21. rev-list: teach --no-object-names to enable pipingEmily Shaffer, Jun 19, 2019
  22. Jeff KingJun 19, 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.