our $do_git_untracked = 1;
our $argcounter;
+our @forms;
+
sub rjustt ($$;$) { # right justify and truncate (ie, pad and truncate at left)
# always includes prefix
my ($sz, $whole, $prefix) = @_;
sub genform ($@) {
my ($form, @lines) = @_;
gentextmodule($form, @lines);
+ my $f = {
+ Form => $form,
+ Chars => (length join '', @lines),
+ Lines => (scalar @lines),
+ Ambiguous => ($form =~ m/Full/ && !grep { m/\W/ } @lines),
+ };
+ push @forms, $f;
}
sub genform_q ($$$) {
rjustt($e, $git_count));
}
}
-}
+}
+
+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/;
+}
while (@ARGV) {
$_ = shift;
gentextmodule('FontDemo', @demo);
do_git();
+do_git_best();
p "module Commitid_2DDemo(){\n";
p " st = Commitid__scale() * [ 10, 5 ];\n";