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

[PATCH 00/11] git add -i: add a rudimentary version in C (supporting only status and help so far)

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 10, 2019, 17:37 UTC
Message-ID
<pull.170.git.gitgitgadget@gmail.com>

This is the first leg on the long journey to a fully built-in git add -i (next up: parts 2 [https://github.com/gitgitgadget/git/pull/171], 3 [https://github.com/gitgitgadget/git/pull/172], 4 [https://github.com/gitgitgadget/git/pull/173], 5 [https://github.com/gitgitgadget/git/pull/174], and 6 [https://github.com/gitgitgadget/git/pull/175]).

It reflects the part that was submitted a couple of times (see https://github.com/gitgitgadget/git/pull/103) during the Outreachy project by Slavica Ðukic that continued the journey based on an initial patch series by Daniel Ferreira.

This part only implements the status and the help part, like Slavica's last iteration did, in the interest of making the review remotely more reviewable. I fear that this attempt of making it a bit more reviewable is pretty futile, as so many things changed. So I will ask the reviewers for forgiveness: please be kind, and give this sort of a fresh review.

I threw in a couple of major changes on top of that iteration, though:
 * The original plan was to add a helper (git add--helper) that takes over
   more and more responsibility from the Perl script over the course of the
   conversion.
   
   This plan is no longer in effect, as I encountered a serious problem with
   that: the MSYS2 runtime used by the Perl interpreter which Git for
   Windows employs to run git add -i has a curious bug (that is safely
   outside the purview of this here patch series) where it fails to read
   from standard input after it spawned a non-MSYS2 program (such as 
   add--helper) that reads from standard input. So that wouldn't work, but
   quit the interactive add as soon as even one interactive command had been
   handled by the helper. To keep my git add -i in a working state, I
   therefore adopted a different strategy:
   
   Just like git difftool was converted by starting with a built-in that did
   nothing but handing off to the scripted version, guarded by the (opt-in) 
   difftool.useBuiltin config setting, I start this patch series by a
   built-in add -i that does nothing else but state that it is not
   implemented yet, guarded by the (opt-in) add.interactive.useBuiltin 
   config setting.
   
   In contrast to the git difftool situation, it is quite a bit easier here,
   as we do not even have to rename the script to 
   git-legacy-add--interactive.perl: the add--interactive command is an
   implementation detail that users are not even supposed to know about.
   Therefore, we can implement that road fork between the built-in and the
   scripted version in builtin/add.c, i.e. in the user-facing git add 
   command.
   
   This will also naturally help with the transition to a fully built-in git
   add -i/git add -p, as we saw with the built-in git rebase how important
   it is for end users to have an escape hatch (and for that reason, tried
   our best to provide the same with the built-in git stash).
   
   
 * The help command was actually not hooked up in git add -i in Slavica's
   last iteration, but was only available as a special option of the git
   add--helper command. As that command no longer exists, I kind of had to
   implement some way to let the built-in git add -i show the help text.
   
   
 * The main loop of git add -i (i.e. the thing that lets you choose status 
   or help) is now implemented (but only lists status and help, of course),
   as it makes use of that feature that took the main chunk of the Outreachy
   project: the function to determine unique prefixes of a list of strings.
   
   
 * Speaking of the unique prefixes: the functionality to determine those is
   now encapsulated in the prefix-map.c file, and I also added a regression
   test.
   
   
 * Speaking of the tests: I also implemented support for the environment
   variable GIT_TEST_ADD_I_USE_BUILTIN: by setting it, the test suite can be
   forced to use the built-in, or the Perl script, version of git add -i.
   Needless to say: by the end of this patch series, running the test suite
   with GIT_TEST_ADD_I_USE_BUILTIN=true will still result in a ton of test
   failures due to not-yet-implemented commands, but it will also
   demonstrate what already works.
   
   
 * Since the main loop starts not only by showing the status, but refreshes
   the index before that, I added that, and I actually refactored that code
   into a new function (repo_refresh_and_write_index()), as it will be used
   a couple of times by the end of the complete conversion of git add -i 
   into a built-in command.
Daniel Ferreira (2):
  diff: export diffstat interface
  built-in add -i: implement the `status` command
Johannes Schindelin (6):
  Start to implement a built-in version of `git add --interactive`
  built-in add -i: refresh the index before running `status`
  built-in add -i: color the header in the `status` command
  built-in add -i: implement the main loop
  built-in add -i: support `?` (prompt help)
  built-in add -i: implement the `help` command
Slavica Djukic (3):
  Add a function to determine unique prefixes for a list of strings
  built-in add -i: show unique prefixes of the commands
  built-in add -i: use color in the main loop
 Documentation/config/add.txt |   5 +
 Makefile                     |   3 +
 add-interactive.c            | 560 +++++++++++++++++++++++++++++++++++
 add-interactive.h            |  10 +
 builtin/add.c                |  16 +-
 diff.c                       |  37 +--
 diff.h                       |  19 ++
 prefix-map.c                 | 111 +++++++
 prefix-map.h                 |  40 +++
 repository.c                 |  19 ++
 repository.h                 |   7 +
 t/README                     |   4 +
 t/helper/test-prefix-map.c   |  58 ++++
 t/helper/test-tool.c         |   1 +
 t/helper/test-tool.h         |   1 +
 t/t0016-prefix-map.sh        |  10 +
 t/t3701-add-interactive.sh   |  24 ++
 17 files changed, 902 insertions(+), 23 deletions(-)
 create mode 100644 add-interactive.c
 create mode 100644 add-interactive.h
 create mode 100644 prefix-map.c
 create mode 100644 prefix-map.h
 create mode 100644 t/helper/test-prefix-map.c
 create mode 100755 t/t0016-prefix-map.sh
base-commit: 8104ec994ea3849a968b4667d072fedd1e688642
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-170%2Fdscho%2Fadd-i-in-c-status-and-help-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-170/dscho/add-i-in-c-status-and-help-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/170
-- 
gitgitgadget
Next: Johannes Schindelin via GitGitGadget
Message 1 of 124 in “git add -i: add a rudimentary version in C (supporting only status and help so far)”
  1. 00/11 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, Apr 10, 2019
  2. 01/11 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, Apr 10, 2019
  3. Jeff HostetlerApr 18, 2019
  4. Jeff KingApr 18, 2019
  5. Johannes SchindelinApr 30, 2019
  6. Jeff KingMay 1, 2019
  7. Johannes SchindelinMay 13, 2019
  8. 02/11 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, Apr 10, 2019
  9. 04/11 built-in add -i: refresh the index before running `status`Johannes Schindelin via GitGitGadget, Apr 10, 2019
  10. 03/11 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, Apr 10, 2019
  11. 05/11 built-in add -i: color the header in the `status` commandJohannes Schindelin via GitGitGadget, Apr 10, 2019
  12. 06/11 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, Apr 10, 2019
  13. Jeff HostetlerApr 18, 2019
  14. Johannes SchindelinMay 13, 2019
  15. 09/11 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, Apr 10, 2019
  16. 08/11 built-in add -i: show unique prefixes of the commandsSlavica Djukic via GitGitGadget, Apr 10, 2019
  17. 07/11 Add a function to determine unique prefixes for a list of stringsSlavica Djukic via GitGitGadget, Apr 10, 2019
  18. Jeff HostetlerApr 18, 2019
  19. Johannes SchindelinMay 13, 2019
  20. 10/11 built-in add -i: use color in the main loopSlavica Djukic via GitGitGadget, Apr 10, 2019
  21. 11/11 built-in add -i: implement the `help` commandJohannes Schindelin via GitGitGadget, Apr 10, 2019
  22. 00/11 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, May 13, 2019
  23. 02/11 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, May 13, 2019
  24. 04/11 built-in add -i: refresh the index before running `status`Johannes Schindelin via GitGitGadget, May 13, 2019
  25. 06/11 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, May 13, 2019
  26. 08/11 built-in add -i: show unique prefixes of the commandsSlavica Djukic via GitGitGadget, May 13, 2019
  27. 11/11 built-in add -i: implement the `help` commandJohannes Schindelin via GitGitGadget, May 13, 2019
  28. 10/11 built-in add -i: use color in the main loopSlavica Djukic via GitGitGadget, May 13, 2019
  29. 07/11 Add a function to determine unique prefixes for a list of stringsSlavica Djukic via GitGitGadget, May 13, 2019
  30. 05/11 built-in add -i: color the header in the `status` commandJohannes Schindelin via GitGitGadget, May 13, 2019
  31. 09/11 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, May 13, 2019
  32. 01/11 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, May 13, 2019
  33. 03/11 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, May 13, 2019
  34. 00/11 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, Jul 16, 2019
  35. 01/11 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, Jul 16, 2019
  36. Junio C HamanoJul 31, 2019
  37. Johannes SchindelinAug 26, 2019
  38. Junio C HamanoAug 27, 2019
  39. Johannes SchindelinAug 28, 2019
  40. Junio C HamanoAug 28, 2019
  41. 02/11 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, Jul 16, 2019
  42. Junio C HamanoJul 31, 2019
  43. Johannes SchindelinAug 27, 2019
  44. 05/11 built-in add -i: color the header in the `status` commandJohannes Schindelin via GitGitGadget, Jul 16, 2019
  45. 04/11 built-in add -i: refresh the index before running `status`Johannes Schindelin via GitGitGadget, Jul 16, 2019
  46. 06/11 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, Jul 16, 2019
  47. Junio C HamanoJul 31, 2019
  48. 08/11 built-in add -i: show unique prefixes of the commandsSlavica Djukic via GitGitGadget, Jul 16, 2019
  49. 07/11 Add a function to determine unique prefixes for a list of stringsSlavica Djukic via GitGitGadget, Jul 16, 2019
  50. Junio C HamanoJul 31, 2019
  51. SZEDER GáborAug 24, 2019
  52. Johannes SchindelinAug 27, 2019
  53. SZEDER GáborAug 28, 2019
  54. [PoC] A simpler find_unique_prefixes() implementationSZEDER Gábor, Aug 28, 2019
  55. Johannes SchindelinAug 30, 2019
  56. 09/11 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, Jul 16, 2019
  57. 03/11 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, Jul 16, 2019
  58. Junio C HamanoJul 31, 2019
  59. Johannes SchindelinAug 27, 2019
  60. 10/11 built-in add -i: use color in the main loopSlavica Djukic via GitGitGadget, Jul 16, 2019
  61. 11/11 built-in add -i: implement the `help` commandJohannes Schindelin via GitGitGadget, Jul 16, 2019
  62. Junio C HamanoAug 2, 2019
  63. Jeff KingAug 2, 2019
  64. Johannes SchindelinJul 16, 2019
  65. Junio C HamanoAug 2, 2019
  66. 00/11 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, Aug 27, 2019
  67. 01/11 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, Aug 27, 2019
  68. 08/11 built-in add -i: show unique prefixes of the commandsSlavica Djukic via GitGitGadget, Aug 27, 2019
  69. 03/11 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, Aug 27, 2019
  70. 06/11 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, Aug 27, 2019
  71. 04/11 built-in add -i: refresh the index before running `status`Johannes Schindelin via GitGitGadget, Aug 27, 2019
  72. 09/11 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, Aug 27, 2019
  73. 11/11 built-in add -i: implement the `help` commandJohannes Schindelin via GitGitGadget, Aug 27, 2019
  74. 10/11 built-in add -i: use color in the main loopSlavica Djukic via GitGitGadget, Aug 27, 2019
  75. 02/11 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, Aug 27, 2019
  76. 07/11 Add a function to determine unique prefixes for a list of stringsSlavica Djukic via GitGitGadget, Aug 27, 2019
  77. 05/11 built-in add -i: color the header in the `status` commandJohannes Schindelin via GitGitGadget, Aug 27, 2019
  78. 0/9 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, Nov 4, 2019
  79. 1/9 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, Nov 4, 2019
  80. Junio C HamanoNov 8, 2019
  81. Johannes SchindelinNov 9, 2019
  82. Junio C HamanoNov 10, 2019
  83. Johannes SchindelinNov 11, 2019
  84. Junio C HamanoNov 11, 2019
  85. Johannes SchindelinNov 12, 2019
  86. Junio C HamanoNov 13, 2019
  87. Johannes SchindelinNov 13, 2019
  88. Junio C HamanoNov 13, 2019
  89. 4/9 built-in add -i: color the header in the `status` commandSlavica Đukić via GitGitGadget, Nov 4, 2019
  90. 3/9 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, Nov 4, 2019
  91. Junio C HamanoNov 8, 2019
  92. 2/9 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, Nov 4, 2019
  93. Junio C HamanoNov 8, 2019
  94. 7/9 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, Nov 4, 2019
  95. 5/9 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, Nov 4, 2019
  96. Junio C HamanoNov 8, 2019
  97. Johannes SchindelinNov 9, 2019
  98. 8/9 built-in add -i: use color in the main loopSlavica Đukić via GitGitGadget, Nov 4, 2019
  99. 9/9 built-in add -i: implement the `help` commandSlavica Đukić via GitGitGadget, Nov 4, 2019
  100. 6/9 built-in add -i: show unique prefixes of the commandsJohannes Schindelin via GitGitGadget, Nov 4, 2019
  101. 0/9 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, Nov 13, 2019
  102. 2/9 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, Nov 13, 2019
  103. 1/9 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, Nov 13, 2019
  104. Junio C HamanoNov 14, 2019
  105. Johannes SchindelinNov 14, 2019
  106. Junio C HamanoNov 15, 2019
  107. 3/9 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, Nov 13, 2019
  108. 6/9 built-in add -i: show unique prefixes of the commandsJohannes Schindelin via GitGitGadget, Nov 13, 2019
  109. 7/9 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, Nov 13, 2019
  110. 9/9 built-in add -i: implement the `help` commandSlavica Đukić via GitGitGadget, Nov 13, 2019
  111. 5/9 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, Nov 13, 2019
  112. 8/9 built-in add -i: use color in the main loopSlavica Đukić via GitGitGadget, Nov 13, 2019
  113. 4/9 built-in add -i: color the header in the `status` commandSlavica Đukić via GitGitGadget, Nov 13, 2019
  114. Johannes SchindelinNov 13, 2019
  115. 0/9 git add -i: add a rudimentary version in C (supporting only status and help so far)Johannes Schindelin via GitGitGadget, Nov 15, 2019
  116. 1/9 Start to implement a built-in version of `git add --interactive`Johannes Schindelin via GitGitGadget, Nov 15, 2019
  117. 4/9 built-in add -i: color the header in the `status` commandSlavica Đukić via GitGitGadget, Nov 15, 2019
  118. 7/9 built-in add -i: support `?` (prompt help)Johannes Schindelin via GitGitGadget, Nov 15, 2019
  119. 5/9 built-in add -i: implement the main loopJohannes Schindelin via GitGitGadget, Nov 15, 2019
  120. 2/9 diff: export diffstat interfaceDaniel Ferreira via GitGitGadget, Nov 15, 2019
  121. 6/9 built-in add -i: show unique prefixes of the commandsJohannes Schindelin via GitGitGadget, Nov 15, 2019
  122. 3/9 built-in add -i: implement the `status` commandDaniel Ferreira via GitGitGadget, Nov 15, 2019
  123. 8/9 built-in add -i: use color in the main loopSlavica Đukić via GitGitGadget, Nov 15, 2019
  124. 9/9 built-in add -i: implement the `help` commandSlavica Đukić via GitGitGadget, Nov 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.