Skip to content

Commit c41494f

Browse files
moygitster
authored andcommitted
Reduce cost of deletion in levenstein distance (4 -> 3)
Before this patch, a character deletion has the same cost as 2 swaps, or 4 additions, so Git prefers suggesting a completely scrambled command name to removing a character. For example, "git tags" suggests "stage", but not "tag". By setting the deletion cost to 3, we keep it higher than swaps or additions, but prefer 1 deletion to 2 swaps. "git tags" now suggests "tag" in addition to staged. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent befc5ed commit c41494f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ const char *help_unknown_cmd(const char *cmd)
317317
}
318318

319319
main_cmds.names[i]->len =
320-
levenshtein(cmd, candidate, 0, 2, 1, 4) + 1;
320+
levenshtein(cmd, candidate, 0, 2, 1, 3) + 1;
321321
}
322322

323323
qsort(main_cmds.names, main_cmds.cnt,

0 commit comments

Comments
 (0)