xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / repo.inc.php (efea1970013c6a26d44d737f862217aea4e8f98c) (1,106B) (mode 100644) [raw]
<?php
require_once($INC . "/xlog.inc.php");
require_once($INC . "/db.inc.php");
require_once($INC . "/state.inc.php");

$repo_error = "";

function repo_set_error($str)
{
	global $repo_error;
	$repo_error = $str;
}

function repo_error()
{
	global $repo_error;
	return $repo_error;
}

/*
 * Check if a uid has access to repository
 */
function repo_allow($db, $repo_id, $uid, $perms)
{
	xlog("repo_allow: repo_id=$repo_id, uid=$uid, perms=$perms...");

	$e_repo_id = sprintf("%u", $repo_id);
	$e_uid = sprintf("%u", $uid);
	$e_perms = preg_replace("/[^A-Z]/", "", $perms);

	if (empty($e_perms))
		return FALSE;

	if (strcmp($perms, "R") == 0)
		$perms_add = " AND (perm = 'R' OR perm = 'W')";
	else
		$perms_add = " AND perm = 'W'";

	$sql = "SELECT 1 AS junk FROM repo_access"
		. " WHERE repo_id = $e_repo_id"
		. " AND uid = $e_uid"
		. $perms_add;
	$res = sql_query($db, $sql);
	if ($res === FALSE)
		return FALSE;
	$row = sql_fetch_array($res);
	sql_free_result($res);

	if (!isset($row['junk'])) {
		xlog("\tDo not allow access!");
		return FALSE;
	}

	xlog("\tAllow access!");

	return TRUE;
}

?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master