X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FUtils.pm;h=6d32446f0cdb339804da2bc9f4b3b5f2f4d9c2cf;hb=eb8ee28a1c14382122949c6dcc09bc3ee6a08310;hp=f11dc3402935b752f98cc524f50f6098204036d6;hpb=b1c8b22c3db33682673723c1400f8b8c08bcc9a3;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Utils.pm b/lib/Gitalist/Utils.pm index f11dc34..6d32446 100644 --- a/lib/Gitalist/Utils.pm +++ b/lib/Gitalist/Utils.pm @@ -5,6 +5,7 @@ use Exporter qw/import/; our @EXPORT_OK = qw/ age_string + mode_string /; sub age_string { @@ -50,6 +51,40 @@ sub is_binary { return $_[0] !~ /^[[:print:]]+$ (?: \s ^[[:print:]]+$ )?/mx; } +# via gitweb.pm circa line 1305 +use Fcntl ':mode'; +use constant { + S_IFINVALID => 0030000, + S_IFGITLINK => 0160000, +}; + +# submodule/subrepository, a commit object reference +sub S_ISGITLINK($) { + return (($_[0] & S_IFMT) == S_IFGITLINK) +} + +# convert file mode in octal to symbolic file mode string +sub mode_string { + my $mode = shift; + + if (S_ISGITLINK($mode)) { + return 'm---------'; + } elsif (S_ISDIR($mode & S_IFMT)) { + return 'drwxr-xr-x'; + } elsif ($^O ne 'MSWin32' and S_ISLNK($mode)) { # this is ENOLINKS country, we can't stop here! + return 'lrwxrwxrwx'; + } elsif (S_ISREG($mode)) { + # git cares only about the executable bit + if ($mode & S_IXUSR) { + return '-rwxr-xr-x'; + } else { + return '-rw-r--r--'; + } + } else { + return '----------'; + } +} + 1; __END__