[aur-dev] [PATCH 1/4] git-update: Move blacklist reading further down
Since c4870a9 (git-update: Only check HEAD for blacklisted packages, 2015-06-04), only the HEAD commit package name is looked up in the blacklist. This means that we no longer need to read the blacklist before running the commit walker. Moving the blacklist reading code further down makes the code easier to read. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/git-update.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-interface/git-update.py b/git-interface/git-update.py index 935fa5b..de6ceb4 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -212,9 +212,6 @@ walker = repo.walk(sha1_new, pygit2.GIT_SORT_TOPOLOGICAL) if sha1_old != "0000000000000000000000000000000000000000": walker.hide(sha1_old) -cur.execute("SELECT Name FROM PackageBlacklist") -blacklist = [row[0] for row in cur.fetchall()] - for commit in walker: for fname in ('.SRCINFO', 'PKGBUILD'): if not fname in commit.tree: @@ -293,6 +290,9 @@ pkgbase = srcinfo._pkgbase['pkgname'] cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase]) pkgbase_id = cur.fetchone()[0] +cur.execute("SELECT Name FROM PackageBlacklist") +blacklist = [row[0] for row in cur.fetchall()] + for pkgname in srcinfo.GetPackageNames(): pkginfo = srcinfo.GetMergedPackage(pkgname) pkgname = pkginfo['pkgname'] -- 2.5.0
The pkgbase variable already contains the package base name at this point, no need to reassign it. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/git-update.py | 1 - 1 file changed, 1 deletion(-) diff --git a/git-interface/git-update.py b/git-interface/git-update.py index de6ceb4..8e69505 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -286,7 +286,6 @@ srcinfo_pkgbase = srcinfo._pkgbase['pkgname'] if srcinfo_pkgbase != pkgbase: die('invalid pkgbase: {:s}, expected {:s}'.format(srcinfo_pkgbase, pkgbase)) -pkgbase = srcinfo._pkgbase['pkgname'] cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase]) pkgbase_id = cur.fetchone()[0] -- 2.5.0
Add some comments to explain the major steps performed in the update hook. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/git-update.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-interface/git-update.py b/git-interface/git-update.py index 8e69505..d258385 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -212,6 +212,7 @@ walker = repo.walk(sha1_new, pygit2.GIT_SORT_TOPOLOGICAL) if sha1_old != "0000000000000000000000000000000000000000": walker.hide(sha1_old) +# Validate all new commits. for commit in walker: for fname in ('.SRCINFO', 'PKGBUILD'): if not fname in commit.tree: @@ -278,14 +279,17 @@ for commit in walker: if not fname in commit.tree: die_commit('missing source file: {:s}'.format(fname), str(commit.id)) +# Read .SRCINFO from the HEAD commit. srcinfo_raw = repo[repo[sha1_new].tree['.SRCINFO'].id].data.decode() srcinfo_raw = srcinfo_raw.split('\n') srcinfo = aurinfo.ParseAurinfoFromIterable(srcinfo_raw) +# Ensure that the package base name matches the repository name. srcinfo_pkgbase = srcinfo._pkgbase['pkgname'] if srcinfo_pkgbase != pkgbase: die('invalid pkgbase: {:s}, expected {:s}'.format(srcinfo_pkgbase, pkgbase)) +# Ensure that packages are neither blacklisted nor overwritten. cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase]) pkgbase_id = cur.fetchone()[0] @@ -304,6 +308,7 @@ for pkgname in srcinfo.GetPackageNames(): if cur.fetchone()[0] > 0: die('cannot overwrite package: {:s}'.format(pkgname)) +# Store package base details in the database. save_srcinfo(srcinfo, db, cur, user) db.close() -- 2.5.0
Implement a new command that can be used to restore deleted package bases without having to push a new commit. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- conf/config.proto | 1 + doc/git-interface.txt | 1 + git-interface/git-serve.py | 19 +++++++++++++++++++ git-interface/git-update.py | 21 ++++++++++++--------- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/conf/config.proto b/conf/config.proto index 52da796..2c798b7 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -51,6 +51,7 @@ ssh-options = no-port-forwarding,no-X11-forwarding,no-pty repo-path = /srv/http/aurweb/aur.git/ repo-regex = [a-z0-9][a-z0-9.+_-]*$ git-shell-cmd = /usr/bin/git-shell +git-update-cmd = /srv/http/aurweb/git-interface/git-update.py ssh-cmdline = ssh aur@aur.archlinux.org [aurblup] diff --git a/doc/git-interface.txt b/doc/git-interface.txt index b34e112..9ded20f 100644 --- a/doc/git-interface.txt +++ b/doc/git-interface.txt @@ -44,6 +44,7 @@ The git-serve command, the "aurweb shell", provides different subcommands: * The help command shows a list of available commands. * The list-repos command lists all repositories of the authenticated user. * The setup-repo command can be used to create a new repository. +* The restore command can be used to restore a deleted package base. * The git-{receive,upload}-pack commands are redirected to git-shell(1). The requested command is extracted from the SSH_ORIGINAL_COMMAND environment diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py index 8316cf7..45c9a01 100755 --- a/git-interface/git-serve.py +++ b/git-interface/git-serve.py @@ -19,6 +19,7 @@ aur_db_socket = config.get('database', 'socket') repo_path = config.get('serve', 'repo-path') repo_regex = config.get('serve', 'repo-regex') git_shell_cmd = config.get('serve', 'git-shell-cmd') +git_update_cmd = config.get('serve', 'git-update-cmd') ssh_cmdline = config.get('serve', 'ssh-cmdline') enable_maintenance = config.getboolean('options', 'enable-maintenance') @@ -152,10 +153,28 @@ elif action == 'setup-repo': if len(cmdargv) > 2: die_with_help("{:s}: too many arguments".format(action)) create_pkgbase(cmdargv[1], user) +elif action == 'restore': + if len(cmdargv) < 2: + die_with_help("{:s}: missing repository name".format(action)) + if len(cmdargv) > 2: + die_with_help("{:s}: too many arguments".format(action)) + + pkgbase = cmdargv[1] + if not re.match(repo_regex, pkgbase): + die('{:s}: invalid repository name: {:s}'.format(action, pkgbase)) + + if pkgbase_exists(pkgbase): + die('{:s}: package base exists: {:s}'.format(action, pkgbase)) + create_pkgbase(pkgbase, user) + + os.environ["AUR_USER"] = user + os.environ["AUR_PKGBASE"] = pkgbase + os.execl(git_update_cmd, git_update_cmd, 'restore') elif action == 'help': die("Commands:\n" + " help Show this help message and exit.\n" + " list-repos List all your repositories.\n" + + " restore <name> Restore a deleted package base.\n" + " setup-repo <name> Create an empty repository.\n" + " git-receive-pack Internal command used with Git.\n" + " git-upload-pack Internal command used with Git.") diff --git a/git-interface/git-update.py b/git-interface/git-update.py index d258385..5ff8b28 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -176,22 +176,25 @@ def die_commit(msg, commit): sys.stderr.write("error: {:s}\n".format(msg)) exit(1) -if len(sys.argv) != 4: - die("invalid arguments") - -refname = sys.argv[1] -sha1_old = sys.argv[2] -sha1_new = sys.argv[3] +repo = pygit2.Repository(repo_path) user = os.environ.get("AUR_USER") pkgbase = os.environ.get("AUR_PKGBASE") privileged = (os.environ.get("AUR_PRIVILEGED", '0') == '1') +if len(sys.argv) == 2 and sys.argv[1] == "restore": + if 'refs/heads/' + pkgbase not in repo.listall_references(): + die('{:s}: repository not found: {:s}'.format(sys.argv[1], pkgbase)) + refname = "refs/heads/master" + sha1_old = sha1_new = repo.lookup_reference('refs/heads/' + pkgbase).target +elif len(sys.argv) == 4: + refname, sha1_old, sha1_new = sys.argv[1:3] +else: + die("invalid arguments") + if refname != "refs/heads/master": die("pushing to a branch other than master is restricted") -repo = pygit2.Repository(repo_path) - db = mysql.connector.connect(host=aur_db_host, user=aur_db_user, passwd=aur_db_pass, db=aur_db_name, unix_socket=aur_db_socket, buffered=True) @@ -291,7 +294,7 @@ if srcinfo_pkgbase != pkgbase: # Ensure that packages are neither blacklisted nor overwritten. cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase]) -pkgbase_id = cur.fetchone()[0] +pkgbase_id = cur.fetchone()[0] if cur.rowcount == 1 else 0 cur.execute("SELECT Name FROM PackageBlacklist") blacklist = [row[0] for row in cur.fetchall()] -- 2.5.0
participants (1)
-
Lukas Fleischer