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

Re: [PATCH REPLACEMENT for 2/2] git status: show relative paths when run in a subdirectory

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 10, 2007, 14:10 UTC
Message-ID
<Pine.LNX.4.64.0711101401370.4362@racer.site>
In-Reply-To
<fh46vv$ooj$1@ger.gmane.org>
Hi,

please, please, please do not cull the Cc list. I consider it rude to reply to _me_, but _address_ the mail to me, either the To: (preferred) or the Cc: (not so preferred).

On Sat, 10 Nov 2007, Michel Marti wrote:
Show 55 quoted lines
> Untracked files in the current dir don't include the relative path 
> to the project-root, but changed/updated files do:
> 
> # Changes to be committed:
> #   (use "git reset HEAD <file>..." to unstage)
> #
> #       new file: ../subdir/hello
> #
> # Untracked files:
> #   (use "git add <file>..." to include in what will be committed)
> #
> #       world
> 
> With the patch below (on top of your changes), the output becomes
> 
> # Changes to be committed:
> #   (use "git reset HEAD <file>..." to unstage)
> #
> #       new file: hello
> #
> # Untracked files:
> #   (use "git add <file>..." to include in what will be committed)
> #
> #       world
> 
> Cheers,
> 
> - Michel
> 
> diff --git a/wt-status.c b/wt-status.c
> index 0d25362..2cdc8ce 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -133,8 +133,8 @@ static void wt_status_print_filepair(struct wt_status *s,
>  
>         strbuf_init(&onebuf, 0);
>         strbuf_init(&twobuf, 0);
> -       one = quote_path(p->one->path, -1, &onebuf, s->prefix);
> -       two = quote_path(p->two->path, -1, &twobuf, s->prefix);
> +       one = quote_path(p->one->path, strlen(p->one->path), &onebuf, s->prefix);
> +       two = quote_path(p->two->path, strlen(p->two->path), &twobuf, s->prefix);
>  
>         color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
>         switch (p->status) {
> @@ -233,7 +233,8 @@ static void wt_status_print_initial(struct wt_status *s)
>         for (i = 0; i < active_nr; i++) {
>                 color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
>                 color_fprintf_ln(s->fp, color(WT_STATUS_UPDATED), "new file: %s",
> -                               quote_path(active_cache[i]->name, -1,
> +                               quote_path(active_cache[i]->name,
> +                                       strlen(active_cache[i]->name),
>                                            &buf, s->prefix));
>         }
>         if (active_nr)
> 
This patch is wrong.

If you want to go that way, move the strlen() call _into_ quote_path(), like I had it earlier.

But then we will have a double traversal of the strings again. That's what I tried to avoid, but I missed one place:

In line 94, it says "... && off < len && ...". This should read something like "((len < 0 && !in[off]) || off < len)" instead. Or maybe even "(len < 0 || off < len)" and have an "} else if (in[off]) off++; else break;" in the loop block.

Besides, you completely ignored the nice examples how other people contribute their patches, with mail bodies that double as a commit message, a diffstat, and with a test case.

Hth, Dscho

Previous: Michel MartiNext: Wincent Colaiuta
Message 45 of 48 in “Inconsistencies with git log”
  1. Jon SmirlNov 7, 2007
  2. Johannes SchindelinNov 7, 2007
  3. Jon SmirlNov 7, 2007
  4. Johannes SchindelinNov 7, 2007
  5. Jon SmirlNov 7, 2007
  6. Johannes SchindelinNov 7, 2007
  7. Jon SmirlNov 7, 2007
  8. Jon SmirlNov 7, 2007
  9. Johannes SchindelinNov 8, 2007
  10. Jon SmirlNov 8, 2007
  11. Andreas EricssonNov 8, 2007
  12. Johannes SchindelinNov 8, 2007
  13. Linus TorvaldsNov 9, 2007
  14. Jon SmirlNov 9, 2007
  15. Linus TorvaldsNov 9, 2007
  16. Linus TorvaldsNov 9, 2007
  17. Jon SmirlNov 9, 2007
  18. Linus TorvaldsNov 9, 2007
  19. Peter BaumannNov 9, 2007
  20. Junio C HamanoNov 9, 2007
  21. Jakub NarebskiNov 9, 2007
  22. Peter BaumannNov 9, 2007
  23. Linus TorvaldsNov 9, 2007
  24. Jakub NarebskiNov 9, 2007
  25. Wincent ColaiutaNov 8, 2007
  26. Daniel BarkalowNov 8, 2007
  27. Brian GernhardtNov 7, 2007
  28. David SymondsNov 7, 2007
  29. Johannes SchindelinNov 8, 2007
  30. David SymondsNov 8, 2007
  31. Brian GernhardtNov 8, 2007
  32. 1/2 Makefile: wt-status.h is also a lib headerJohannes Schindelin, Nov 8, 2007
  33. Andreas EricssonNov 8, 2007
  34. Peter BaumannNov 8, 2007
  35. David SymondsNov 8, 2007
  36. Andreas EricssonNov 8, 2007
  37. Alex RiesenNov 8, 2007
  38. Alex RiesenNov 8, 2007
  39. 2/2 git status: show relative paths when run in a subdirectoryJohannes Schindelin, Nov 8, 2007
  40. David SymondsNov 8, 2007
  41. Johannes SchindelinNov 8, 2007
  42. Junio C HamanoNov 8, 2007
  43. 2/2 git status: show relative paths when run in a subdirectoryJohannes Schindelin, Nov 9, 2007
  44. Michel MartiNov 10, 2007
  45. Johannes SchindelinNov 10, 2007
  46. Wincent ColaiutaNov 8, 2007
  47. Miles BaderNov 10, 2007
  48. David SymondsNov 7, 2007

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.