399f604ba9120128f97d4de9c4bfbfb5892a0357
commit 399f604ba9120128f97d4de9c4bfbfb5892a0357
Author: spesk1 <spesk@pm.me>
Date: Sat Jul 20 14:53:11 2019 +0000

Added timer and detection of binary files

diff --git a/README.md b/README.md
index 8663028..e28405f 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ DONE:
* Diff highlighting for log
* Show git:// address for cloning (configurable via config file)
* Support detection of misconfig of config file (pretty basic at this stage)
+* Detects binary files

TODO:
* Get diff stat for top of log index links
@@ -27,6 +28,7 @@ TODO:
* (Stretch Goal) HTML based syntax highlighting for files
* View history of files
* Add support for displaying difference branches
+* Figure out more efficient/faster detection of binary files

## Framework Plans ##
* gsg -- Perl script to generate the site, uses modules below
diff --git a/gsg b/gsg
index 1add206..25d3260 100755
--- a/gsg
+++ b/gsg
@@ -11,6 +11,8 @@ use Gsg::ConfigParse qw(parse_gsg_config);
use Gsg::Gather qw(get_file_tree get_projects trim_project_paths);
use Gsg::Html qw(write_file append_file write_root_index clean_web_root write_project_content);

+my $start_time = time();
+
# TODO set this in config file?
my $log_file = "gsg.log";
sub get_log_name { return $log_file; };
@@ -99,5 +101,7 @@ if ( $config{'CloneEnabled'} eq "yes" ) {
}

write_project_content($git_projects_ref,$trimmed_git_projects_ref,$web_projects_dir,$clone_path,$logger);
-
+my $end_time = time();
+my $run_time = $end_time - $start_time;
+print "Took $run_time seconds\n";
$logger->info("Done");
diff --git a/lib/Gsg/Gather.pm b/lib/Gsg/Gather.pm
index 3917e27..071afae 100644
--- a/lib/Gsg/Gather.pm
+++ b/lib/Gsg/Gather.pm
@@ -82,6 +82,18 @@ sub get_file_tree($$) {
my %file_content;
foreach my $filename ( keys %file_tree ) {
my $content = shellex("$gitCmd --git-dir=\"$projectDir\" show $file_tree{$filename}",$logger);
+ # - TODO -
+ # A hack -- interested in a better way to detect if git files are binary
+ # Also dramatically increases run time (~3 seconds additional run time, will likely ballon on bigger git repos)
+ my $file_cmd = findBin("file",$logger);
+ my $rm_cmd = findBin("rm",$logger);
+ my $test_write_path = "/tmp/test";
+ my $bin_test = shellex("$gitCmd --git-dir=\"$projectDir\" show $file_tree{$filename} > $test_write_path && $file_cmd -i $test_write_path && $rm_cmd $test_write_path",$logger);
+
+ if ( $bin_test !~ m/text/ ) {
+ $content = "Binary file";
+ }
+
chomp $content;
# Name - file content
$file_content{$filename} = $content;