Skip to content

Commit

Permalink
Reduce cost of deletion in levenstein distance (4 -> 3)
Browse files Browse the repository at this point in the history
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 <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Matthieu Moy authored and Junio C Hamano committed May 29, 2012
1 parent befc5ed commit c41494f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const char *help_unknown_cmd(const char *cmd)
}

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

qsort(main_cmds.names, main_cmds.cnt,
Expand Down

0 comments on commit c41494f

Please sign in to comment.