stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
3f7ec74cc31a28ba74c788aae4636d7e531bfa36
parent
7689d61d4afb8ae71757bcb680d9d53b7287a3ca
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-05-06 04:53
generate post-update hook instead of copying it

Diffstat

M Makefile 1 -
D gitolite/post-update.py 10 ----------
M gitolite/stagit.py 25 +++++++++++++++++++------

3 files changed, 19 insertions, 17 deletions


diff --git a/Makefile b/Makefile

@@ -19,7 +19,6 @@ install: stagit
   19    19 	install -D -m 644 README.md "${DESTDIR}/usr/share/doc/stagit/README.md"
   20    20 
   21    21 	install -D -m 755 gitolite/shell.py "${DESTDIR}/usr/lib/stagit/shell"
   22    -1 	install -D -m 755 gitolite/post-update.py "${DESTDIR}/usr/lib/stagit/hooks/post-update"
   23    22 	install -D -m 644 gitolite/stagit.py "${DESTDIR}/usr/lib/python3/dist-packages/stagit.py"
   24    23 
   25    24 .PHONY: install

diff --git a/gitolite/post-update.py b/gitolite/post-update.py

@@ -1,10 +0,0 @@
    1    -1 #!/usr/bin/env python3
    2    -1 # see man githooks
    3    -1 
    4    -1 import os
    5    -1 
    6    -1 import stagit
    7    -1 
    8    -1 
    9    -1 repo = os.environ['STAGIT_REPO']
   10    -1 stagit.render_repo(repo)

diff --git a/gitolite/stagit.py b/gitolite/stagit.py

@@ -1,5 +1,6 @@
    1     1 import os
    2     2 import sys
   -1     3 import stat
    3     4 import shutil
    4     5 import subprocess
    5     6 import configparser
@@ -11,14 +12,23 @@ WWW_DIR = '/var/www/git/'
   11    12 REPO_DIR = os.path.expanduser('~/repos/')
   12    13 CONF_PATH = os.path.expanduser('~/stagit.conf')
   13    14 
   14    -1 POST_UPDATE_HOOK = '/usr/lib/stagit/hooks/post-update'
   15    -1 
   16    15 
   17    16 if os.environ.get('USER') != USER:
   18    17 	sys.stderr.write('wrong user\n')
   19    18 	sys.exit(1)
   20    19 
   21    20 
   -1    21 def create_sh_script(path, lines):
   -1    22 	if lines:
   -1    23 		with open(path, 'w') as fh:
   -1    24 			fh.write('#!/bin/sh\n')
   -1    25 			for line in lines:
   -1    26 				fh.write(line + '\n')
   -1    27 		os.chmod(path, 0o775)
   -1    28 	elif os.path.exists(path):
   -1    29 		os.unlink(path)
   -1    30 
   -1    31 
   22    32 def get_repo_dir(repo):
   23    33 	return os.path.join(REPO_DIR, repo + '.git')
   24    34 
@@ -54,16 +64,19 @@ def update_repo(repo):
   54    64 		subprocess.check_call(['git', 'init', '--bare'], cwd=repodir)
   55    65 
   56    66 	export_ok = os.path.join(repodir, 'git-daemon-export-ok')
   57    -1 	post_update = os.path.join(repodir, 'hooks', 'post-update')
   -1    67 	post_update = []
   58    68 	if config.getboolean(repo, 'http'):
   59    -1 		shutil.copy(POST_UPDATE_HOOK, post_update)
   -1    69 		post_update.append(
   -1    70 			'python3 -c \'import os, stagit; '
   -1    71 			'stagit.render_repo(os.environ["STAGIT_REPO"])\''
   -1    72 		)
   60    73 		with open(export_ok, 'a'):
   61    74 			os.utime(export_ok, None)
   62    75 	else:
   63    76 		if os.path.exists(export_ok):
   64    77 			os.unlink(export_ok)
   65    -1 		if os.path.exists(post_update):
   66    -1 			os.unlink(post_update)
   -1    78 
   -1    79 	create_sh_script(os.path.join(repodir, 'hooks', 'post-update'), post_update)
   67    80 
   68    81 	with open(os.path.join(repodir, 'description'), 'w') as fh:
   69    82 		fh.write(config.get(repo, 'desc'))