8000 Minify the HG setup (#583) · python/psf-salt@442a8e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 442a8e9

Browse files
authored
Minify the HG setup (#583)
* add flask app and apache config for hglookup/hgrev * g'night hg
1 parent 7bb3480 commit 442a8e9

File tree

19 files changed

+131
-548
lines changed

19 files changed

+131
-548
lines changed

pillar/base/haproxy.sls

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ haproxy:
156156
hsts_preload: False
157157

158158
listens:
159-
hg_ssh:
160-
bind: :20100
161-
service: hg-ssh
162-
163159
buildbot_worker:
164160
bind: :20101
165161
service: buildbot-master-worker

salt/hg/config/hg.apache.conf.jinja

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,14 @@
3232
Require all granted
3333
</Directory>
3434

35-
# The lookup app is better run with few processes, since it uses a cache.
36-
WSGIDaemonProcess hglookup user=hg group=hg \
37-
threads=2 processes=1 maximum-requests=1000 \
38-
display-name=hglookup
39-
# The Location hack ensures the lookup app is run within
40-
# this process group
4135
<Location /lookup>
42-
WSGIProcessGroup hglookup
36+
ProxyPass http://localhost:8000/lookup
4337
</Location>
4438

45-
WSGIScriptAlias /lookup /srv/hg/wsgi/lookup.wsgi
46-
47-
# A lightweight standin for revision app to maintain support for /lookup
48-
WSGIDaemonProcess hgrev user=hg group=hg \
49-
threads=1 processes=6 maximum-requests=100 \
50-
display-name=hgrev
51-
# The Location hack ensures the lookup app is run within
52-
# this process group
5339
<LocationMatch "^(.*)/rev/([A-Fa-f0-9]{12,40})/?">
54-
WSGIProcessGroup hgrev
40+
ProxyPass http://localhost:8000
5541
</LocationMatch>
5642

57-
WSGIScriptAliasMatch "^(.*)/rev/([A-Fa-f0-9]{12,40})/?" /srv/hg/wsgi/rev.wsgi
58-
5943
# Staticly serve hg repos over HTTP
6044
DocumentRoot /srv/hg/hg-static/
6145
<Directory /srv/hg/hg-static>

salt/hg/config/hgmin.service.jinja

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Unit]
2+
Description=Minimal HG service
3+
After=network.target
4+
5+
[Service]
6+
Environment=LC_ALL=en_US.UTF-8
7+
Environment=LANG=en_US.UTF-8
8+
WorkingDirectory=/srv/hg/src
9+
ExecStart=/srv/hg/env/bin/gunicorn app:app -w 4 --access-logfile - --error-logfile -
10+
ExecReload=/bin/kill -HUP $MAINPID
11+
ExecStop = /bin/kill -s TERM $MAINPID
12+
Restart=on-failure
13+
User=hg
14+
Group=hg
15+
16+
[Install]
17+
WantedBy=multi-user.target

salt/hg/config/repos.conf

Lines changed: 0 additions & 19 deletions
This file was deleted.

salt/hg/files/hg/bin/gcrepos

Lines changed: 0 additions & 76 deletions
This file was deleted.

salt/hg/files/hg/bin/genauth

Lines changed: 0 additions & 80 deletions
This file was deleted.

salt/hg/files/hg/src/app.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import io
2+
import os
3+
import subprocess
4+
import shlex
5+
import json
6+
7+
from flask import current_app, Flask, make_response, redirect
8+
9+
app = Flask(__name__)
10+
11+
HG_COMMITS = os.path.join(os.path.dirname(__file__), "hg_commits.json")
12+
app.hg_commits = set()
13+
with io.open(HG_COMMITS, "r", encoding="utf-8") as file:
14+
hg_commits = json.load(file)
15+
hg_commits = set(hg_commits)
16+
hg_commits.update(commit[:12] for commit in list(hg_commits))
17+
app.hg_commits = frozenset(hg_commits)
18+
19+
20+
@app.route("/lookup/<rev>")
21+
def lookup(rev):
22+
url = None
23+
if rev.startswith("hg") or rev in current_app.hg_commits:
24+
if rev.startswith("hg"):
25+
rev = rev[len("hg") :]
26+
url = "https://hg.python.org/cpython/rev/" + rev
27+
elif rev.startswith("r"):
28+
url = "http://svn.python.org/view?view=revision&revision=" + rev[1:]
29+
else:
30+
if rev.startswith("git"):
31+
rev = rev[len("git") :]
32+
url = "https://github.com/python/cpython/commit/" + rev
33+
if url is None:
34+
return make_response(
35+
(
36+
"Usage: /lookup/GITHEXHASH or gitGITHEXHASH "
37+
"(10, 11, or 40 hex characters)\n",
38+
"/lookup/HGHEXNODE or hgHGHEXNODE (12 or 40 hex characters)\n",
39+
"/lookup/rSVNREVISION\n",
40+
),
41+
404,
42+
)
43+
else:
44+
return redirect(url, code=303)
45+
46+
47+
@app.route("/<path:repo>/rev/<rev>")
48+
def hgrev(repo, rev):
49+
hg_repo = os.path.join("/srv/hg/repos", repo, ".hg")
50+
if not os.path.exists(hg_repo):
51+
return make_response(f"repo not found ({repo}) ({rev})", 404)
52+
command = ["hg", "log", "-v", "-p", "-r", shlex.quote(rev)]
53+
try:
54+
result = subprocess.run(
55+
command,
56+
cwd=hg_repo,
57+
capture_output=True,
58+
text=False,
59+
shell=False,
60+
check=True,
61+
)
62+
except Exception as e:
63+
return make_response(
64+
(
65+
f"{str(e)}\n"
66+
"Usage: path/to/hg/repo/rev/HGHEXNODE "
67+
"(12 or 40 hex characters)\n"
68+
),
69+
404,
70+
)
71+
72+
return make_response(result.stdout, 200)

salt/hg/files/hg/src/hglookup.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0