From ae036887ef0e74213cbe41af1bda34ae6eebac7c Mon Sep 17 00:00:00 2001 From: June Date: Thu, 22 Dec 2022 02:45:12 +0100 Subject: [PATCH] First commit! Scripts are ready --- git/hooks/pre-commit | 25 ++++++++++++++++++++++++ index.html | 7 +++++++ log2html.pl | 46 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100755 git/hooks/pre-commit create mode 100644 index.html create mode 100755 log2html.pl diff --git a/git/hooks/pre-commit b/git/hooks/pre-commit new file mode 100755 index 0000000..32b8672 --- /dev/null +++ b/git/hooks/pre-commit @@ -0,0 +1,25 @@ +#!/bin/sh + +# error handler +exit_if_error() { + local exit_code=$1 + shift + [[ $exit_code ]] && # do nothing if no error code passed + ((exit_code != 0)) && { # do nothing if error code is 0 + printf 'ERROR: %s\n' "$@" >&2 # we can use better logging here + exit "$exit_code" # we could also check to make sure + # error code is numeric when passed + } +} + +echo '==== Write html blog ====' + +perl log2html.pl>index.html +exit_if_error $? "Writing failed" +echo 'Done.' + +echo '==== End of writing ====' + +echo '==== Adding html in the commit ====' +git add --verbose index.html +echo '==== End of commit ====' \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..4c70402 --- /dev/null +++ b/index.html @@ -0,0 +1,7 @@ + + + + +
+
+ diff --git a/log2html.pl b/log2html.pl new file mode 100755 index 0000000..6a2d9a7 --- /dev/null +++ b/log2html.pl @@ -0,0 +1,46 @@ +# Script from Panike: https://gist.github.com/panike/811354.js + + +sub new_hl { + my @l = (); + return \@l; +} + +@args = @ARGV; +shift @args; +print "\n"; +print "\n"; +print " \n"; +print "\n"; +print "
\n";
+open REVLIST, "git log " . join(' ',@args) . " --topo-order --abbrev-commit --graph|" || die "Cannot get log";
+while(){
+        chomp;
+        if(/^Merge: /){
+                next;
+        }
+        if(/^commit/){
+                @list = split / /;
+                @tlist = @list;
+                print "commit $list[1]\n";
+                @list = @list[2 .. $#list];
+                foreach $key (@list) {
+                        print "parent $key\n";
+                        if(!$commits{$key}){
+                                $commits{$key}=new_hl;
+                        }
+                        push @{$commits{$key}}, $tlist[1];
+                }
+                foreach $key (@{$commits{$tlist[1]}}){
+                        print "child $key\n";
+                }
+        }else{
+                s//\>/g;
+                print;
+                print "\n";
+        }
+}
+print "
\n"; +print "\n"; +