1 package Gitalist::Utils;
4 use Exporter qw/import/;
15 if ( $age > 60 * 60 * 24 * 365 * 2 ) {
16 $age_str = ( int $age / 60 / 60 / 24 / 365 );
17 $age_str .= " years ago";
19 elsif ( $age > 60 * 60 * 24 * ( 365 / 12 ) * 2 ) {
20 $age_str = int $age / 60 / 60 / 24 / ( 365 / 12 );
21 $age_str .= " months ago";
23 elsif ( $age > 60 * 60 * 24 * 7 * 2 ) {
24 $age_str = int $age / 60 / 60 / 24 / 7;
25 $age_str .= " weeks ago";
27 elsif ( $age > 60 * 60 * 24 * 2 ) {
28 $age_str = int $age / 60 / 60 / 24;
29 $age_str .= " days ago";
31 elsif ( $age > 60 * 60 * 2 ) {
32 $age_str = int $age / 60 / 60;
33 $age_str .= " hours ago";
35 elsif ( $age > 60 * 2 ) {
36 $age_str = int $age / 60;
37 $age_str .= " min ago";
41 $age_str .= " sec ago";
44 $age_str .= " right now";
50 # Crappy heuristic - does the first line or so look printable?
51 return $_[0] !~ /^[[:print:]]+$ (?: \s ^[[:print:]]+$ )?/mx;
54 # via gitweb.pm circa line 1305
57 S_IFINVALID => 0030000,
58 S_IFGITLINK => 0160000,
61 # submodule/subrepository, a commit object reference
63 return (($_[0] & S_IFMT) == S_IFGITLINK)
66 # convert file mode in octal to symbolic file mode string
70 if (S_ISGITLINK($mode)) {
72 } elsif (S_ISDIR($mode & S_IFMT)) {
74 } elsif ($^O ne 'MSWin32' and S_ISLNK($mode)) { # this is ENOLINKS country, we can't stop here!
76 } elsif (S_ISREG($mode)) {
77 # git cares only about the executable bit
78 if ($mode & S_IXUSR) {
94 Gitalist::Utils - trivial utils for Gitalist
100 Turns an integer number of seconds into a string.
104 Check whether a string is binary according to C<-B>.
108 See L<Gitalist> for authors.
112 See L<Gitalist> for the license.