Browse Source

Display configured clone interface

spesk1 3 years ago
parent
commit
3b9e66f00f
5 changed files with 40 additions and 7 deletions
  1. 2 1
      README.md
  2. 3 1
      config.default
  3. 10 1
      gsg
  4. 16 1
      lib/Gsg/Gather.pm
  5. 9 3
      lib/Gsg/Html.pm

+ 2 - 1
README.md

@@ -15,9 +15,10 @@ DONE:
 * Extremely basic markdown parser (only supports headings and non nested bullets
 * Line numbers for file browsing
 * Diff highlighting for log
+* Show git:// address for cloning (configurable via config file)
 
 TODO:
-* Show git:// address for cloning (configurable via config file)
+* Get diff stat for top of log index links
 * Code needs to be more robust / handle failure cases
 * Need to recurse git home, right now will only pull dirs in root of git home
 * README.md markdown renderer/parser / display in project index

+ 3 - 1
config.default

@@ -1,3 +1,5 @@
-GitHome = "/home/git"
+GitHome = "/home/git/"
 WebRoot = "/var/www/html/git"
+CloneEnabled = "yes"
+ClonePath = "git://site.xz:/"
 IgnoredProjects = [ "/home/git/projec_to_ignore.git/", "/home/git/some_project_to_ignore2.git/" ]

+ 10 - 1
gsg

@@ -73,6 +73,8 @@ sub dump_config {
 	}
 }
 
+dump_config();
+
 # Get projects list
 my $git_projects_ref = get_projects($config{'GitHome'},$config{'IgnoredProjects'},$logger);
 foreach my $p ( @$git_projects_ref ) {
@@ -89,6 +91,13 @@ my $trimmed_git_projects_ref = trim_project_paths($git_projects_ref,$logger);
 write_root_index($root_index,$trimmed_git_projects_ref,$web_projects_dir,$logger);
 
 # Write project contents
-write_project_content($git_projects_ref,$trimmed_git_projects_ref,$web_projects_dir,$logger);
+my $clone_path;
+if ( $config{'CloneEnabled'} eq "yes" ) {
+	$clone_path = $config{'ClonePath'};
+} else {
+	$clone_path = "Disabled";
+}
+
+write_project_content($git_projects_ref,$trimmed_git_projects_ref,$web_projects_dir,$clone_path,$logger);
 
 $logger->info("Done");

+ 16 - 1
lib/Gsg/Gather.pm

@@ -4,7 +4,22 @@ use warnings;
 use Log::Log4perl qw(:easy);
 use Shellex::Shellex qw(shellex findBin);
 use Exporter qw(import);
-our @EXPORT_OK = qw(get_file_tree get_projects trim_project_paths);
+our @EXPORT_OK = qw(get_file_tree get_projects trim_project_paths get_diff_stat);
+
+sub get_diff_stat($$$$) {
+
+	my $project_dir = shift;
+	my $newest_commit = shift;
+	my $compare_commit = shift;
+	my $logger = shift;
+
+	# git --git-dir=/home/git/git-site-gen.git/ diff --stat 37f54811d49d41a4d794594e5bbaaee2271d82ad 1afd193eda9a6bc703011a72afa273e560355713
+	my $gitCmd = findBin("git",$logger);
+	my $diff_stat = shellex("$gitCmd --git-dir=$project_dir $newest_commit $compare_commit",$logger);
+
+	return $diff_stat;
+
+}
 
 sub get_projects($$$) {
 

+ 9 - 3
lib/Gsg/Html.pm

@@ -4,7 +4,7 @@ use warnings;
 use Log::Log4perl qw(:easy);
 use lib "/usr/local/lib";
 use Shellex::Shellex qw(shellex findBin);
-use Gsg::Gather qw(get_file_tree);
+use Gsg::Gather qw(get_file_tree get_diff_stat);
 use Gsg::MdParse qw (render_readme);
 use Exporter qw(import);
 our @EXPORT_OK = qw(
@@ -155,11 +155,12 @@ sub gen_diff_colors($$$) {
 
 # Main sub for generating project page
 # Might make more sense to split into more subs?
-sub write_project_content($$$$) {
+sub write_project_content($$$$$) {
 
 	my $project_dirs_ref = shift;
 	my $trimmed_project_dirs_ref = shift;
 	my $web_projects_dir = shift;
+	my $clone_path = shift;
 	my $logger = shift;
 
 	# Make these array's easier to work with in a hash
@@ -173,7 +174,12 @@ sub write_project_content($$$$) {
 		my $spec_web_dir = $web_projects_dir . $projects_map{$project_path};
 		my $project_index = $spec_web_dir . "index.html";
 		write_file("",$project_index);
-		append_file("<html><a href=\"../../index.html\">Return to index</a></b><hr/>",$project_index);
+		append_file("<html><a href=\"../../index.html\"><b>Return to index</a></b></br>",$project_index);
+		my $uniq_clone_path = "Disabled";
+		if ( $clone_path ne "Disabled" ) {
+			$uniq_clone_path = $clone_path . $projects_map{$project_path};
+		}
+		append_file("<b><pre>Clone:<font color=\"green\"> git clone $uniq_clone_path</font></pre></b><hr/>",$project_index);
 		# Get all project data structures/info
 		my ( $file_tree_ref, $file_content_ref, $commits_ref, $commit_ids_ref ) = get_file_tree($project_path,$logger);