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

[PATCH 0/3] Port git-add--interactive.perl:status_cmd to C

From
Daniel Ferreira <bnmvco@gmail.com>
Date
May 5, 2017, 18:43 UTC
Message-ID
<1494009820-2090-1-git-send-email-bnmvco@gmail.com>

Hm, it looks like my GSoC project won't be in the Git organization, although I'm still interested in going for this so I guess I'll send patches to implement my proposal anyway (although certainly in a slower pace than I would if on the program).

This series introduces git-add-interactive--helper (or should it be called git-add--interactive--helper?) as a builtin capable of doing what the Perl script's status_cmd() would do.

I wish this patch series could have been smaller, although I don't think it would make sense to bring add-interactive "subunits" smaller than a command to the helper, and status_cmd (aside from probably add_untracked_cmd) was the simplest one to do after all -- and still required ~250 lines on the new builtin.

Another regret I had was not being able to retire any code from the Perl script yet (and will likely not be able to do so until all commands have been ported), but that is not such a big thing after all.

As for the new builtin, I think the color handling code is pretty straightforward. In fact, it was practically copied from places like clean.c or diff.c (which makes me wonder if some of that code could be generalized to avoid duplication). The same goes for the pretty simple option parsing code.

Bigger issues seem to arise when dealing with getting the numstat. While (as Junio anticipated on an RFC) some tasks like getting the actual diff and splitting it may require making the "diff machinery" write to a temporary file that we will read and do things with, I think it would be weird to do that for parsing a simple numstat from it. My first instinct was to create something like show_numstat_interactive() or something on diff.c (analogous to the other show_* functions). Doing that, however, would stumble upon another issue: we would not be able to print both a file's diff against the index (obtained from run_diff_index) and against the worktree (obtained from run_diff_files) in that function. The solution I came up with was to export the diffstat interface from diff.c into the world and allow our new builtin to use that and build our status_cmd output. Unless this breaks some rule of Git's API design, the result seems pretty reasonable to me.

Travis CI build: https://travis-ci.org/theiostream/git/builds/229232202

Looking forward for feedback, Daniel.

Daniel Ferreira (3):
  diff: export diffstat interface
  add--interactive: add builtin helper for interactive add
  add--interactive: use add-interactive--helper for status_cmd
 .gitignore                        |   1 +
 Makefile                          |   1 +
 builtin.h                         |   1 +
 builtin/add-interactive--helper.c | 258 ++++++++++++++++++++++++++++++++++++++
 diff.c                            |  17 +--
 diff.h                            |  19 ++-
 git-add--interactive.perl         |   4 +-
 git.c                             |   1 +
 8 files changed, 282 insertions(+), 20 deletions(-)
 create mode 100644 builtin/add-interactive--helper.c

-- 2.7.4 (Apple Git-66)

Next: Daniel Ferreira
Message 1 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.