]> git.ipfire.org Git - thirdparty/git.git/commit
built-in add -i: show unique prefixes of the commands
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 15 Nov 2019 11:11:17 +0000 (11:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Nov 2019 02:18:30 +0000 (11:18 +0900)
commit76b743234c6d122d9e194556f6f94f61493094f6
tree64e8f3e7bb97b60558bb7c3e5472fc36af5bcf60
parent6348bfba5843a17efc33b4ca13db36a982f1baed
built-in add -i: show unique prefixes of the commands

Just like in the Perl script `git-add--interactive.perl`, for each
command a unique prefix is determined (if there exists any within the
given parameters), and shown in the list, and accepted as a shortcut for
the command.

To determine the unique prefixes, as well as to look up the command in
question, we use a copy of the list and sort it.

While this might seem like overkill for a single command, it will make
much more sense when all the commands are implemented, and when we reuse
the same logic to present a list of files to edit, with convenient
unique prefixes.

At the start of the development of this patch series, a dedicated data
structure was introduced that imitated the Trie that the Perl version
implements. However, this was deemed overkill, and we now simply sort
the list before determining the length of the unique prefixes by looking
at each item's neighbor. As a bonus, we now use the same sorted list to
perform a binary search using the user-provided prefix as search key.

Original-patch-by: Slavica Đukić <slawica92@hotmail.com>
Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c