Browse Source

Added timer and detection of binary files

spesk1 4 years ago
parent
commit
399f604ba9
3 changed files with 19 additions and 1 deletions
  1. 2 0
      README.md
  2. 5 1
      gsg
  3. 12 0
      lib/Gsg/Gather.pm

+ 2 - 0
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

+ 5 - 1
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");

+ 12 - 0
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;