+}
+
+sub do_some_best ($$) {
+ my ($modname, $formre) = @_;
+ p "module Commitid_$modname(max_sz) {\n";
+ foreach my $f (
+ sort {
+ $b->{Chars} <=> $a->{Chars} or
+ $a->{Lines} <=> $b->{Chars}
+ }
+ grep {
+ $_->{Form} =~ m/$formre/ &&
+ !$_->{Ambiguous}
+ }
+ @forms
+ ) {
+ p "// $f->{Form}\n";
+ }
+ p "}\n";
+}
+
+sub do_git_best () {
+ return unless $do_git;
+
+ # Auto-computer for `best fit'
+ #
+ # We have two best fit approaches: with count, and git-object-id-only
+ #
+ # For `with count', we only ever include the git object id if the
+ # result would be unambigous. That means that at least one space
+ # or punctuation was generated.
+ #
+ # We sort the options by firstly number of characters
+ # (decreasing), and then by number of lines (increasing) and
+ # try each one both ways round.
+
+ do_some_best('BestCount', 'Small|Full') if $do_git =~ m/c/;
+ do_some_best('BestObjid', 'Git|Full') if $do_git =~ m/o/;
+}