barryserver-git
Barry Splitting into more pages + commit pages a6603d5 (2 years, 3 months ago)<?php require_once $_SERVER["DOCUMENT_ROOT"]."/config.php"; ?> <?php $SIDE_LINKS = array(); ?> <?php const MAX_PER_PAGE = 20; if (!isset($_GET["repo"])) {header("Location: /");die();} $repo = $_GET["repo"]??""; if (isset($_GET["repo"])) { $PAGE_TITLE = $repo; } if (!is_dir(GIT_DIR."/".$repo.".git")) { ?> <?php require_once $_SERVER["DOCUMENT_ROOT"]."/head.php"; ?> <main> <h1>Repository not found</h1> <article>The repository you were looking for was not found on this server. Please check the URL and look for errors. If there are no errors, then the repository does not exist. Please use the index to reach any repositories you wish to access.</article> </main> <?php require_once $_SERVER["DOCUMENT_ROOT"]."/foot.php"; ?> <?php die();} $branch = $_GET["object"]??DEFAULT_BRANCH; $path = $_GET["path"]??"."; chdir(GIT_DIR."/".$repo.".git"); if ($branch === "") { $branch = DEFAULT_BRANCH; } $SIDE_LINKS["git clone"] = "git://".$_SERVER["SERVER_NAME"]."/".$repo.".git"; $PAGE_TITLE = "Commits - ".$PAGE_TITLE; require_once $_SERVER["DOCUMENT_ROOT"]."/head.php"; echo "<main><h1>".$repo."</h1>\n"; $page = intval($_GET["page"]??0); $commits = shell_exec("git rev-list --all --count"); if (($page*MAX_PER_PAGE)+1 >= $commits) {header("Location: .");die();} echo shell_exec("git --git-dir ".GIT_DIR."/".escapeshellcmd($repo).".git/ log -n ".MAX_PER_PAGE." --skip ".($page*MAX_PER_PAGE)." --format='<a href=\"/".escapeshellcmd($repo)."/commit/%H/".escapeshellcmd($path)."\" class=\"commit\"><b>%s</b><br>%cn (%cr) — %h</a><br>' ".escapeshellarg($branch)." -- ".escapeshellarg($path)); if ($commits > MAX_PER_PAGE) { ?> <br> <div class="commit-nav"> <?= ($page*MAX_PER_PAGE)+1 ?> - <?= min(($page+1)*MAX_PER_PAGE,$commits) ?> of <?= $commits ?> <br> <form method="GET" action=""> <input type="hidden" name="page" value="<?= ($page > 0)?($page - 1):(0) ?>"> <input type="submit" value="Previous"<?= ($page <= 0)?" disabled":"" ?>> </form> <form method="GET" action=""> <input type="hidden" name="page" value="<?= (($page+1)*MAX_PER_PAGE < $commits)?($page + 1):($page) ?>"> <input type="submit" value="Next"<?= (($page+1)*MAX_PER_PAGE >= $commits)?" disabled":"" ?>> </form> </div> <?php } ?> </main> <?php require_once $_SERVER["DOCUMENT_ROOT"]."/foot.php"; ?>