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

Re: [PATCH 2/3] add--interactive: add builtin helper for interactive add

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 5, 2017, 23:28 UTC
Message-ID
<CACBZZX6-ZmxkPo14N_D5f9rm=WtR_MkJzgZv_xYMqtcq5xfBHA@mail.gmail.com>
In-Reply-To
<CAEA2_RKzUdSPP4bBvGiFVfNnAY3wwp+0LYriC4q5XfCP-1-F4w@mail.gmail.com>

On Sat, May 6, 2017 at 1:13 AM, Daniel Ferreira (theiostream) <bnmvco@gmail.com> wrote:

Show 41 quoted lines
> On Fri, May 5, 2017 at 7:30 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
>>> +static int git_add_interactive_config(const char *var,
>>
>> Not git_add_interactive__helper_config()? ;-)
>
> I don't get if you mean this ironically (because of the verbosity) or
> if you do think this would be a good name ;P
>
>>> +     for (i = 0; i < q->nr; i++) {
>>> +             struct diff_filepair *p;
>>> +             p = q->queue[i];
>>> +             diff_flush_stat(p, options, &stat);
>>> +     }
>>> +
>>> +     for (i = 0; i < stat.nr; i++) {
>>> +             int file_index = s->file_count;
>>> +             for (j = 0; j < s->file_count; j++) {
>>> +                     if (!strcmp(s->files[j].path, stat.files[i]->name)) {
>>> +                             file_index = j;
>>> +                             break;
>>> +                     }
>>> +             }
>>
>> So basically, this is looking up in a list whether we saw the file in
>> question already, and the reason we have to do that is that we run the
>> entire shebang twice, once with the worktree and once with the index.
>>
>> I wonder whether it would not make sense to switch away s->files from a
>> list to a hashmap.
>> [...]
>> BTW in the first pass, we pretty much know that we only get unique names,
>> so the entire lookup is unnecessary and will just increase the time
>> complexity from O(n) to O(n^2). So let's avoid that.
>>
>> By moving to a hashmap, you can even get the second phase down to an
>> expected O(n).
>
> How would you go about implementing that hashmap (i.e. what should be
> the hash)? Does Git have any interface for it, or is there any example
> I can look after in the codebase?
Git has a hashmap API already. 7d4558c462 is a good example of using it.
Show 8 quoted lines
>>> +     printf(ADD_INTERACTIVE_HEADER_INDENT);
>>> +     color_fprintf(stdout, header_color, modified_fmt, _("staged"),
>>> +                     _("unstaged"), _("path"));
>>
>> I think these _() need to become N_().
>
> I cannot find any call to N_() outside of Perl code. What should that
> even do differently?

N_() is to mark a string for later translation, not to return it. See my "how to use getopt" patch for an example of that, but this doesn't look like such a case, since _() is returning the string to color_fprintf, surely...

    $ git grep -P '\bN_\(' -- '*.c'
Previous: Daniel Ferreira (theiostream)Next: Johannes Schindelin
Message 12 of 21 in “Port git-add--interactive.perl:status_cmd to C”
  1. 0/3 Port git-add--interactive.perl:status_cmd to CDaniel Ferreira, May 5, 2017
  2. 1/3 diff: export diffstat interfaceDaniel Ferreira, May 5, 2017
  3. Johannes SchindelinMay 5, 2017
  4. 2/3 add--interactive: add builtin helper for interactive addDaniel Ferreira, May 5, 2017
  5. Ævar Arnfjörð BjarmasonMay 5, 2017
  6. Johannes SchindelinMay 5, 2017
  7. Ævar Arnfjörð BjarmasonMay 5, 2017
  8. Johannes SchindelinMay 5, 2017
  9. Ævar Arnfjörð BjarmasonMay 5, 2017
  10. Johannes SchindelinMay 8, 2017
  11. Daniel Ferreira (theiostream)May 5, 2017
  12. Ævar Arnfjörð BjarmasonMay 5, 2017
  13. Johannes SchindelinMay 8, 2017
  14. 3/3 add--interactive: use add-interactive--helper for status_cmdDaniel Ferreira, May 5, 2017
  15. Johannes SchindelinMay 5, 2017
  16. Ævar Arnfjörð BjarmasonMay 5, 2017
  17. Johannes SchindelinMay 5, 2017
  18. Jonathan NiederMay 5, 2017
  19. Johannes SchindelinMay 5, 2017
  20. Daniel Ferreira (theiostream)May 5, 2017
  21. Johannes SchindelinMay 8, 2017

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.